Skip to content

Commit a679fc0

Browse files
committed
MinProperties, enum etc.
1 parent f2bd271 commit a679fc0

File tree

45 files changed

+415
-190
lines changed

Some content is hidden

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

45 files changed

+415
-190
lines changed

.golangci-kal.yml

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,35 @@ linters:
174174

175175
# https://github.com/kubernetes-sigs/cluster-api/pull/12431
176176
# https://github.com/kubernetes-sigs/cluster-api/pull/12435
177-
# Take a closer look
177+
# FIXME: this excludes too much atm (also things not fixed in the PRs)
178178
- path: ".*"
179179
text: "field Spec|Status is optional"
180180
linters:
181181
- kubeapilinter
182182

183+
# MinProperties PR: FIXME
184+
- path: "api/bootstrap/kubeadm/v1beta2/kubeadm_types.go"
185+
text: "optionalfields: field (NodeRegistration|LocalAPIEndpoint|Etcd|APIServer|ControllerManager|Scheduler|DNS|Discovery) is optional and should (be a pointer|have the omitempty tag)"
186+
linters:
187+
- kubeapilinter
188+
- path: "api/core/v1beta2/cluster_types.go"
189+
text: "optionalfields: field (ControlPlaneEndpoint|ControlPlane|Metadata) is optional and should (be a pointer|have the omitempty tag)"
190+
linters:
191+
- kubeapilinter
192+
- path: "api/core/v1beta2/clusterclass_types.go"
193+
text: "optionalfields: field (Workers|Metadata|DeprecatedV1Beta1Metadata) is optional and should (be a pointer|have the omitempty tag)"
194+
linters:
195+
- kubeapilinter
196+
- path: "api/ipam/v1beta2/ipaddressclaim_types.go"
197+
text: "optionalfields: field AddressRef is optional and should (be a pointer|have the omitempty tag)"
198+
linters:
199+
- kubeapilinter
200+
201+
# enum bug: https://github.com/kubernetes-sigs/kube-api-linter/issues/113
202+
- path: ".*"
203+
text: "optionalfields: field (Format|Encoding|Type) is optional and (should be a pointer|has a valid zero value)"
204+
linters:
205+
- kubeapilinter
183206
issues:
184207
max-same-issues: 0
185208
max-issues-per-linter: 0

api/bootstrap/kubeadm/v1beta1/conversion.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,15 @@ func Convert_v1beta2_KubeadmConfigStatus_To_v1beta1_KubeadmConfigStatus(in *boot
375375
return nil
376376
}
377377

