Skip to content

Commit 3b1fa37

Browse files
committed
Enable optionalfields linter
1 parent ce4c050 commit 3b1fa37

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

.golangci-kal.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ 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+
- "optionalfields" # Ensure that all fields marked as optional adhere to being pointers and
27+
# having the `omitempty` value in their `json` tag where appropriate.
2628
- "optionalorrequired" # Every field should be marked as `+optional` or `+required`.
2729
- "requiredfields" # Required fields should not be pointers, and should not have `omitempty`.
2830
- "statusoptional" # Ensure all first children within status should be optional.
@@ -46,6 +48,12 @@ linters:
4648
# optionalOrRequired:
4749
# preferredOptionalMarker: optional | kubebuilder:validation:Optional # The preferred optional marker to use, fixes will suggest to use this marker. Defaults to `optional`.
4850
# preferredRequiredMarker: required | kubebuilder:validation:Required # The preferred required marker to use, fixes will suggest to use this marker. Defaults to `required`.
51+
optionalFields:
52+
pointers:
53+
preference: Always # Always | WhenRequired # Whether to always require pointers, or only when required. Defaults to `Always`.
54+
policy: SuggestFix # SuggestFix | Warn # The policy for pointers in optional fields. Defaults to `SuggestFix`.
55+
omitempty:
56+
policy: SuggestFix # SuggestFix | Warn | Ignore # The policy for omitempty in optional fields. Defaults to `SuggestFix`.
4957
# requiredFields:
5058
# pointerPolicy: Warn | SuggestFix # Defaults to `SuggestFix`. We want our required fields to not be pointers.
5159

@@ -70,6 +78,10 @@ linters:
7078
text: "Conditions field must be a slice of metav1.Condition"
7179
linters:
7280
- kubeapilinter
81+
- path: "api/addons/v1beta1/*|api/bootstrap/kubeadm/v1beta1/*|api/controlplane/kubeadm/v1beta1/*|api/core/v1beta1/*|api/ipam/v1beta1/*|api/ipam/v1alpha1/*|api/runtime/v1alpha1/*"
82+
text: "optionalfields"
83+
linters:
84+
- kubeapilinter
7385
- path: "api/core/v1beta2/*|api/core/v1beta1/*"
7486
text: "field Conditions type Conditions must have a maximum items, add kubebuilder:validation:MaxItems marker"
7587
linters:

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-20250605073038-74075c8eae51
6+
version: v0.0.0-20250613105907-bce00ef0e9a6

0 commit comments

Comments
 (0)