Skip to content

Commit 1356666

Browse files
committed
Bump KAL to pick up latest requiredfields linter
1 parent 5cfc702 commit 1356666

File tree

2 files changed

+16
-81
lines changed

2 files changed

+16
-81
lines changed

.golangci-kal.yml

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

3636
# Per discussion in July 2024, we are keeping phase fields for now.
@@ -52,15 +52,6 @@ linters:
5252
policy: SuggestFix # SuggestFix | Warn # The policy for pointers in optional fields. Defaults to `SuggestFix`.
5353
omitempty:
5454
policy: SuggestFix # SuggestFix | Warn | Ignore # The policy for omitempty in optional fields. Defaults to `SuggestFix`.
55-
# jsontags:
56-
# jsonTagRegex: "^[a-z][a-z0-9]*(?:[A-Z][a-z0-9]*)*$" # The default regex is appropriate for our use case.
57-
# optionalorrequired:
58-
# preferredOptionalMarker: optional | kubebuilder:validation:Optional # The preferred optional marker to use, fixes will suggest to use this marker. Defaults to `optional`.
59-
# preferredRequiredMarker: required | kubebuilder:validation:Required # The preferred required marker to use, fixes will suggest to use this marker. Defaults to `required`.
60-
# requiredfields:
61-
# pointerPolicy: Warn | SuggestFix # Defaults to `SuggestFix`. We want our required fields to not be pointers.
62-
# ssatags:
63-
# listTypeSetUsage: Warn | Ignore # The policy for listType=set usage on object arrays. Defaults to `Warn`.
6455

6556
exclusions:
6657
generated: strict
@@ -103,7 +94,7 @@ linters:
10394
## Excludes for current clusterctl v1alpha3 and Runtime Hooks v1alpha1 apiVersions (can be fixed once we bump their apiVersion).
10495
# Note: The types in api/runtime/hooks/v1alpha1 are not CRDs, so e.g. SSA markers don't make sense there.
10596
- path: "cmd/clusterctl/api/v1alpha3|api/runtime/hooks/v1alpha1"
106-
text: "optionalfields|maxlength|ssatags"
97+
text: "optionalfields|requiredfields|maxlength|ssatags"
10798
linters:
10899
- kubeapilinter
109100

@@ -130,7 +121,7 @@ linters:
130121
- kubeapilinter
131122
# It's simpler to check these fields against nil vs. using reflect.DeepEqual everywhere.
132123
- path: "api/core/v1beta2/clusterclass_types.go"
133-
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)"
124+
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)"
134125
linters:
135126
- kubeapilinter
136127

@@ -147,83 +138,26 @@ linters:
147138
linters:
148139
- kubeapilinter
149140

150-
## Excludes for optionalfields
141+
## Excludes for requiredfields
151142
# Empty Bootstrap object is blocked via validating webhooks. This cannot be detected by KAL (same if we move the validation to CEL).
152143
- path: "api/core/v1beta2/machine_types.go"
153-
text: "optionalfields: field (Bootstrap) is optional and (should be a pointer|should have the omitempty tag|has a valid zero value)"
144+
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."
154145
linters:
155146
- kubeapilinter
156147