378+
func Convert_v1beta2_ControllerManager_To_v1beta1_ControlPlaneComponent(in *bootstrapv1.ControllerManager, out *ControlPlaneComponent, s apimachineryconversion.Scope) error {
379+
380+
return Convert_v1beta2_ControlPlaneComponent_To_v1beta1_ControlPlaneComponent(&in.ControlPlaneComponent, out, s)
381+
}
382+
383+
func Convert_v1beta2_Scheduler_To_v1beta1_ControlPlaneComponent(in *bootstrapv1.Scheduler, out *ControlPlaneComponent, s apimachineryconversion.Scope) error {
384+
return Convert_v1beta2_ControlPlaneComponent_To_v1beta1_ControlPlaneComponent(&in.ControlPlaneComponent, out, s)
385+
}
386+
378387
func Convert_v1beta2_ControlPlaneComponent_To_v1beta1_ControlPlaneComponent(in *bootstrapv1.ControlPlaneComponent, out *ControlPlaneComponent, s apimachineryconversion.Scope) error {
379388
// Following fields require a custom conversions.
380389
out.ExtraArgs = bootstrapv1.ConvertFromArgs(in.ExtraArgs)
@@ -406,6 +415,14 @@ func Convert_v1beta1_APIServer_To_v1beta2_APIServer(in *APIServer, out *bootstra
406415
return autoConvert_v1beta1_APIServer_To_v1beta2_APIServer(in, out, s)
407416
}
408417

418+
func Convert_v1beta1_ControlPlaneComponent_To_v1beta2_ControllerManager(in *ControlPlaneComponent, out *bootstrapv1.ControllerManager, s apimachineryconversion.Scope) error {
419+
return Convert_v1beta1_ControlPlaneComponent_To_v1beta2_ControlPlaneComponent(in, &out.ControlPlaneComponent, s)
420+
}
421+
422+
func Convert_v1beta1_ControlPlaneComponent_To_v1beta2_Scheduler(in *ControlPlaneComponent, out *bootstrapv1.Scheduler, s apimachineryconversion.Scope) error {
423+
return Convert_v1beta1_ControlPlaneComponent_To_v1beta2_ControlPlaneComponent(in, &out.ControlPlaneComponent, s)
424+
}
425+
409426
func Convert_v1beta1_Discovery_To_v1beta2_Discovery(in *Discovery, out *bootstrapv1.Discovery, s apimachineryconversion.Scope) error {
410427
// Timeout has been removed in v1beta2
411428
return autoConvert_v1beta1_Discovery_To_v1beta2_Discovery(in, out, s)

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

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

api/bootstrap/kubeadm/v1beta2/kubeadm_types.go

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ type InitConfiguration struct {
8585
// When used in the context of control plane nodes, NodeRegistration should remain consistent
8686
// across both InitConfiguration and JoinConfiguration
8787
// +optional
88-
// +kubebuilder:validation:MinProperties=1
89-
NodeRegistration NodeRegistrationOptions `json:"nodeRegistration,omitempty,omitzero"` // nolint:kubeapilinter // nolint:kubeapilinter
88+
NodeRegistration NodeRegistrationOptions `json:"nodeRegistration,omitempty,omitzero"`
9089

9190
// localAPIEndpoint represents the endpoint of the API server instance that's deployed on this control plane node
9291
// In HA setups, this differs from ClusterConfiguration.ControlPlaneEndpoint in the sense that ControlPlaneEndpoint
@@ -95,8 +94,7 @@ type InitConfiguration struct {
9594
// on. By default, kubeadm tries to auto-detect the IP of the default interface and use that, but in case that process
9695
// fails you may set the desired value here.
9796
// +optional
98-
// +kubebuilder:validation:MinProperties=1
99-
LocalAPIEndpoint APIEndpoint `json:"localAPIEndpoint,omitempty,omitzero"` // nolint:kubeapilinter
97+
LocalAPIEndpoint APIEndpoint `json:"localAPIEndpoint,omitempty,omitzero"`
10098

10199
// skipPhases is a list of phases to skip during command execution.
102100
// The list of phases can be obtained with the "kubeadm init --help" command.
@@ -121,9 +119,9 @@ type InitConfiguration struct {
121119
type ClusterConfiguration struct {
122120
// etcd holds configuration for etcd.
123121
// NB: This value defaults to a Local (stacked) etcd
122+
// FIXME: double check that unsetting etcd still works: https://github.com/kubernetes-sigs/cluster-api/pull/12065
124123
// +optional
125-
// +kubebuilder:validation:MinProperties=1
126-
Etcd Etcd `json:"etcd,omitempty,omitzero"` // nolint:kubeapilinter // FIXME: double check that unsetting etcd still works: https://github.com/kubernetes-sigs/cluster-api/pull/12065
124+
Etcd Etcd `json:"etcd,omitempty,omitzero"`
127125

128126
// controlPlaneEndpoint sets a stable IP address or DNS name for the control plane; it
129127
// can be a valid IP address or a RFC-1123 DNS subdomain, both with optional TCP port.
@@ -144,23 +142,19 @@ type ClusterConfiguration struct {
144142

145143
// apiServer contains extra settings for the API server control plane component
146144
// +optional
147-
// +kubebuilder:validation:MinProperties=1
148-
APIServer APIServer `json:"apiServer,omitempty,omitzero"` // nolint:kubeapilinter
145+
APIServer APIServer `json:"apiServer,omitempty,omitzero"`
149146

150147
// controllerManager contains extra settings for the controller manager control plane component
151148
// +optional
152-
// +kubebuilder:validation:MinProperties=1
153-
ControllerManager ControlPlaneComponent `json:"controllerManager,omitempty,omitzero"` // nolint:kubeapilinter // FIXME: replace with ControllerManager struct
149+
ControllerManager ControllerManager `json:"controllerManager,omitempty,omitzero"`
154150

155151
// scheduler contains extra settings for the scheduler control plane component
156152
// +optional
157-
// +kubebuilder:validation:MinProperties=1
158-
Scheduler ControlPlaneComponent `json:"scheduler,omitempty,omitzero"` // nolint:kubeapilinter // FIXME: replace with Scheduler struct
153+
Scheduler Scheduler `json:"scheduler,omitempty,omitzero"`
159154

160155
// dns defines the options for the DNS add-on installed in the cluster.
161156
// +optional
162-
// +kubebuilder:validation:MinProperties=1
163-
DNS DNS `json:"dns,omitempty,omitzero"` // nolint:kubeapilinter
157+
DNS DNS `json:"dns,omitempty,omitzero"`
164158

165159
// certificatesDir specifies where to store or look for all required certificates.
166160
// NB: if not provided, this will default to `/etc/kubernetes/pki`
@@ -191,6 +185,7 @@ type ClusterConfiguration struct {
191185
}
192186

193187
// ControlPlaneComponent holds settings common to control plane component of the cluster.
188+
// +kubebuilder:validation:MinProperties=1
194189
type ControlPlaneComponent struct {
195190
// extraArgs is a list of args to pass to the control plane component.
196191
// The arg name must match the command line flag name except without leading dash(es).
@@ -229,7 +224,18 @@ type APIServer struct {
229224
CertSANs []string `json:"certSANs,omitempty"`
230225
}
231226

227+
// ControllerManager holds settings necessary for controller-manager deployments in the cluster.
228+
type ControllerManager struct {
229+
ControlPlaneComponent `json:",inline"`
230+
}
231+
232+
// Scheduler holds settings necessary for scheduler deployments in the cluster.
233+
type Scheduler struct {
234+
ControlPlaneComponent `json:",inline"`
235+
}
236+
232237
// DNS defines the DNS addon that should be used in the cluster.
238+
// +kubebuilder:validation:MinProperties=1
233239
type DNS struct {
234240
// ImageMeta allows to customize the image used for the DNS component
235241
ImageMeta `json:",inline"`
@@ -256,6 +262,7 @@ type ImageMeta struct {
256262
}
257263

258264
// APIEndpoint struct contains elements of API server instance deployed on a node.
265+
// +kubebuilder:validation:MinProperties=1
259266
type APIEndpoint struct {
260267
// advertiseAddress sets the IP address for the API server to advertise.
261268
// +optional
@@ -272,8 +279,9 @@ type APIEndpoint struct {
272279

273280
// NodeRegistrationOptions holds fields that relate to registering a new control-plane or node to the cluster, either via "kubeadm init" or "kubeadm join".
274281
// Note: The NodeRegistrationOptions struct has to be kept in sync with the structs in MarshalJSON.
282+
// FIXME: somehow cannot apply this marker to this struct? // +kubebuilder:validation:MinProperties=1
283+
// FIXME: maybe the marshal func? Check if we can just get rid of it => []Taints => *[]Taints
275284
type NodeRegistrationOptions struct {
276-
277285
// name is the `.Metadata.Name` field of the Node API object that will be created in this `kubeadm init` or `kubeadm join` operation.
278286
// This field is also used in the CommonName field of the kubelet's client certificate to the API server.
279287
// Defaults to the hostname of the node if not provided.
@@ -420,8 +428,8 @@ type BootstrapToken struct {
420428
}
421429

422430
// Etcd contains elements describing Etcd configuration.
431+
// +kubebuilder:validation:MinProperties=1
423432
type Etcd struct {
424-
425433
// local provides configuration knobs for configuring the local etcd instance
426434
// Local and External are mutually exclusive
427435
// +optional
@@ -518,8 +526,7 @@ type JoinConfiguration struct {
518526
// When used in the context of control plane nodes, NodeRegistration should remain consistent
519527
// across both InitConfiguration and JoinConfiguration
520528
// +optional
521-
// +kubebuilder:validation:MinProperties=1
522-
NodeRegistration NodeRegistrationOptions `json:"nodeRegistration,omitempty,omitzero"` // nolint:kubeapilinter
529+
NodeRegistration NodeRegistrationOptions `json:"nodeRegistration,omitempty,omitzero"`
523530

524531
// caCertPath is the path to the SSL certificate authority used to
525532
// secure communications between node and control-plane.
@@ -533,9 +540,8 @@ type JoinConfiguration struct {
533540
// discovery specifies the options for the kubelet to use during the TLS Bootstrap process
534541
// +optional
535542
// TODO: revisit when there is defaulting from k/k
536-
// +kubebuilder:validation:MinProperties=1
537543
// FIXME: double check that one of BootstrapToken or File must be set
538-
Discovery Discovery `json:"discovery,omitempty,omitzero"` // nolint:kubeapilinter
544+
Discovery Discovery `json:"discovery,omitempty,omitzero"`
539545

540546
// controlPlane defines the additional control plane instance to be deployed on the joining node.
541547
// If nil, no additional control plane instance will be deployed.
@@ -565,11 +571,11 @@ type JoinConfiguration struct {
565571
type JoinControlPlane struct {
566572
// localAPIEndpoint represents the endpoint of the API server instance to be deployed on this node.
567573
// +optional
568-
// +kubebuilder:validation:MinProperties=1
569-
LocalAPIEndpoint APIEndpoint `json:"localAPIEndpoint,omitempty,omitzero"` // nolint:kubeapilinter
574+
LocalAPIEndpoint APIEndpoint `json:"localAPIEndpoint,omitempty,omitzero"`
570575
}
571576

572577
// Discovery specifies the options for the kubelet to use during the TLS Bootstrap process.
578+
// +kubebuilder:validation:MinProperties=1
573579
type Discovery struct {
574580
// bootstrapToken is used to set the options for bootstrap token based discovery
575581
// BootstrapToken and File are mutually exclusive

api/bootstrap/kubeadm/v1beta2/kubeadmconfig_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ type KubeadmConfigSpec struct {
116116

117117
// format specifies the output format of the bootstrap data
118118
// +optional
119-
Format Format `json:"format,omitempty"` // nolint:kubeapilinter // FIXME: Talk to Joel: optionalfields linter should be improved to detect enum on the type
119+
Format Format `json:"format,omitempty"`
120120

121121
// verbosity is the number for the kubeadm log level verbosity.
122122
// It overrides the `--v` flag in kubeadm commands.
@@ -630,7 +630,7 @@ type File struct {
630630

631631
// encoding specifies the encoding of the file contents.
632632
// +optional
633-
Encoding Encoding `json:"encoding,omitempty"` // nolint:kubeapilinter // FIXME: Talk to Joel: optionalfields linter should be improved to detect enum on the type
633+
Encoding Encoding `json:"encoding,omitempty"`
634634

635635
// append specifies whether to append Content to existing file if Path exists.
636636
// +optional

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

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

api/controlplane/kubeadm/v1beta2/kubeadm_control_plane_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ type RolloutStrategy struct {
538538
// "RollingUpdate".
539539
// Default is RollingUpdate.
540540
// +optional
541-
Type RolloutStrategyType `json:"type,omitempty"` // nolint:kubeapilinter // FIXME: Talk to Joel: optionalfields linter should be improved to detect enum on the type
541+
Type RolloutStrategyType `json:"type,omitempty"`
542542

543543
// rollingUpdate is the rolling update config params. Present only if
544544
// RolloutStrategyType = RollingUpdate.

0 commit comments

Comments
 (0)