Skip to content

Commit 0cae86e

Browse files
sbueringerk8s-infra-cherrypick-robot
authored andcommitted
Bump KAL to pick up latest requiredfields linter, add Min/MaxLength to BootstrapToken
1 parent d1e0c63 commit 0cae86e

File tree

7 files changed

+28
-78
lines changed

7 files changed

+28
-78
lines changed

.golangci-kal.yml

Lines changed: 17 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ linters:
2424
- "nobools" # Bools do not evolve over time, should use enums instead.
2525
- "nofloats" # Ensure floats are not used.
2626
- "nomaps" # Ensure maps are not used.
27+
- "notimestamp" # Prevents usage of 'Timestamp' fields
2728
- "optionalfields" # Ensure that all fields marked as optional adhere to being pointers and
2829
# having the `omitempty` value in their `json` tag where appropriate.
2930
- "optionalorrequired" # Every field should be marked as `+optional` or `+required`.
3031
- "requiredfields" # Required fields should not be pointers, and should not have `omitempty`.
3132
- "ssatags" # Ensure array fields have the appropriate listType markers
3233
- "statusoptional" # Ensure all first children within status should be optional.
3334
- "statussubresource" # All root objects that have a `status` field should have a status subresource.
34-
- "notimestamp" # Prevents usage of 'Timestamp' fields
3535
- "uniquemarkers" # Ensure that types and fields do not contain more than a single definition of a marker that should only be present once.
3636

3737
# Per discussion in July 2024, we are keeping phase fields for now.
@@ -60,15 +60,6 @@ linters:
6060
policy: SuggestFix # SuggestFix | Warn # The policy for pointers in optional fields. Defaults to `SuggestFix`.
6161
omitempty:
6262
policy: SuggestFix # SuggestFix | Warn | Ignore # The policy for omitempty in optional fields. Defaults to `SuggestFix`.
63-
# jsontags:
64-
# jsonTagRegex: "^[a-z][a-z0-9]*(?:[A-Z][a-z0-9]*)*$" # The default regex is appropriate for our use case.
65-
# optionalorrequired:
66-
# preferredOptionalMarker: optional | kubebuilder:validation:Optional # The preferred optional marker to use, fixes will suggest to use this marker. Defaults to `optional`.
67-
# preferredRequiredMarker: required | kubebuilder:validation:Required # The preferred required marker to use, fixes will suggest to use this marker. Defaults to `required`.
68-
# requiredfields:
69-
# pointerPolicy: Warn | SuggestFix # Defaults to `SuggestFix`. We want our required fields to not be pointers.
70-
# ssatags:
71-
# listTypeSetUsage: Warn | Ignore # The policy for listType=set usage on object arrays. Defaults to `Warn`.
7263

7364
exclusions:
7465
generated: strict
@@ -111,7 +102,7 @@ linters:
111102
## Excludes for current clusterctl v1alpha3 and Runtime Hooks v1alpha1 apiVersions (can be fixed once we bump their apiVersion).
112103
# Note: The types in api/runtime/hooks/v1alpha1 are not CRDs, so e.g. SSA markers don't make sense there.
113104
- path: "cmd/clusterctl/api/v1alpha3|api/runtime/hooks/v1alpha1"
114-
text: "optionalfields|maxlength|ssatags"
105+
text: "optionalfields|requiredfields|maxlength|ssatags"
115106
linters:
116107
- kubeapilinter
117108

@@ -138,7 +129,7 @@ linters:
138129
- kubeapilinter
139130
# It's simpler to check these fields against nil vs. using reflect.DeepEqual everywhere.
140131
- path: "api/core/v1beta2/clusterclass_types.go"
141-
text: "optionalfields: field (AdditionalProperties|Items|Not) (is optional and does not allow the zero value. It must have the omitzero tag|is optional and does not have a valid zero value. The field does not need to be a pointer)"
132+
text: "optionalfields: field (AdditionalProperties|Items|Not) does not allow the zero value. (The field does not need to be a pointer|It must have the omitzero tag)"
142133
linters:
143134
- kubeapilinter
144135

@@ -155,83 +146,32 @@ linters:
155146
linters:
156147
- kubeapilinter
157148

158-
## Excludes for optionalfields
149+
## Excludes for requiredfields
159150
# Empty Bootstrap object is blocked via validating webhooks. This cannot be detected by KAL (same if we move the validation to CEL).
160151
- path: "api/core/v1beta2/machine_types.go"
161-
text: "optionalfields: field (Bootstrap) is optional and (should be a pointer|should have the omitempty tag|has a valid zero value)"
152+
text: "requiredfields: field Bootstrap 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."
153+
linters:
154+
- kubeapilinter
155+
156+
## Excludes for optionalfields
157+
## The ExtraEnvs field intentionally has type *[]EnvVar.
158+
## Today we have MinItems=1, but we might have to support MinItems=0 in the future if kubeadm starts supporting it.
159+
- path: "api/bootstrap/kubeadm/v1beta2/kubeadm_types.go"
160+
text: "optionalfields: field ExtraEnvs does not allow the zero value. The field does not need to be a pointer."
162161
linters:
163162
- kubeapilinter
164163

