Skip to content

Commit 3a40744

Browse files
authored
Merge pull request #12550 from fabriziopandini/omitzero-struct
⚠️ Add omitzero on struct without zero value
2 parents a61c0a9 + 773a8aa commit 3a40744

16 files changed

+31
-29
lines changed

api/bootstrap/kubeadm/v1beta2/kubeadm_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ type FileDiscoveryKubeConfig struct {
710710
// user contains information that describes identity information.
711711
// This is used to tell the kubernetes cluster who you are.
712712
// +required
713-
User KubeConfigUser `json:"user"`
713+
User KubeConfigUser `json:"user,omitempty,omitzero"`
714714
}
715715

716716
// KubeConfigCluster contains information about how to communicate with a kubernetes cluster.

api/bootstrap/kubeadm/v1beta2/kubeadmconfig_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ type File struct {
650650
type FileSource struct {
651651
// secret represents a secret that should populate this file.
652652
// +required
653-
Secret SecretFileSource `json:"secret"`
653+
Secret SecretFileSource `json:"secret,omitempty,omitzero"`
654654
}
655655

656656
// SecretFileSource adapts a Secret into a FileSource.
@@ -677,7 +677,7 @@ type SecretFileSource struct {
677677
type PasswdSource struct {
678678
// secret represents a secret that should populate this password.
679679
// +required
680-
Secret SecretPasswdSource `json:"secret"`
680+
Secret SecretPasswdSource `json:"secret,omitempty,omitzero"`
681681
}
682682

683683
// SecretPasswdSource adapts a Secret into a PasswdSource.

api/bootstrap/kubeadm/v1beta2/kubeadmconfigtemplate_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
type KubeadmConfigTemplateSpec struct {
2727
// template defines the desired state of KubeadmConfigTemplate.
2828
// +required
29-
Template KubeadmConfigTemplateResource `json:"template"`
29+
Template KubeadmConfigTemplateResource `json:"template,omitempty,omitzero"`
3030
}
3131

3232
// KubeadmConfigTemplateResource defines the Template structure.

api/controlplane/kubeadm/v1beta2/kubeadm_control_plane_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ type KubeadmControlPlaneSpec struct {
437437
// machineTemplate contains information about how machines
438438
// should be shaped when creating or updating a control plane.
439439
// +required
440-
MachineTemplate KubeadmControlPlaneMachineTemplate `json:"machineTemplate"`
440+
MachineTemplate KubeadmControlPlaneMachineTemplate `json:"machineTemplate,omitempty,omitzero"`
441441

442442
// kubeadmConfigSpec is a KubeadmConfigSpec
443443
// to use for initializing and joining machines to the control plane.
@@ -480,7 +480,7 @@ type KubeadmControlPlaneMachineTemplateSpec struct {
480480
// infrastructureRef is a required reference to a custom resource
481481
// offered by an infrastructure provider.
482482
// +required
483-
InfrastructureRef clusterv1.ContractVersionedObjectReference `json:"infrastructureRef"`
483+
InfrastructureRef clusterv1.ContractVersionedObjectReference `json:"infrastructureRef,omitempty,omitzero"`
484484

485485
// readinessGates specifies additional conditions to include when evaluating Machine Ready condition;
486486
// KubeadmControlPlane will always add readinessGates for the condition it is setting on the Machine:

api/controlplane/kubeadm/v1beta2/kubeadmcontrolplanetemplate_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
type KubeadmControlPlaneTemplateSpec struct {
2828
// template defines the desired state of KubeadmControlPlaneTemplate.
2929
// +required
30-
Template KubeadmControlPlaneTemplateResource `json:"template"`
30+
Template KubeadmControlPlaneTemplateResource `json:"template,omitempty,omitzero"`
3131
}
3232

3333
// +kubebuilder:object:root=true

api/core/v1beta2/cluster_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ type ClusterAvailabilityGate struct {
540540
type Topology struct {
541541
// classRef is the ref to the ClusterClass that should be used for the topology.
542542
// +required
543-
ClassRef ClusterClassRef `json:"classRef"`
543+
ClassRef ClusterClassRef `json:"classRef,omitempty,omitzero"`
544544

545545
// version is the Kubernetes version of the cluster.
546546
// +required

api/core/v1beta2/clusterclass_types.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -409,12 +409,12 @@ type MachineDeploymentClass struct {
409409
// bootstrap contains the bootstrap template reference to be used
410410
// for the creation of worker Machines.
411411
// +required
412-
Bootstrap MachineDeploymentClassBootstrapTemplate `json:"bootstrap"`
412+
Bootstrap MachineDeploymentClassBootstrapTemplate `json:"bootstrap,omitempty,omitzero"`
413413

414414
// infrastructure contains the infrastructure template reference to be used
415415
// for the creation of worker Machines.
416416
// +required
417-
Infrastructure MachineDeploymentClassInfrastructureTemplate `json:"infrastructure"`
417+
Infrastructure MachineDeploymentClassInfrastructureTemplate `json:"infrastructure,omitempty,omitzero"`
418418

419419
// healthCheck defines a MachineHealthCheck for this MachineDeploymentClass.
420420
// +optional
@@ -714,12 +714,12 @@ type MachinePoolClass struct {
714714
// bootstrap contains the bootstrap template reference to be used
715715
// for the creation of the Machines in the MachinePool.
716716
// +required
717-
Bootstrap MachinePoolClassBootstrapTemplate `json:"bootstrap"`
717+
Bootstrap MachinePoolClassBootstrapTemplate `json:"bootstrap,omitempty,omitzero"`
718718

719719
// infrastructure contains the infrastructure template reference to be used
720720
// for the creation of the MachinePool.
721721
// +required
722-
Infrastructure MachinePoolClassInfrastructureTemplate `json:"infrastructure"`
722+
Infrastructure MachinePoolClassInfrastructureTemplate `json:"infrastructure,omitempty,omitzero"`
723723

724724
// failureDomains is the list of failure domains the MachinePool should be attached to.
725725
// Must match a key in the FailureDomains map stored on the cluster object.
@@ -820,7 +820,7 @@ type ClusterClassVariable struct {
820820

821821
// schema defines the schema of the variable.
822822
// +required
823-
Schema VariableSchema `json:"schema"`
823+
Schema VariableSchema `json:"schema,omitempty,omitzero"`
824824
}
825825

826826
// ClusterClassVariableMetadata is the metadata of a variable.
@@ -848,7 +848,7 @@ type VariableSchema struct {
848848
// schema. The schema is a subset of the schema used in
849849
// Kubernetes CRDs.
850850
// +required
851-
OpenAPIV3Schema JSONSchemaProps `json:"openAPIV3Schema"`
851+
OpenAPIV3Schema JSONSchemaProps `json:"openAPIV3Schema,omitempty,omitzero"`
852852
}
853853

854854
// Adapted from https://github.com/kubernetes/apiextensions-apiserver/blob/v0.28.5/pkg/apis/apiextensions/v1/types_jsonschema.go#L40
@@ -1244,15 +1244,16 @@ type ClusterClassPatch struct {
12441244
type PatchDefinition struct {
12451245
// selector defines on which templates the patch should be applied.
12461246
// +required
1247-
Selector PatchSelector `json:"selector"`
1247+
Selector PatchSelector `json:"selector,omitempty,omitzero"`
12481248

12491249
// jsonPatches defines the patches which should be applied on the templates
12501250
// matching the selector.
12511251
// Note: Patches will be applied in the order of the array.
1252+
// +kubebuilder:validation:MinItems=1
12521253
// +kubebuilder:validation:MaxItems=100
12531254
// +required
12541255
// +listType=atomic
1255-
JSONPatches []JSONPatch `json:"jsonPatches"`
1256+
JSONPatches []JSONPatch `json:"jsonPatches,omitempty"`
12561257
}
12571258

12581259
// PatchSelector defines on which templates the patch should be applied.
@@ -1586,7 +1587,7 @@ type ClusterClassStatusVariableDefinition struct {
15861587

15871588
// schema defines the schema of the variable.
15881589
// +required
1589-
Schema VariableSchema `json:"schema"`
1590+
Schema VariableSchema `json:"schema,omitempty,omitzero"`
15901591
}
15911592

15921593
// GetV1Beta1Conditions returns the set of conditions for this object.

api/core/v1beta2/machine_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ type MachineSpec struct {
391391
// infrastructureRef is a required reference to a custom resource
392392
// offered by an infrastructure provider.
393393
// +required
394-
InfrastructureRef ContractVersionedObjectReference `json:"infrastructureRef"`
394+
InfrastructureRef ContractVersionedObjectReference `json:"infrastructureRef,omitempty,omitzero"`
395395

396396
// version defines the desired Kubernetes version.
397397
// This field is meant to be optionally used by bootstrap providers.

api/core/v1beta2/machinedeployment_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ type MachineDeploymentSpec struct {
274274

275275
// template describes the machines that will be created.
276276
// +required
277-
Template MachineTemplateSpec `json:"template"`
277+
Template MachineTemplateSpec `json:"template,omitempty,omitzero"`
278278

279279
// machineNaming allows changing the naming pattern used when creating Machines.
280280
// Note: InfraMachines & BootstrapConfigs will use the same name as the corresponding Machines.

api/core/v1beta2/machinedrainrules_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const (
4747
type MachineDrainRuleSpec struct {
4848
// drain configures if and how Pods are drained.
4949
// +required
50-
Drain MachineDrainRuleDrainConfig `json:"drain"`
50+
Drain MachineDrainRuleDrainConfig `json:"drain,omitempty,omitzero"`
5151

5252
// machines defines to which Machines this MachineDrainRule should be applied.
5353
//
@@ -212,7 +212,7 @@ type MachineDrainRule struct {
212212

213213
// spec defines the spec of a MachineDrainRule.
214214
// +required
215-
Spec MachineDrainRuleSpec `json:"spec"`
215+
Spec MachineDrainRuleSpec `json:"spec,omitempty,omitzero"`
216216
}
217217

218218
// +kubebuilder:object:root=true

0 commit comments

Comments
 (0)