Skip to content

Commit a067572

Browse files
committed
experiment
1 parent df2839e commit a067572

File tree

12 files changed

+60
-13
lines changed

12 files changed

+60
-13
lines changed

.golangci-kal.yml

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@ linters:
4343
isFirstField: Warn # Require conditions to be the first field in the status struct.
4444
usePatchStrategy: Forbid # Require conditions to be the first field in the status struct.
4545
useProtobuf: Forbid # We don't use protobuf, so protobuf tags are not required.
46-
# jsonTags:
47-
# jsonTagRegex: "^[a-z][a-z0-9]*(?:[A-Z][a-z0-9]*)*$" # The default regex is appropriate for our use case.
48-
# optionalOrRequired:
49-
# preferredOptionalMarker: optional | kubebuilder:validation:Optional # The preferred optional marker to use, fixes will suggest to use this marker. Defaults to `optional`.
50-
# preferredRequiredMarker: required | kubebuilder:validation:Required # The preferred required marker to use, fixes will suggest to use this marker. Defaults to `required`.
5146
optionalFields:
5247
pointers:
53-
preference: Always # Always | WhenRequired # Whether to always require pointers, or only when required. Defaults to `Always`.
48+
preference: WhenRequired # Always | WhenRequired # Whether to always require pointers, or only when required. Defaults to `Always`.
5449
policy: SuggestFix # SuggestFix | Warn # The policy for pointers in optional fields. Defaults to `SuggestFix`.
5550
omitempty:
5651
policy: SuggestFix # SuggestFix | Warn | Ignore # The policy for omitempty in optional fields. Defaults to `SuggestFix`.
52+
# jsonTags:
53+
# jsonTagRegex: "^[a-z][a-z0-9]*(?:[A-Z][a-z0-9]*)*$" # The default regex is appropriate for our use case.
54+
# optionalOrRequired:
55+
# preferredOptionalMarker: optional | kubebuilder:validation:Optional # The preferred optional marker to use, fixes will suggest to use this marker. Defaults to `optional`.
56+
# preferredRequiredMarker: required | kubebuilder:validation:Required # The preferred required marker to use, fixes will suggest to use this marker. Defaults to `required`.
5757
# requiredFields:
5858
# pointerPolicy: Warn | SuggestFix # Defaults to `SuggestFix`. We want our required fields to not be pointers.
5959

@@ -78,7 +78,7 @@ linters:
7878
text: "Conditions field must be a slice of metav1.Condition"
7979
linters:
8080
- kubeapilinter
81-
- path: "api/addons/v1beta1/*|api/bootstrap/kubeadm/v1beta1/*|api/controlplane/kubeadm/v1beta1/*|api/core/v1beta1/*|api/ipam/v1beta1/*|api/ipam/v1alpha1/*|api/runtime/v1alpha1/*"
81+
- path: "api/addons/v1beta1/*|api/bootstrap/kubeadm/v1beta1/*|api/controlplane/kubeadm/v1beta1/*|api/core/v1beta1/*|api/ipam/v1beta1/*|api/ipam/v1alpha1/*|api/runtime/v1alpha1/*|cmd/clusterctl/api/v1alpha3/*"
8282
text: "optionalfields"
8383
linters:
8484
- kubeapilinter
@@ -155,6 +155,17 @@ linters:
155155
text: "field Ref is marked as required, should not be a pointer"
156156
linters:
157157
- kubeapilinter
158+
159+
## TODO: optional required tasks.
160+
- path: ".*"
161+
text: "field Spec|Status is optional"
162+
linters:
163+
- kubeapilinter
164+
# Audit the entire hook types + builtins from a serialization point of view (this is not a CRD)
165+
- path: "api/runtime/hooks/v1alpha1/*"
166+
text: "optionalfields"
167+
linters:
168+
- kubeapilinter
158169
issues:
159170
max-same-issues: 0
160171
max-issues-per-linter: 0

