Skip to content

Commit c974eea

Browse files
Merge pull request #2440 from JoelSpeed/update-kal-and-omitempty-policy
Update KAL to support new guidance on required and optional fields
2 parents 356d265 + 96c90e0 commit c974eea

File tree

13 files changed

+649
-325
lines changed

13 files changed

+649
-325
lines changed

.golangci.yaml

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,28 @@ linters:
2525
preference: WhenRequired
2626
policy: SuggestFix
2727
omitEmpty:
28-
# Ignore missing omitempty so that we can omit the omitempty for discoverability.
29-
# Discoverability is for configuration APIs, generally singletons.
30-
# Refer to the API conventions for when to use discoverability (not our default stance).
31-
policy: Ignore
28+
# This will force omitempty on optional fields.
29+
# This is in line with upstream guidance where optional fields should be omitted
30+
# from the serialized output unless they are non-zero.
31+
policy: SuggestFix
32+
omitzero:
33+
# This will force omitzero on optional struct fields.
34+
# This means they can be omitted correctly and prevents the need for pointers to structs.
35+
policy: SuggestFix
36+
requiredFields:
37+
pointers:
38+
# This will force pointers when the field is required, but only when the zero
39+
# value is a valid user choice, and has a semantic difference to being omitted (e.g. replicas allows 0).
40+
policy: SuggestFix
41+
omitempty:
42+
# This will force omitempty on required fields.
43+
# We do this so that the behaviour of not setting a value for the field is the same between
44+
# both structured and unstructured clients.
45+
policy: SuggestFix
46+
omitzero:
47+
# This will force omitzero on required struct fields.
48+
# This means they can be omitted correctly and prevents the need for pointers to structs.
49+
policy: SuggestFix
3250
uniqueMarkers:
3351
customMarkers:
3452
- identifier: "openshift:validation:FeatureGateAwareEnum"

tools/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ require (
3030
k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff
3131
k8s.io/utils v0.0.0-20250604170112-4c0f3b243397
3232
sigs.k8s.io/controller-tools v0.15.0
33-
sigs.k8s.io/kube-api-linter v0.0.0-20250729132427-47bfeef6cd38
33+
sigs.k8s.io/kube-api-linter v0.0.0-20250808120943-48643eb2563d
3434
sigs.k8s.io/yaml v1.4.0
3535
)
3636

tools/go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -994,6 +994,8 @@ sigs.k8s.io/kube-api-linter v0.0.0-20250723124831-1b29e82a0f55 h1:kD9x5uu1/A7wvh
994994
sigs.k8s.io/kube-api-linter v0.0.0-20250723124831-1b29e82a0f55/go.mod h1:Jxl3NU9lRf9WJ8dgwgF4U6tLF229jR/KEvtxSwRAKnE=
995995
sigs.k8s.io/kube-api-linter v0.0.0-20250729132427-47bfeef6cd38 h1:5WuFSvNbquqwM82aBQ36AfsFGsf2Jc0OJM4SCC2rw4w=
996996
sigs.k8s.io/kube-api-linter v0.0.0-20250729132427-47bfeef6cd38/go.mod h1:Jxl3NU9lRf9WJ8dgwgF4U6tLF229jR/KEvtxSwRAKnE=
997+
sigs.k8s.io/kube-api-linter v0.0.0-20250808120943-48643eb2563d h1:BcgCRoMLmIxRTLokQ1K1LAle+21fKPqgA6OvzN04xEg=
998+
sigs.k8s.io/kube-api-linter v0.0.0-20250808120943-48643eb2563d/go.mod h1:Jxl3NU9lRf9WJ8dgwgF4U6tLF229jR/KEvtxSwRAKnE=
997999
sigs.k8s.io/randfill v0.0.0-20250304075658-069ef1bbf016/go.mod h1:XeLlZ/jmk4i1HRopwe7/aU3H5n1zNUcX6TM94b3QxOY=
9981000
sigs.k8s.io/randfill v1.0.0 h1:JfjMILfT8A6RbawdsK2JXGBR5AQVfd+9TbzrlneTyrU=
9991001
sigs.k8s.io/randfill v1.0.0/go.mod h1:XeLlZ/jmk4i1HRopwe7/aU3H5n1zNUcX6TM94b3QxOY=

tools/vendor/modules.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2378,7 +2378,7 @@ sigs.k8s.io/controller-tools/pkg/webhook
23782378
## explicit; go 1.21
23792379
sigs.k8s.io/json
23802380
sigs.k8s.io/json/internal/golang/encoding/json
2381-
# sigs.k8s.io/kube-api-linter v0.0.0-20250729132427-47bfeef6cd38
2381+
# sigs.k8s.io/kube-api-linter v0.0.0-20250808120943-48643eb2563d
23822382
## explicit; go 1.24.0
23832383
sigs.k8s.io/kube-api-linter/pkg/analysis/commentstart
23842384
sigs.k8s.io/kube-api-linter/pkg/analysis/conditions
@@ -2406,6 +2406,7 @@ sigs.k8s.io/kube-api-linter/pkg/analysis/statusoptional
24062406
sigs.k8s.io/kube-api-linter/pkg/analysis/statussubresource
24072407
sigs.k8s.io/kube-api-linter/pkg/analysis/uniquemarkers
24082408
sigs.k8s.io/kube-api-linter/pkg/analysis/utils
2409+
sigs.k8s.io/kube-api-linter/pkg/analysis/utils/serialization
24092410
sigs.k8s.io/kube-api-linter/pkg/config
24102411
sigs.k8s.io/kube-api-linter/pkg/markers
24112412
sigs.k8s.io/kube-api-linter/pkg/plugin

tools/vendor/sigs.k8s.io/kube-api-linter/pkg/analysis/conflictingmarkers/doc.go

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

tools/vendor/sigs.k8s.io/kube-api-linter/pkg/analysis/optionalfields/analyzer.go

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

0 commit comments

Comments
 (0)