157-
# TODO: Excludes that should be removed once the corresponding issues in KAL are fixed
158-
# KAL incorrectly reports that the Taints field doesn't have to be a pointer (it has to be to preserve []).
159-
# See: https://github.com/kubernetes-sigs/kube-api-linter/issues/116
160-
- path: "api/bootstrap/kubeadm/v1beta2/kubeadm_types.go"
161-
text: "optionalfields: field Taints is optional but the underlying type does not need to be a pointer. The pointer should be removed."
162-
linters:
163-
- kubeapilinter
148+
## Excludes for optionalfields
149+
## The ExtraEnvs field intentionally has type *[]EnvVar.
150+
## Today we have MinItems=1, but we might have to support MinItems=0 in the future if kubeadm starts supporting it.
164151
- path: "api/bootstrap/kubeadm/v1beta2/kubeadm_types.go"
165-
text: "optionalfields: field ExtraEnvs is optional and does not allow the zero value. The field does not need to be a pointer."
166-
linters:
167-
- kubeapilinter
168-
# KAL does not handle omitzero correctly yet: https://github.com/kubernetes-sigs/kube-api-linter/pull/115
169-
- path: "api/.*"
170-
text: "optionalfields: field (Status|Initialization) is optional and should (be a pointer|have the omitempty tag)"
171-
linters:
172-
- kubeapilinter
173-
- path: "api/.*"
174-
text: "optionalfields: field (LastAppliedTime|Expires|After|LastUpdated|CertificatesExpiryDate|NodeDrainStartTime|WaitForNodeVolumeDetachStartTime) is optional and should (be a pointer|have the omitempty tag)"
175-
linters:
176-
- kubeapilinter
177-
- path: "api/bootstrap/kubeadm/v1beta2"
178-
text: "optionalfields: field (Spec|NodeRegistration|LocalAPIEndpoint|Etcd|APIServer|ControllerManager|Scheduler|DNS|Discovery|ObjectMeta) is optional and should (be a pointer|have the omitempty tag)"
179-
linters:
180-
- kubeapilinter
181-
- path: "api/controlplane/kubeadm/v1beta2"
182-
text: "optionalfields: field (Spec|ObjectMeta|KubeadmConfigSpec|Remediation|Rollout|Before|Strategy|RollingUpdate|MachineTemplate) is optional and should (be a pointer|have the omitempty tag)"
183-
linters:
184-
- kubeapilinter
185-
- path: "api/core/v1beta2/cluster_types.go"
186-
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)"
187-
linters:
188-
- kubeapilinter
189-
- path: "api/core/v1beta2/clusterclass_types.go"
190-
text: "optionalfields: field (Workers|Metadata|ControlPlane|Strategy|Infrastructure|DeprecatedV1Beta1Metadata|Rollout|RollingUpdate) is optional and should (be a pointer|have the omitempty tag)"
191-
linters:
192-
- kubeapilinter
193-
- path: "api/core/v1beta2/(cluster_types.go|clusterclass_types.go|machinehealthcheck_types.go)"
194-
text: "optionalfields: field (Checks|Remediation|TriggerIf) is optional and should (be a pointer|have the omitempty tag)"
195-
linters:
196-
- kubeapilinter
197-
- path: "api/core/v1beta2/machinedeployment_types.go"
198-
text: "optionalfields: field (Strategy|Rollout|RollingUpdate|Remediation) is optional and should (be a pointer|have the omitempty tag)"
199-
linters:
200-
- kubeapilinter
201-
- path: "api/ipam/v1beta2/ipaddressclaim_types.go"
202-
text: "optionalfields: field AddressRef is optional and should (be a pointer|have the omitempty tag)"
203-
linters:
204-
- kubeapilinter
205-
- path: "api/core/v1beta2/*|api/controlplane/kubeadm/v1beta2/*"
206-
text: "optionalfields: field (Naming|HealthCheck|MachineNaming|Deletion) is optional and should (be a pointer|have the omitempty tag)"
152+
text: "optionalfields: field ExtraEnvs does not allow the zero value. The field does not need to be a pointer."
207153
linters:
208154
- kubeapilinter
209155

210-
# TODO: Excludes that should be removed once we will get the new version of the requiredfields linter
211-
- path: "api/.*"
212-
text: "requiredfields: field .* is marked as required, but has the omitempty tag"
213-
linters:
214-
- kubeapilinter
215-
- path: "api/.*"
216-
text: "requiredfields: field (Applied|Value|Layout|RetryCount|Required|Prefix|TimeoutSeconds) is marked as required, should not be a pointer"
217-
linters:
218-
- kubeapilinter
219-
220-
# TODO: Excludes that should be removed once https://github.com/kubernetes-sigs/kube-api-linter/issues/132 will be fixed
221-
- path: "api/.*"
222-
text: "optionalfields: field (.*) is optional and (should have the omitempty tag|should be a pointer)"
223-
linters:
224-
- kubeapilinter
225-
- path: "api/.*"
226-
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."
156+
# TODO: Excludes that should be removed once the corresponding issues in KAL are fixed
157+
# KAL incorrectly reports that the Taints field doesn't have to be a pointer (it has to be to preserve []).
158+
# See: https://github.com/kubernetes-sigs/kube-api-linter/issues/116
159+
- path: "api/bootstrap/kubeadm/v1beta2/kubeadm_types.go"
160+
text: "optionalfields: field Taints underlying type does not need to be a pointer. The pointer should be removed."
227161
linters:
228162
- kubeapilinter
229163

hack/tools/.custom-gcl.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ name: golangci-lint-kube-api-linter
33
destination: ./bin
44
plugins:
55
- module: 'sigs.k8s.io/kube-api-linter'
6-
version: v0.0.0-20250723124831-1b29e82a0f55
6+
path: ../../../kube-api-linter
7+
# using JoelSpeed/required-fields-v2 branch for now

0 commit comments

Comments
 (0)