165164
# TODO: Excludes that should be removed once the corresponding issues in KAL are fixed
166165
# KAL incorrectly reports that the Taints field doesn't have to be a pointer (it has to be to preserve []).
167166
# See: https://github.com/kubernetes-sigs/kube-api-linter/issues/116
168167
- path: "api/bootstrap/kubeadm/v1beta2/kubeadm_types.go"
169-
text: "optionalfields: field Taints is optional but the underlying type does not need to be a pointer. The pointer should be removed."
168+
text: "optionalfields: field Taints underlying type does not need to be a pointer. The pointer should be removed."
170169
linters:
171170
- kubeapilinter
171+
# KAL incorrectly reports that the zero value is valid
172+
# See: https://github.com/kubernetes-sigs/kube-api-linter/issues/138
172173
- path: "api/bootstrap/kubeadm/v1beta2/kubeadm_types.go"
173-
text: "optionalfields: field ExtraEnvs is optional and does not allow the zero value. The field does not need to be a pointer."
174-
linters:
175-
- kubeapilinter
176-
# KAL does not handle omitzero correctly yet: https://github.com/kubernetes-sigs/kube-api-linter/pull/115
177-
- path: "api/.*"
178-
text: "optionalfields: field (Status|Initialization) is optional and should (be a pointer|have the omitempty tag)"
179-
linters:
180-
- kubeapilinter
181-
- path: "api/.*"
182-
text: "optionalfields: field (LastAppliedTime|Expires|After|LastUpdated|CertificatesExpiryDate|NodeDrainStartTime|WaitForNodeVolumeDetachStartTime) is optional and should (be a pointer|have the omitempty tag)"
183-
linters:
184-
- kubeapilinter
185-
- path: "api/bootstrap/kubeadm/v1beta2"
186-
text: "optionalfields: field (Spec|NodeRegistration|LocalAPIEndpoint|Etcd|APIServer|ControllerManager|Scheduler|DNS|Discovery|ObjectMeta) is optional and should (be a pointer|have the omitempty tag)"
187-
linters:
188-
- kubeapilinter
189-
- path: "api/controlplane/kubeadm/v1beta2"
190-
text: "optionalfields: field (Spec|ObjectMeta|KubeadmConfigSpec|Remediation|Rollout|Before|Strategy|RollingUpdate|MachineTemplate) is optional and should (be a pointer|have the omitempty tag)"
191-
linters:
192-
- kubeapilinter
193-
- path: "api/core/v1beta2/cluster_types.go"
194-
text: "optionalfields: field (ClusterNetwork|Services|Pods|ControlPlaneEndpoint|ControlPlane|Workers|Metadata|Variables|Strategy|Rollout|RollingUpdate) is optional and should (be a pointer|have the omitempty tag)"
195-
linters:
196-
- kubeapilinter
197-
- path: "api/core/v1beta2/clusterclass_types.go"
198-
text: "optionalfields: field (Workers|Metadata|ControlPlane|Strategy|Infrastructure|DeprecatedV1Beta1Metadata|Rollout|RollingUpdate) is optional and should (be a pointer|have the omitempty tag)"
199-
linters:
200-
- kubeapilinter
201-
- path: "api/core/v1beta2/(cluster_types.go|clusterclass_types.go|machinehealthcheck_types.go)"
202-
text: "optionalfields: field (Checks|Remediation|TriggerIf) is optional and should (be a pointer|have the omitempty tag)"
203-
linters:
204-
- kubeapilinter
205-
- path: "api/core/v1beta2/machinedeployment_types.go"
206-
text: "optionalfields: field (Strategy|Rollout|RollingUpdate|Remediation) is optional and should (be a pointer|have the omitempty tag)"
207-
linters:
208-
- kubeapilinter
209-
- path: "api/ipam/v1beta2/ipaddressclaim_types.go"
210-
text: "optionalfields: field AddressRef is optional and should (be a pointer|have the omitempty tag)"
211-
linters:
212-
- kubeapilinter
213-
- path: "api/core/v1beta2/*|api/controlplane/kubeadm/v1beta2/*"
214-
text: "optionalfields: field (Naming|HealthCheck|MachineNaming|Deletion) is optional and should (be a pointer|have the omitempty tag)"
215-
linters:
216-
- kubeapilinter
217-
218-
# TODO: Excludes that should be removed once we will get the new version of the requiredfields linter
219-
- path: "api/.*"
220-
text: "requiredfields: field .* is marked as required, but has the omitempty tag"
221-
linters:
222-
- kubeapilinter
223-
- path: "api/.*"
224-
text: "requiredfields: field (Applied|Value|Layout|RetryCount|Required|Prefix|TimeoutSeconds) is marked as required, should not be a pointer"
225-
linters:
226-
- kubeapilinter
227-
228-
# TODO: Excludes that should be removed once https://github.com/kubernetes-sigs/kube-api-linter/issues/132 will be fixed
229-
- path: "api/.*"
230-
text: "optionalfields: field (.*) is optional and (should have the omitempty tag|should be a pointer)"
231-
linters:
232-
- kubeapilinter
233-
- path: "api/.*"
234-
text: "optionalfields: field (.*) 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."
174+
text: "requiredfields: field Token has a valid zero value \\({\"\": \"\", \"\": \"\"}\\) and should be a pointer."
235175
linters:
236176
- kubeapilinter
237177

api/bootstrap/kubeadm/v1beta2/kubeadm_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,8 @@ type HostPathMount struct {
954954
// "kubeadm join". This token is and should be short-lived.
955955
//
956956
// +kubebuilder:validation:Type=string
957+
// +kubebuilder:validation:MinLength=1
958+
// +kubebuilder:validation:MaxLength=23
957959
type BootstrapTokenString struct {
958960
ID string `json:"-"`
959961
Secret string `json:"-"`

bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml

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

bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml

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

controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml

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

controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanetemplates.yaml

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

hack/tools/.custom-gcl.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ name: golangci-lint-kube-api-linter
33
destination: ./bin
44
plugins:
55
- module: 'sigs.k8s.io/kube-api-linter'
6-
version: v0.0.0-20250729132427-47bfeef6cd38
6+
version: v0.0.0-20250808120943-48643eb2563d

0 commit comments

Comments
 (0)