api/addons/v1beta2/clusterresourceset_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ type ClusterResourceSetStatus struct {
129129

130130
// observedGeneration reflects the generation of the most recently observed ClusterResourceSet.
131131
// +optional
132+
// +kubebuilder:validation:Minimum=1
132133
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
133134

134135
// deprecated groups all the status fields that are deprecated and will be removed when all the nested field are removed.

api/bootstrap/kubeadm/v1beta2/kubeadm_types.go

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +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
8889
NodeRegistration NodeRegistrationOptions `json:"nodeRegistration,omitempty"`
8990

9091
// localAPIEndpoint represents the endpoint of the API server instance that's deployed on this control plane node
@@ -94,6 +95,7 @@ type InitConfiguration struct {
9495
// on. By default, kubeadm tries to auto-detect the IP of the default interface and use that, but in case that process
9596
// fails you may set the desired value here.
9697
// +optional
98+
// +kubebuilder:validation:MinProperties=1
9799
LocalAPIEndpoint APIEndpoint `json:"localAPIEndpoint,omitempty"`
98100

99101
// skipPhases is a list of phases to skip during command execution.
@@ -120,22 +122,27 @@ type ClusterConfiguration struct {
120122
// etcd holds configuration for etcd.
121123
// NB: This value defaults to a Local (stacked) etcd
122124
// +optional
123-
Etcd Etcd `json:"etcd,omitempty"`
125+
// +kubebuilder:validation:MinProperties=1
126+
Etcd Etcd `json:"etcd,omitempty"` // FIXME: consider omitzero
124127

125128
// apiServer contains extra settings for the API server control plane component
126129
// +optional
130+
// +kubebuilder:validation:MinProperties=1
127131
APIServer APIServer `json:"apiServer,omitempty"`
128132

129133
// controllerManager contains extra settings for the controller manager control plane component
130134
// +optional
131-
ControllerManager ControlPlaneComponent `json:"controllerManager,omitempty"`
135+
// +kubebuilder:validation:MinProperties=1
136+
ControllerManager ControlPlaneComponent `json:"controllerManager,omitempty"` // FIXME: replace with ControllerManager struct
132137

133138
// scheduler contains extra settings for the scheduler control plane component
134139
// +optional
135-
Scheduler ControlPlaneComponent `json:"scheduler,omitempty"`
140+
// +kubebuilder:validation:MinProperties=1
141+
Scheduler ControlPlaneComponent `json:"scheduler,omitempty"` // FIXME: replace with Scheduler struct
136142

137143
// dns defines the options for the DNS add-on installed in the cluster.
138144
// +optional
145+
// +kubebuilder:validation:MinProperties=1
139146
DNS DNS `json:"dns,omitempty"`
140147

141148
// certificatesDir specifies where to store or look for all required certificates.
@@ -396,7 +403,6 @@ type BootstrapToken struct {
396403

397404
// Etcd contains elements describing Etcd configuration.
398405
type Etcd struct {
399-
400406
// local provides configuration knobs for configuring the local etcd instance
401407
// Local and External are mutually exclusive
402408
// +optional
@@ -492,6 +498,7 @@ type JoinConfiguration struct {
492498
// When used in the context of control plane nodes, NodeRegistration should remain consistent
493499
// across both InitConfiguration and JoinConfiguration
494500
// +optional
501+
// +kubebuilder:validation:MinProperties=1
495502
NodeRegistration NodeRegistrationOptions `json:"nodeRegistration,omitempty"`
496503

497504
// caCertPath is the path to the SSL certificate authority used to
@@ -506,6 +513,8 @@ type JoinConfiguration struct {
506513
// discovery specifies the options for the kubelet to use during the TLS Bootstrap process
507514
// +optional
508515
// TODO: revisit when there is defaulting from k/k
516+
// +kubebuilder:validation:MinProperties=1
517+
// FIXME: double check that one of BootstrapToken or File must be set
509518
Discovery Discovery `json:"discovery,omitempty"`
510519

511520
// controlPlane defines the additional control plane instance to be deployed on the joining node.
@@ -536,6 +545,7 @@ type JoinConfiguration struct {
536545
type JoinControlPlane struct {
537546
// localAPIEndpoint represents the endpoint of the API server instance to be deployed on this node.
538547
// +optional
548+
// +kubebuilder:validation:MinProperties=1
539549
LocalAPIEndpoint APIEndpoint `json:"localAPIEndpoint,omitempty"`
540550
}
541551

api/bootstrap/kubeadm/v1beta2/kubeadmconfig_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,7 @@ type KubeadmConfigStatus struct {
472472

473473
// observedGeneration is the latest generation observed by the controller.
474474
// +optional
475+
// +kubebuilder:validation:Minimum=1
475476
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
476477

477478
// deprecated groups all the status fields that are deprecated and will be removed when all the nested field are removed.

api/controlplane/kubeadm/v1beta2/kubeadm_control_plane_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,7 @@ type KubeadmControlPlaneStatus struct {
676676

677677
// observedGeneration is the latest generation observed by the controller.
678678
// +optional
679+
// +kubebuilder:validation:Minimum=1
679680
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
680681

681682
// lastRemediation stores info about last remediation performed.

api/core/v1beta2/cluster_types.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,11 @@ type Topology struct {
549549

550550
// controlPlane describes the cluster control plane.
551551
// +optional
552+
// +kubebuilder:validation:MinProperties=1
553+
// FIXME: double check if ratcheting ensures this won't break pre-existing objects
554+
// * P0: storage migration + conversion probably removes empty {}, if we fix marshalling on our v1beta2 structs (e.g. omitzero)
555+
// * CRD ratcheting was enabled per default with v1.30, GA with v1.33 => Cluster API min mgmt is v1.30
556+
// * which use cases are actually breaking (does it also break updates that only try to modify other fields)
552557
ControlPlane ControlPlaneTopology `json:"controlPlane,omitempty"`
553558

554559
// workers encapsulates the different constructs that form the worker nodes
@@ -597,6 +602,7 @@ type ControlPlaneTopology struct {
597602
// is applied only to the ControlPlane.
598603
// At runtime this metadata is merged with the corresponding metadata from the ClusterClass.
599604
// +optional
605+
// +kubebuilder:validation:MinProperties=1
600606
Metadata ObjectMeta `json:"metadata,omitempty"`
601607

602608
// replicas is the number of control plane nodes.
@@ -675,6 +681,7 @@ type MachineDeploymentTopology struct {
675681
// metadata is the metadata applied to the MachineDeployment and the machines of the MachineDeployment.
676682
// At runtime this metadata is merged with the corresponding metadata from the ClusterClass.
677683
// +optional
684+
// +kubebuilder:validation:MinProperties=1
678685
Metadata ObjectMeta `json:"metadata,omitempty"`
679686

680687
// class is the name of the MachineDeploymentClass used to create the set of worker nodes.
@@ -789,6 +796,7 @@ type MachinePoolTopology struct {
789796
// metadata is the metadata applied to the MachinePool.
790797
// At runtime this metadata is merged with the corresponding metadata from the ClusterClass.
791798
// +optional
799+
// +kubebuilder:validation:MinProperties=1
792800
Metadata ObjectMeta `json:"metadata,omitempty"`
793801

794802
// class is the name of the MachinePoolClass used to create the pool of worker nodes.
@@ -997,6 +1005,7 @@ type ClusterStatus struct {
9971005

9981006
// observedGeneration is the latest generation observed by the controller.
9991007
// +optional
1008+
// +kubebuilder:validation:Minimum=1
10001009
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
10011010

10021011
// deprecated groups all the status fields that are deprecated and will be removed when all the nested field are removed.

api/core/v1beta2/clusterclass_types.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,20 @@ type ClusterClassSpec struct {
103103
// infrastructure is a reference to a local struct that holds the details
104104
// for provisioning the infrastructure cluster for the Cluster.
105105
// +optional
106+
// +kubebuilder:validation:MinProperties=1
106107
Infrastructure InfrastructureClass `json:"infrastructure,omitempty"`
107108

108109
// controlPlane is a reference to a local struct that holds the details
109110
// for provisioning the Control Plane for the Cluster.
110111
// +optional
112+
// +kubebuilder:validation:MinProperties=1
111113
ControlPlane ControlPlaneClass `json:"controlPlane,omitempty"`
112114

113115
// workers describes the worker nodes for the cluster.
114116
// It is a collection of node types which can be used to create
115117
// the worker nodes of the cluster.
116118
// +optional
119+
// +kubebuilder:validation:MinProperties=1
117120
Workers WorkersClass `json:"workers,omitempty"`
118121

119122
// variables defines the variables which can be configured
@@ -150,6 +153,7 @@ type ControlPlaneClass struct {
150153
// This field is supported if and only if the control plane provider template
151154
// referenced is Machine based.
152155
// +optional
156+
// +kubebuilder:validation:MinProperties=1
153157
Metadata ObjectMeta `json:"metadata,omitempty"`
154158

155159
// LocalObjectTemplate contains the reference to a provider-specific control plane template.
@@ -353,6 +357,7 @@ type MachineDeploymentClassTemplate struct {
353357
// metadata is the metadata applied to the MachineDeployment and the machines of the MachineDeployment.
354358
// At runtime this metadata is merged with the corresponding metadata from the topology.
355359
// +optional
360+
// +kubebuilder:validation:MinProperties=1
356361
Metadata ObjectMeta `json:"metadata,omitempty"`
357362

358363
// bootstrap contains the bootstrap template reference to be used
@@ -503,6 +508,7 @@ type MachinePoolClassTemplate struct {
503508
// metadata is the metadata applied to the MachinePool.
504509
// At runtime this metadata is merged with the corresponding metadata from the topology.
505510
// +optional
511+
// +kubebuilder:validation:MinProperties=1
506512
Metadata ObjectMeta `json:"metadata,omitempty"`
507513

508514
// bootstrap contains the bootstrap template reference to be used
@@ -560,6 +566,7 @@ type ClusterClassVariable struct {
560566
// Deprecated: This field is deprecated and will be removed when support for v1beta1 will be dropped. Please use XMetadata in JSONSchemaProps instead.
561567
//
562568
// +optional
569+
// +kubebuilder:validation:MinProperties=1
563570
DeprecatedV1Beta1Metadata ClusterClassVariableMetadata `json:"deprecatedV1Beta1Metadata,omitempty"`
564571

565572
// schema defines the schema of the variable.
@@ -1218,6 +1225,7 @@ type ClusterClassStatus struct {
12181225

12191226
// observedGeneration is the latest generation observed by the controller.
12201227
// +optional
1228+
// +kubebuilder:validation:Minimum=1
12211229
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
12221230

12231231
// deprecated groups all the status fields that are deprecated and will be removed when all the nested field are removed.
@@ -1286,6 +1294,7 @@ type ClusterClassStatusVariableDefinition struct {
12861294
// Deprecated: This field is deprecated and will be removed when support for v1beta1 will be dropped. Please use XMetadata in JSONSchemaProps instead.
12871295
//
12881296
// +optional
1297+
// +kubebuilder:validation:MinProperties=1
12891298
DeprecatedV1Beta1Metadata ClusterClassVariableMetadata `json:"deprecatedV1Beta1Metadata,omitempty"`
12901299

12911300
// schema defines the schema of the variable.

api/core/v1beta2/machine_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ type MachineStatus struct {
544544

545545
// observedGeneration is the latest generation observed by the controller.
546546
// +optional
547+
// +kubebuilder:validation:Minimum=1
547548
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
548549

549550
// deletion contains information relating to removal of the Machine.

api/core/v1beta2/machinedeployment_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ type MachineDeploymentStatus struct {
431431

432432
// observedGeneration is the generation observed by the deployment controller.
433433
// +optional
434+
// +kubebuilder:validation:Minimum=1
434435
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
435436

436437
// selector is the same as the label selector but in the string format to avoid introspection

api/core/v1beta2/machinehealthcheck_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@ type MachineHealthCheckStatus struct {
225225

226226
// observedGeneration is the latest generation observed by the controller.
227227
// +optional
228+
// +kubebuilder:validation:Minimum=1
228229
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
229230

230231
// targets shows the current list of machines the machine health check is watching

api/core/v1beta2/machinepool_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ type MachinePoolStatus struct {
147147

148148
// observedGeneration is the latest generation observed by the controller.
149149
// +optional
150+
// +kubebuilder:validation:Minimum=1
150151
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
151152

152153
// deprecated groups all the status fields that are deprecated and will be removed when all the nested field are removed.

api/core/v1beta2/machineset_types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ type MachineSetSpec struct {
8181
// template is the object that describes the machine that will be created if
8282
// insufficient replicas are detected.
8383
// Object references to custom resources are treated as templates.
84-
// +optional
85-
Template MachineTemplateSpec `json:"template,omitempty"`
84+
// +required
85+
Template MachineTemplateSpec `json:"template"`
8686

8787
// machineNamingStrategy allows changing the naming pattern used when creating Machines.
8888
// Note: InfraMachines & BootstrapConfigs will use the same name as the corresponding Machines.
@@ -312,6 +312,7 @@ type MachineSetStatus struct {
312312

313313
// observedGeneration reflects the generation of the most recently observed MachineSet.
314314
// +optional
315+
// +kubebuilder:validation:Minimum=1
315316
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
316317

317318
// deprecated groups all the status fields that are deprecated and will be removed when all the nested field are removed.

0 commit comments

Comments
 (0)