Skip to content

Commit 5f657cf

Browse files
⚠️ Add omitempty to required string without zero value (#12548)
* Add omitempty to required string without zero value * Add temporary exclude rule * Add another temporary exclude rule * Drop omit empty on layout (it is not a string)
1 parent e9d395f commit 5f657cf

18 files changed

+94
-112
lines changed

.golangci-kal.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,17 @@ linters:
204204
linters:
205205
- kubeapilinter
206206

207+
# TODO: Excludes that should be removed once we will get the new version of the requiredfields linter
208+
- path: "api/.*"
209+
text: "requiredfields: field .* is marked as required, but has the omitempty tag"
210+
linters:
211+
- kubeapilinter
212+
213+
# TODO: Excludes that should be removed once https://github.com/kubernetes-sigs/kube-api-linter/issues/132 will be fixed
214+
- path: "api/ipam/v1beta2/ipaddressclaim_types.go"
215+
text: "optionalfields: field AddressRef is optional and has a valid zero value \\({}\\), but the validation is not complete \\(e.g. min properties/adding required fields\\). The field should be a pointer to allow the zero value to be set. If the zero value is not a valid use case, complete the validation and remove the pointer."
216+
linters:
217+
- kubeapilinter
207218
issues:
208219
max-same-issues: 0
209220
max-issues-per-linter: 0

api/addons/v1beta2/clusterresourceset_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,12 @@ type ResourceRef struct {
8888
// +required
8989
// +kubebuilder:validation:MinLength=1
9090
// +kubebuilder:validation:MaxLength=253
91-
Name string `json:"name"`
91+
Name string `json:"name,omitempty"`
9292

9393
// kind of the resource. Supported kinds are: Secrets and ConfigMaps.
9494
// +kubebuilder:validation:Enum=Secret;ConfigMap
9595
// +required
96-
Kind string `json:"kind"`
96+
Kind string `json:"kind,omitempty"`
9797
}
9898

9999
// ClusterResourceSetStrategy is a string representation of a ClusterResourceSet Strategy.

api/addons/v1beta2/clusterresourcesetbinding_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ type ResourceSetBinding struct {
4949
// +required
5050
// +kubebuilder:validation:MinLength=1
5151
// +kubebuilder:validation:MaxLength=253
52-
ClusterResourceSetName string `json:"clusterResourceSetName"`
52+
ClusterResourceSetName string `json:"clusterResourceSetName,omitempty"`
5353

5454
// resources is a list of resources that the ClusterResourceSet has.
5555
// +optional
@@ -140,7 +140,7 @@ type ClusterResourceSetBindingSpec struct {
140140
// +required
141141
// +kubebuilder:validation:MinLength=1
142142
// +kubebuilder:validation:MaxLength=63
143-
ClusterName string `json:"clusterName"`
143+
ClusterName string `json:"clusterName,omitempty"`
144144
}
145145

146146
// +kubebuilder:object:root=true

api/bootstrap/kubeadm/v1beta2/kubeadm_types.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -545,21 +545,21 @@ type ExternalEtcd struct {
545545
// +required
546546
// +kubebuilder:validation:MinLength=1
547547
// +kubebuilder:validation:MaxLength=512
548-
CAFile string `json:"caFile"`
548+
CAFile string `json:"caFile,omitempty"`
549549

550550
// certFile is an SSL certification file used to secure etcd communication.
551551
// Required if using a TLS connection.
552552
// +required
553553
// +kubebuilder:validation:MinLength=1
554554
// +kubebuilder:validation:MaxLength=512
555-
CertFile string `json:"certFile"`
555+
CertFile string `json:"certFile,omitempty"`
556556

557557
// keyFile is an SSL key file used to secure etcd communication.
558558
// Required if using a TLS connection.
559559
// +required
560560
// +kubebuilder:validation:MinLength=1
561561
// +kubebuilder:validation:MaxLength=512
562-
KeyFile string `json:"keyFile"`
562+
KeyFile string `json:"keyFile,omitempty"`
563563
}
564564

565565
// JoinConfiguration contains elements describing a particular node.
@@ -685,7 +685,7 @@ type FileDiscovery struct {
685685
// +required
686686
// +kubebuilder:validation:MinLength=1
687687
// +kubebuilder:validation:MaxLength=512
688-
KubeConfigPath string `json:"kubeConfigPath"`
688+
KubeConfigPath string `json:"kubeConfigPath,omitempty"`
689689

690690
// kubeConfig is used (optionally) to generate a KubeConfig based on the KubeadmConfig's information.
691691
// The file is generated at the path specified in KubeConfigPath.
@@ -785,7 +785,7 @@ type KubeConfigAuthProvider struct {
785785
// +required
786786
// +kubebuilder:validation:MinLength=1
787787
// +kubebuilder:validation:MaxLength=256
788-
Name string `json:"name"`
788+
Name string `json:"name,omitempty"`
789789

790790
// config holds the parameters for the authentication plugin.
791791
// +optional
@@ -802,7 +802,7 @@ type KubeConfigAuthExec struct {
802802
// +required
803803
// +kubebuilder:validation:MinLength=1
804804
// +kubebuilder:validation:MaxLength=1024
805-
Command string `json:"command"`
805+
Command string `json:"command,omitempty"`
806806

807807
// args is the arguments to pass to the command when executing it.
808808
// +optional
@@ -846,12 +846,13 @@ type KubeConfigAuthExecEnv struct {
846846
// +required
847847
// +kubebuilder:validation:MinLength=1
848848
// +kubebuilder:validation:MaxLength=512
849-
Name string `json:"name"`
849+
Name string `json:"name,omitempty"`
850+
850851
// value of the environment variable
851852
// +required
852853
// +kubebuilder:validation:MinLength=1
853854
// +kubebuilder:validation:MaxLength=512
854-
Value string `json:"value"`
855+
Value string `json:"value,omitempty"`
855856
}
856857

857858
// HostPathMount contains elements describing volumes that are mounted from the
@@ -861,21 +862,25 @@ type HostPathMount struct {
861862
// +required
862863
// +kubebuilder:validation:MinLength=1
863864
// +kubebuilder:validation:MaxLength=512
864-
Name string `json:"name"`
865+
Name string `json:"name,omitempty"`
866+
865867
// hostPath is the path in the host that will be mounted inside
866868
// the pod.
867869
// +required
868870
// +kubebuilder:validation:MinLength=1
869871
// +kubebuilder:validation:MaxLength=512
870-
HostPath string `json:"hostPath"`
872+
HostPath string `json:"hostPath,omitempty"`
873+
871874
// mountPath is the path inside the pod where hostPath will be mounted.
872875
// +required
873876
// +kubebuilder:validation:MinLength=1
874877
// +kubebuilder:validation:MaxLength=512
875-
MountPath string `json:"mountPath"`
878+
MountPath string `json:"mountPath,omitempty"`
879+
876880
// readOnly controls write access to the volume
877881
// +optional
878882
ReadOnly *bool `json:"readOnly,omitempty"`
883+
879884
// pathType is the type of the HostPath.
880885
// +optional
881886
PathType corev1.HostPathType `json:"pathType,omitempty"`
@@ -963,7 +968,7 @@ type Arg struct {
963968
// +required
964969
// +kubebuilder:validation:MinLength=1
965970
// +kubebuilder:validation:MaxLength=256
966-
Name string `json:"name"`
971+
Name string `json:"name,omitempty"`
967972

968973
// value is the Value of the extraArg.
969974
// +required

api/bootstrap/kubeadm/v1beta2/kubeadmconfig_types.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ type File struct {
611611
// +required
612612
// +kubebuilder:validation:MinLength=1
613613
// +kubebuilder:validation:MaxLength=512
614-
Path string `json:"path"`
614+
Path string `json:"path,omitempty"`
615615

616616
// owner specifies the ownership of the file, e.g. "root:root".
617617
// +optional
@@ -662,13 +662,13 @@ type SecretFileSource struct {
662662
// +required
663663
// +kubebuilder:validation:MinLength=1
664664
// +kubebuilder:validation:MaxLength=253
665-
Name string `json:"name"`
665+
Name string `json:"name,omitempty"`
666666

667667
// key is the key in the secret's data map for this value.
668668
// +required
669669
// +kubebuilder:validation:MinLength=1
670670
// +kubebuilder:validation:MaxLength=256
671-
Key string `json:"key"`
671+
Key string `json:"key,omitempty"`
672672
}
673673

674674
// PasswdSource is a union of all possible external source types for passwd data.
@@ -689,13 +689,13 @@ type SecretPasswdSource struct {
689689
// +required
690690
// +kubebuilder:validation:MinLength=1
691691
// +kubebuilder:validation:MaxLength=253
692-
Name string `json:"name"`
692+
Name string `json:"name,omitempty"`
693693

694694
// key is the key in the secret's data map for this value.
695695
// +required
696696
// +kubebuilder:validation:MinLength=1
697697
// +kubebuilder:validation:MaxLength=256
698-
Key string `json:"key"`
698+
Key string `json:"key,omitempty"`
699699
}
700700

701701
// User defines the input for a generated user in cloud-init.
@@ -704,7 +704,7 @@ type User struct {
704704
// +required
705705
// +kubebuilder:validation:MinLength=1
706706
// +kubebuilder:validation:MaxLength=256
707-
Name string `json:"name"`
707+
Name string `json:"name,omitempty"`
708708

709709
// gecos specifies the gecos to use for the user
710710
// +optional
@@ -807,16 +807,19 @@ type Partition struct {
807807
// +required
808808
// +kubebuilder:validation:MinLength=1
809809
// +kubebuilder:validation:MaxLength=256
810-
Device string `json:"device"`
810+
Device string `json:"device,omitempty"`
811+
811812
// layout specifies the device layout.
812813
// If it is true, a single partition will be created for the entire device.
813814
// When layout is false, it means don't partition or ignore existing partitioning.
814815
// +required
815816
Layout bool `json:"layout"`
817+
816818
// overwrite describes whether to skip checks and create the partition if a partition or filesystem is found on the device.
817819
// Use with caution. Default is 'false'.
818820
// +optional
819821
Overwrite *bool `json:"overwrite,omitempty"`
822+
820823
// tableType specifies the tupe of partition table. The following are supported:
821824
// 'mbr': default and setups a MS-DOS partition table
822825
// 'gpt': setups a GPT partition table
@@ -831,13 +834,13 @@ type Filesystem struct {
831834
// +required
832835
// +kubebuilder:validation:MinLength=1
833836
// +kubebuilder:validation:MaxLength=256
834-
Device string `json:"device"`
837+
Device string `json:"device,omitempty"`
835838

836839
// filesystem specifies the file system type.
837840
// +required
838841
// +kubebuilder:validation:MinLength=1
839842
// +kubebuilder:validation:MaxLength=128
840-
Filesystem string `json:"filesystem"`
843+
Filesystem string `json:"filesystem,omitempty"`
841844

842845
// label specifies the file system label to be used. If set to None, no label is used.
843846
// +optional

api/controlplane/kubeadm/v1beta2/kubeadm_control_plane_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ type KubeadmControlPlaneSpec struct {
432432
// +required
433433
// +kubebuilder:validation:MinLength=1
434434
// +kubebuilder:validation:MaxLength=256
435-
Version string `json:"version"`
435+
Version string `json:"version,omitempty"`
436436

437437
// machineTemplate contains information about how machines
438438
// should be shaped when creating or updating a control plane.
@@ -805,7 +805,7 @@ type LastRemediationStatus struct {
805805
// +required
806806
// +kubebuilder:validation:MinLength=1
807807
// +kubebuilder:validation:MaxLength=253
808-
Machine string `json:"machine"`
808+
Machine string `json:"machine,omitempty"`
809809

810810
// time is when last remediation happened. It is represented in RFC3339 form and is in UTC.
811811
// +required

api/core/v1beta2/cluster_types.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ type ClusterAvailabilityGate struct {
525525
// +kubebuilder:validation:Pattern=`^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$`
526526
// +kubebuilder:validation:MinLength=1
527527
// +kubebuilder:validation:MaxLength=316
528-
ConditionType string `json:"conditionType"`
528+
ConditionType string `json:"conditionType,omitempty"`
529529

530530
// polarity of the conditionType specified in this availabilityGate.
531531
// Valid values are Positive, Negative and omitted.
@@ -546,7 +546,7 @@ type Topology struct {
546546
// +required
547547
// +kubebuilder:validation:MinLength=1
548548
// +kubebuilder:validation:MaxLength=256
549-
Version string `json:"version"`
549+
Version string `json:"version,omitempty"`
550550

551551
// controlPlane describes the cluster control plane.
552552
// +optional
@@ -578,7 +578,7 @@ type ClusterClassRef struct {
578578
// +kubebuilder:validation:MinLength=1
579579
// +kubebuilder:validation:MaxLength=253
580580
// +kubebuilder:validation:Pattern=`^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$`
581-
Name string `json:"name"`
581+
Name string `json:"name,omitempty"`
582582

583583
// namespace is the namespace of the ClusterClass that should be used for the topology.
584584
// If namespace is empty or not set, it is defaulted to the namespace of the Cluster object.
@@ -822,7 +822,7 @@ type MachineDeploymentTopology struct {
822822
// +required
823823
// +kubebuilder:validation:MinLength=1
824824
// +kubebuilder:validation:MaxLength=256
825-
Class string `json:"class"`
825+
Class string `json:"class,omitempty"`
826826

827827
// name is the unique identifier for this MachineDeploymentTopology.
828828
// The value is used with other unique identifiers to create a MachineDeployment's Name
@@ -831,7 +831,7 @@ type MachineDeploymentTopology struct {
831831
// +required
832832
// +kubebuilder:validation:MinLength=1
833833
// +kubebuilder:validation:MaxLength=63
834-
Name string `json:"name"`
834+
Name string `json:"name,omitempty"`
835835

836836
// failureDomain is the failure domain the machines will be created in.
837837
// Must match a key in the FailureDomains map stored on the cluster object.
@@ -1132,7 +1132,7 @@ type MachinePoolTopology struct {
11321132
// +required
11331133
// +kubebuilder:validation:MinLength=1
11341134
// +kubebuilder:validation:MaxLength=256
1135-
Class string `json:"class"`
1135+
Class string `json:"class,omitempty"`
11361136

11371137
// name is the unique identifier for this MachinePoolTopology.
11381138
// The value is used with other unique identifiers to create a MachinePool's Name
@@ -1141,7 +1141,7 @@ type MachinePoolTopology struct {
11411141
// +required
11421142
// +kubebuilder:validation:MinLength=1
11431143
// +kubebuilder:validation:MaxLength=63
1144-
Name string `json:"name"`
1144+
Name string `json:"name,omitempty"`
11451145

11461146
// failureDomains is the list of failure domains the machine pool will be created in.
11471147
// Must match a key in the FailureDomains map stored on the cluster object.
@@ -1208,7 +1208,7 @@ type ClusterVariable struct {
12081208
// +required
12091209
// +kubebuilder:validation:MinLength=1
12101210
// +kubebuilder:validation:MaxLength=256
1211-
Name string `json:"name"`
1211+
Name string `json:"name,omitempty"`
12121212

12131213
// value of the variable.
12141214
// Note: the value will be validated against the schema of the corresponding ClusterClassVariable
@@ -1608,7 +1608,7 @@ type FailureDomain struct {
16081608
// +required
16091609
// +kubebuilder:validation:MinLength=1
16101610
// +kubebuilder:validation:MaxLength=256
1611-
Name string `json:"name"`
1611+
Name string `json:"name,omitempty"`
16121612

16131613
// controlPlane determines if this failure domain is suitable for use by control plane machines.
16141614
// +optional

0 commit comments

Comments
 (0)