Skip to content

Commit 495d454

Browse files
authored
⚠️ Enable nomaps linter, Remove unused kubeadm ClusterStatus struct, Migrate Cluster.status.failureDomains to array (#12083)
* Add nomaps API linter and corresponding excludes Signed-off-by: Stefan Büringer buringerst@vmware.com * Remove unused bootstrap/kubeadm v1beta2 ClusterStatus struct * Migrate Cluster.status.failureDomains from map to array * Fix review findings --------- Signed-off-by: Stefan Büringer buringerst@vmware.com
1 parent 63c1e70 commit 495d454

File tree

52 files changed

+880
-754
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+880
-754
lines changed

.golangci-kal.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ linters:
2222
- "maxlength" # Ensure all strings and arrays have maximum lengths/maximum items.
2323
- "nobools" # Bools do not evolve over time, should use enums instead.
2424
- "nofloats" # Ensure floats are not used.
25+
- "nomaps" # Ensure maps are not used.
2526
- "optionalorrequired" # Every field should be marked as `+optional` or `+required`.
2627
- "requiredfields" # Required fields should not be pointers, and should not have `omitempty`.
2728
- "statusoptional" # Ensure all first children within status should be optional.
@@ -86,6 +87,14 @@ linters:
8687
text: "field Addresses type MachineAddresses must have a maximum items, add kubebuilder:validation:MaxItems marker"
8788
linters:
8889
- kubeapilinter
90+
- path: "api/bootstrap/kubeadm/v1beta1/*"
91+
text: "nomaps: APIEndpoints should not use a map type, use a list type with a unique name/identifier instead"
92+
linters:
93+
- kubeapilinter
94+
- path: "api/core/v1beta1/*"
95+
text: "nomaps: FailureDomains should not use a map type, use a list type with a unique name/identifier instead"
96+
linters:
97+
- kubeapilinter
8998

9099
## Excludes for clusterctl and Runtime Hooks (can be fixed once we bump their apiVersion)
91100
- path: "cmd/clusterctl/api/v1alpha3|api/runtime/hooks/v1alpha1"
@@ -111,6 +120,18 @@ linters:
111120
text: "field (XPreserveUnknownFields|XPreserveUnknownFields|XValidations|XMetadata|XIntOrString) json tag does not match pattern"
112121
linters:
113122
- kubeapilinter
123+
# We want to align Properties to the corresponding field in CustomResourceDefinitions.
124+
- path: "api/core/v1beta2/*|api/core/v1beta1/*"
125+
text: "Properties should not use a map type, use a list type with a unique name/identifier instead"
126+
linters:
127+
- kubeapilinter
128+
129+
## Excludes for kubeadm types
130+
# We want to align the FeatureGates field to the FeatureGates field in kubeadm.
131+
- path: "api/bootstrap/kubeadm/v1beta2/*|api/bootstrap/kubeadm/v1beta1/*"
132+
text: "nomaps: FeatureGates should not use a map type, use a list type with a unique name/identifier instead"
133+
linters:
134+
- kubeapilinter
114135

115136
## TODO: The following rules are disabled until we migrate to the new API.
116137
# Note: Maybe this has to stay a pointer for marshalling reasons.

api/bootstrap/kubeadm/v1beta1/zz_generated.conversion.go

Lines changed: 0 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/bootstrap/kubeadm/v1beta2/conversion.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ func (*KubeadmConfig) Hub() {}
2929
func (*KubeadmConfigTemplate) Hub() {}
3030

3131
func (*ClusterConfiguration) Hub() {}
32-
func (*ClusterStatus) Hub() {}
3332
func (*InitConfiguration) Hub() {}
3433
func (*JoinConfiguration) Hub() {}
3534

api/bootstrap/kubeadm/v1beta2/kubeadm_types.go

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -239,22 +239,6 @@ type ImageMeta struct {
239239
// TODO: evaluate if we need also a ImageName based on user feedbacks
240240
}
241241

242-
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
243-
244-
// ClusterStatus contains the cluster status. The ClusterStatus will be stored in the kubeadm-config
245-
// ConfigMap in the cluster, and then updated by kubeadm when additional control plane instance joins or leaves the cluster.
246-
//
247-
// Deprecated: ClusterStatus has been removed from kubeadm v1beta3 API; This type is preserved only to support
248-
// conversion to older versions of the kubeadm API.
249-
type ClusterStatus struct {
250-
metav1.TypeMeta `json:",inline"`
251-
252-
// apiEndpoints currently available in the cluster, one for each control plane/api server instance.
253-
// The key of the map is the IP of the host's default interface
254-
// +optional
255-
APIEndpoints map[string]APIEndpoint `json:"apiEndpoints"`
256-
}
257-
258242
// APIEndpoint struct contains elements of API server instance deployed on a node.
259243
type APIEndpoint struct {
260244
// advertiseAddress sets the IP address for the API server to advertise.

api/bootstrap/kubeadm/v1beta2/zz_generated.deepcopy.go

Lines changed: 0 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/core/v1beta1/conversion.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,17 @@ func Convert_v1beta2_ClusterStatus_To_v1beta1_ClusterStatus(in *clusterv1.Cluste
321321
out.InfrastructureReady = in.Initialization.InfrastructureProvisioned
322322
}
323323

324+
// Move FailureDomains
325+
if in.FailureDomains != nil {
326+
out.FailureDomains = FailureDomains{}
327+
for _, fd := range in.FailureDomains {
328+
out.FailureDomains[fd.Name] = FailureDomainSpec{
329+
ControlPlane: fd.ControlPlane,
330+
Attributes: fd.Attributes,
331+
}
332+
}
333+
}
334+
324335
// Move new conditions (v1beta2), controlPlane and workers counters to the v1beta2 field.
325336
if in.Conditions == nil && in.ControlPlane == nil && in.Workers == nil {
326337
return nil
@@ -399,6 +410,18 @@ func Convert_v1beta1_ClusterStatus_To_v1beta2_ClusterStatus(in *ClusterStatus, o
399410
out.Initialization.InfrastructureProvisioned = in.InfrastructureReady
400411
}
401412

413+
// Move FailureDomains
414+
if in.FailureDomains != nil {
415+
out.FailureDomains = []clusterv1.FailureDomain{}
416+
for name, fd := range in.FailureDomains {
417+
out.FailureDomains = append(out.FailureDomains, clusterv1.FailureDomain{
418+
Name: name,
419+
ControlPlane: fd.ControlPlane,
420+
Attributes: fd.Attributes,
421+
})
422+
}
423+
}
424+
402425
// Move legacy conditions (v1beta1), FailureReason and FailureMessage to the deprecated field.
403426
if in.Conditions == nil && in.FailureReason == nil && in.FailureMessage == nil {
404427
return nil

api/core/v1beta1/zz_generated.conversion.go

Lines changed: 2 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/core/v1beta2/cluster_types.go

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
2727
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2828
"k8s.io/apimachinery/pkg/types"
29-
"k8s.io/utils/ptr"
3029

3130
capierrors "sigs.k8s.io/cluster-api/errors"
3231
)
@@ -976,7 +975,11 @@ type ClusterStatus struct {
976975

977976
// failureDomains is a slice of failure domain objects synced from the infrastructure provider.
978977
// +optional
979-
FailureDomains FailureDomains `json:"failureDomains,omitempty"`
978+
// +listType=map
979+
// +listMapKey=name
980+
// +kubebuilder:validation:MinItems=1
981+
// +kubebuilder:validation:MaxItems=100
982+
FailureDomains []FailureDomain `json:"failureDomains,omitempty"`
980983

981984
// phase represents the current phase of cluster actuation.
982985
// +optional
@@ -1235,33 +1238,15 @@ func init() {
12351238
objectTypes = append(objectTypes, &Cluster{}, &ClusterList{})
12361239
}
12371240

1238-
// FailureDomains is a slice of FailureDomains.
1239-
type FailureDomains map[string]FailureDomainSpec
1240-
1241-
// FilterControlPlane returns a FailureDomain slice containing only the domains suitable to be used
1242-
// for control plane nodes.
1243-
func (in FailureDomains) FilterControlPlane() FailureDomains {
1244-
res := make(FailureDomains)
1245-
for id, spec := range in {
1246-
if spec.ControlPlane {
1247-
res[id] = spec
1248-
}
1249-
}
1250-
return res
1251-
}
1252-
1253-
// GetIDs returns a slice containing the ids for failure domains.
1254-
func (in FailureDomains) GetIDs() []*string {
1255-
ids := make([]*string, 0, len(in))
1256-
for id := range in {
1257-
ids = append(ids, ptr.To(id))
1258-
}
1259-
return ids
1260-
}
1261-
1262-
// FailureDomainSpec is the Schema for Cluster API failure domains.
1241+
// FailureDomain is the Schema for Cluster API failure domains.
12631242
// It allows controllers to understand how many failure domains a cluster can optionally span across.
1264-
type FailureDomainSpec struct {
1243+
type FailureDomain struct {
1244+
// name is the name of the failure domain.
1245+
// +required
1246+
// +kubebuilder:validation:MinLength=1
1247+
// +kubebuilder:validation:MaxLength=256
1248+
Name string `json:"name"`
1249+
12651250
// controlPlane determines if this failure domain is suitable for use by control plane machines.
12661251
// +optional
12671252
ControlPlane bool `json:"controlPlane,omitempty"`

api/core/v1beta2/clusterclass_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ type MachineDeploymentClass struct {
280280
MachineHealthCheck *MachineHealthCheckClass `json:"machineHealthCheck,omitempty"`
281281

282282
// failureDomain is the failure domain the machines will be created in.
283-
// Must match a key in the FailureDomains map stored on the cluster object.
283+
// Must match the name of a FailureDomain from the Cluster status.
284284
// NOTE: This value can be overridden while defining a Cluster.Topology using this MachineDeploymentClass.
285285
// +optional
286286
// +kubebuilder:validation:MinLength=1

api/core/v1beta2/machine_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ type MachineSpec struct {
418418
ProviderID *string `json:"providerID,omitempty"`
419419

420420
// failureDomain is the failure domain the machine will be created in.
421-
// Must match a key in the FailureDomains map stored on the cluster object.
421+
// Must match the name of a FailureDomain from the Cluster status.
422422
// +optional
423423
// +kubebuilder:validation:MinLength=1
424424
// +kubebuilder:validation:MaxLength=256

0 commit comments

Comments
 (0)