Skip to content

Commit c5bbc0c

Browse files
committed
Add omitempty/omitzero to required fields
1 parent 21c7313 commit c5bbc0c

16 files changed

+32
-27
lines changed

.golangci-kal.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ linters:
9595
text: "field Conditions type Conditions must have a maximum items, add kubebuilder:validation:MaxItems marker"
9696
linters:
9797
- kubeapilinter
98+
- path: "api/core/v1beta2/condition_types.go"
99+
text: "requiredfields: field (Type|Status|LastTransitionTime) should have the omitempty tag"
100+
linters:
101+
- kubeapilinter
98102

99103
## Excludes for current clusterctl v1alpha3 and Runtime Hooks v1alpha1 apiVersions (can be fixed once we bump their apiVersion).
100104
# Note: The types in api/runtime/hooks/v1alpha1 are not CRDs, so e.g. SSA markers don't make sense there.

api/addons/v1beta2/clusterresourceset_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,14 @@ type ClusterResourceSetSpec struct {
5858
// It must match the Cluster labels. This field is immutable.
5959
// Label selector cannot be empty.
6060
// +required
61-
ClusterSelector metav1.LabelSelector `json:"clusterSelector"`
61+
ClusterSelector metav1.LabelSelector `json:"clusterSelector,omitempty,omitzero"`
6262

6363
// resources is a list of Secrets/ConfigMaps where each contains 1 or more resources to be applied to remote clusters.
6464
// +required
6565
// +listType=atomic
6666
// +kubebuilder:validation:MinItems=1
6767
// +kubebuilder:validation:MaxItems=100
68-
Resources []ResourceRef `json:"resources"`
68+
Resources []ResourceRef `json:"resources,omitempty"`
6969

7070
// strategy is the strategy to be used during applying resources. Defaults to ApplyOnce. This field is immutable.
7171
// +kubebuilder:validation:Enum=ApplyOnce;Reconcile

api/bootstrap/kubeadm/v1beta2/kubeadm_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ type ExternalEtcd struct {
560560
// +kubebuilder:validation:MaxItems=50
561561
// +kubebuilder:validation:items:MinLength=1
562562
// +kubebuilder:validation:items:MaxLength=512
563-
Endpoints []string `json:"endpoints"`
563+
Endpoints []string `json:"endpoints,omitempty"`
564564

565565
// caFile is an SSL Certificate Authority file used to secure etcd communication.
566566
// Required if using a TLS connection.

api/controlplane/kubeadm/v1beta2/kubeadm_control_plane_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ type KubeadmControlPlaneRolloutStrategy struct {
569569
// "RollingUpdate".
570570
// Default is RollingUpdate.
571571
// +required
572-
Type KubeadmControlPlaneRolloutStrategyType `json:"type"`
572+
Type KubeadmControlPlaneRolloutStrategyType `json:"type,omitempty"`
573573

574574
// rollingUpdate is the rolling update config params. Present only if
575575
// type = RollingUpdate.
@@ -809,7 +809,7 @@ type LastRemediationStatus struct {
809809

810810
// time is when last remediation happened. It is represented in RFC3339 form and is in UTC.
811811
// +required
812-
Time metav1.Time `json:"time"`
812+
Time metav1.Time `json:"time,omitempty,omitzero"`
813813

814814
// retryCount used to keep track of remediation retry for the last remediated machine.
815815
// A retry happens when a machine that was created as a replacement for an unhealthy machine also fails.

api/core/v1beta2/cluster_types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,7 +1081,7 @@ type MachineDeploymentTopologyRolloutStrategy struct {
10811081
// type of rollout. Allowed values are RollingUpdate and OnDelete.
10821082
// Default is RollingUpdate.
10831083
// +required
1084-
Type MachineDeploymentRolloutStrategyType `json:"type"`
1084+
Type MachineDeploymentRolloutStrategyType `json:"type,omitempty"`
10851085

10861086
// rollingUpdate is the rolling update config params. Present only if
10871087
// type = RollingUpdate.
@@ -1225,7 +1225,7 @@ type ClusterVariable struct {
12251225
// i.e. it is not possible to have no type field.
12261226
// Ref: https://github.com/kubernetes-sigs/controller-tools/blob/d0e03a142d0ecdd5491593e941ee1d6b5d91dba6/pkg/crd/known_types.go#L106-L111
12271227
// +required
1228-
Value apiextensionsv1.JSON `json:"value"`
1228+
Value apiextensionsv1.JSON `json:"value,omitempty,omitzero"`
12291229
}
12301230

12311231
// ControlPlaneVariables can be used to provide variables for the ControlPlane.
@@ -1299,7 +1299,7 @@ type NetworkRanges struct {
12991299
// +kubebuilder:validation:MaxItems=100
13001300
// +kubebuilder:validation:items:MinLength=1
13011301
// +kubebuilder:validation:items:MaxLength=43
1302-
CIDRBlocks []string `json:"cidrBlocks"`
1302+
CIDRBlocks []string `json:"cidrBlocks,omitempty"`
13031303
}
13041304

13051305
func (n NetworkRanges) String() string {

api/core/v1beta2/clusterclass_types.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ type MachineDeploymentClassRolloutStrategy struct {
652652
// type of rollout. Allowed values are RollingUpdate and OnDelete.
653653
// Default is RollingUpdate.
654654
// +required
655-
Type MachineDeploymentRolloutStrategyType `json:"type"`
655+
Type MachineDeploymentRolloutStrategyType `json:"type,omitempty"`
656656

657657
// rollingUpdate is the rolling update config params. Present only if
658658
// type = RollingUpdate.
@@ -1280,12 +1280,13 @@ type PatchSelector struct {
12801280

12811281
// matchResources selects templates based on where they are referenced.
12821282
// +required
1283-
MatchResources PatchSelectorMatch `json:"matchResources"`
1283+
MatchResources PatchSelectorMatch `json:"matchResources,omitempty,omitzero"`
12841284
}
12851285

12861286
// PatchSelectorMatch selects templates based on where they are referenced.
12871287
// Note: The selector must match at least one template.
12881288
// Note: The results of selection based on the individual fields are ORed.
1289+
// +kubebuilder:validation:MinProperties=1
12891290
type PatchSelectorMatch struct {
12901291
// controlPlane selects templates referenced in .spec.ControlPlane.
12911292
// Note: this will match the controlPlane and also the controlPlane
@@ -1563,8 +1564,9 @@ type ClusterClassStatusVariable struct {
15631564
// definitions is a list of definitions for a variable.
15641565
// +required
15651566
// +listType=atomic
1567+
// +kubebuilder:validation:MinItems=1
15661568
// +kubebuilder:validation:MaxItems=100
1567-
Definitions []ClusterClassStatusVariableDefinition `json:"definitions"`
1569+
Definitions []ClusterClassStatusVariableDefinition `json:"definitions,omitempty"`
15681570
}
15691571

15701572
// ClusterClassStatusVariableDefinition defines a variable which appears in the status of a ClusterClass.

api/core/v1beta2/common_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ const (
292292
type MachineAddress struct {
293293
// type is the machine address type, one of Hostname, ExternalIP, InternalIP, ExternalDNS or InternalDNS.
294294
// +required
295-
Type MachineAddressType `json:"type"`
295+
Type MachineAddressType `json:"type,omitempty"`
296296

297297
// address is the machine address.
298298
// +required

api/core/v1beta2/machinedeployment_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ type MachineDeploymentSpec struct {
270270
// selected by this will be the ones affected by this deployment.
271271
// It must match the machine template's labels.
272272
// +required
273-
Selector metav1.LabelSelector `json:"selector"`
273+
Selector metav1.LabelSelector `json:"selector,omitempty,omitzero"`
274274

275275
// template describes the machines that will be created.
276276
// +required
@@ -318,7 +318,7 @@ type MachineDeploymentRolloutStrategy struct {
318318
// type of rollout. Allowed values are RollingUpdate and OnDelete.
319319
// Default is RollingUpdate.
320320
// +required
321-
Type MachineDeploymentRolloutStrategyType `json:"type"`
321+
Type MachineDeploymentRolloutStrategyType `json:"type,omitempty"`
322322

323323
// rollingUpdate is the rolling update config params. Present only if
324324
// type = RollingUpdate.

api/core/v1beta2/machinedrainrules_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ type MachineDrainRuleDrainConfig struct {
129129
// "WaitCompleted" means that the pods to which this MachineDrainRule applies will never be evicted
130130
// and we wait for them to be completed, it is enforced that pods marked with this behavior always have Order=0.
131131
// +required
132-
Behavior MachineDrainRuleDrainBehavior `json:"behavior"`
132+
Behavior MachineDrainRuleDrainBehavior `json:"behavior,omitempty"`
133133

134134
// order defines the order in which Pods are drained.
135135
// Pods with higher order are drained after Pods with lower order.

api/core/v1beta2/machinehealthcheck_types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ type MachineHealthCheckSpec struct {
5656

5757
// selector is a label selector to match machines whose health will be exercised
5858
// +required
59-
Selector metav1.LabelSelector `json:"selector"`
59+
Selector metav1.LabelSelector `json:"selector,omitempty,omitzero"`
6060

6161
// checks are the checks that are used to evaluate if a Machine is healthy.
6262
//
@@ -217,13 +217,13 @@ type UnhealthyNodeCondition struct {
217217
// +kubebuilder:validation:Type=string
218218
// +kubebuilder:validation:MinLength=1
219219
// +required
220-
Type corev1.NodeConditionType `json:"type"`
220+
Type corev1.NodeConditionType `json:"type,omitempty"`
221221

222222
// status of the condition, one of True, False, Unknown.
223223
// +kubebuilder:validation:Type=string
224224
// +kubebuilder:validation:MinLength=1
225225
// +required
226-
Status corev1.ConditionStatus `json:"status"`
226+
Status corev1.ConditionStatus `json:"status,omitempty"`
227227

228228
// timeoutSeconds is the duration that a node must be in a given status for,
229229
// after which the node is considered unhealthy.

0 commit comments

Comments
 (0)