Skip to content

Commit d8bb5d9

Browse files
authored
Update KAL and fix new findings (#4461)
* Update KAL and its configuration * Fix kal findings on the API * Fix kal findings on the API - generated files
1 parent 83afaad commit d8bb5d9

File tree

13 files changed

+62
-40
lines changed

13 files changed

+62
-40
lines changed

.custom-gcl.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
version: v2.7.0
1+
version: v2.8.0
22
name: golangci-kube-api-linter
33
destination: ./bin
44
plugins:
55
- module: 'sigs.k8s.io/kube-api-linter'
6-
version: 'v0.0.0-20251201121224-8e86c463aeb8' # Pin to a commit while there's no tag
6+
version: 'v0.0.0-20260123105127-470c3a315f3a' # Pin to a commit while there's no tag

.github/workflows/kal.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
with:
2424
go-version-file: 'go.work'
2525
- name: Install Golang CI Lint
26-
run: go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.7.0
26+
run: go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.8.0
2727
- name: Build KAL
2828
run: golangci-lint custom -v
2929
- name: run api linter

.golangci-kal.yml

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,50 @@ linters:
1111
settings:
1212
linters:
1313
enable:
14-
- "duplicatemarkers" # Ensure there are no exact duplicate markers. for types and fields.
15-
- "jsontags" # Ensure every field has a json tag.
16-
- "nofloats" # Ensure floats are not used.
17-
- "nomaps" # Ensure maps are not used.
14+
- "defaultorrequired" # defaultorrequired analyzer checks that fields marked as required do not have default values applied.
15+
- "defaults" # defaults is a linter to check that fields with default markers are configured correctly.
16+
- "duplicatemarkers" # Ensures there are no exact duplicate markers. for types and fields.
17+
- "jsontags" # Ensures every field has a json tag.
18+
- "nodurations" # Ensures that fields in the API types do not contain `Duration` type ether from the `time` package or the `k8s.io/apimachinery/pkg/apis/meta/v1` package
19+
- "nofloats" # Ensures floats are not used.
20+
- "nomaps" # Ensures maps are not used.
21+
- "nonullable" # Ensures that types and fields do not have the `nullable` marker
1822
- "nophase" # Phase fields are discouraged by the Kube API conventions, use conditions instead.
23+
- "noreferences" # Ensures that field names use 'Ref'/'Refs' instead of 'Reference'/'References'.
24+
- "notimestamp" # Ensures that structs do not contain a TimeStamp field.
1925
- "optionalorrequired" # Every field should be marked as `+optional` or `+required`.
2026
- "ssatags" # Ensure proper Server-Side Apply (SSA) tags on array fields.
2127
- "statussubresource" # All root objects that have a `status` field should have a status subresource.
2228
- "uniquemarkers" # Ensure that types and fields do not contain more than a single definition of a marker that should only be present once.
2329
disable:
30+
# Enforces that an array of struct has at least one required fields. Disabled because BackendRef and others are already using it
31+
# - "arrayofstructs"
32+
# Disabled because it is very verbose...
33+
# - "commentstart"
34+
# Disabled because it changes how conditions are merged and we may need to check impact on existing installations
35+
# - "conditions"
36+
# Enforces usage of int32 or int64. Disabled because GA APIs are already using it
37+
# - "integers"
38+
# Disabled because some GA fields do not have a maxlength and this may break
39+
# - "maxlength"
40+
# Disabled because some GA fields do not have a minlength and this may break.
41+
# Must be revisited with VAP
42+
# - "minlength"
43+
# Ensure no booleans are used - controversial
44+
# - "nobools"
45+
# Ensure that non pointer structs with no required fields are marked as optional. Breaking change
46+
# - "nonpointerstructs"
47+
# Ensure that optional fields are pointers - controversial
48+
# - "optionalfields"
49+
# Ensures that required fields has omitempty tags
50+
# - "requiredfields"
51+
# Ensures that all first-level children fields within a status struct are marked as optional.
52+
# Disabled, breaking change for RouteParentStatus
53+
# - "statusoptional"
2454
- "*"
25-
lintersConfig: {}
55+
lintersConfig:
56+
defaults:
57+
preferredDefaultMarker: "kubebuilder:default"
2658
exclusions:
2759
generated: strict
2860
paths:

apis/v1/backendtlspolicy_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type BackendTLSPolicy struct {
3737

3838
// Spec defines the desired state of BackendTLSPolicy.
3939
// +required
40-
Spec BackendTLSPolicySpec `json:"spec"`
40+
Spec BackendTLSPolicySpec `json:"spec,omitzero"`
4141

4242
// Status defines the current state of BackendTLSPolicy.
4343
// +optional
@@ -120,7 +120,7 @@ type BackendTLSPolicySpec struct {
120120
// +kubebuilder:validation:MaxItems=16
121121
// +kubebuilder:validation:XValidation:message="sectionName must be specified when targetRefs includes 2 or more references to the same target",rule="self.all(p1, self.all(p2, p1.group == p2.group && p1.kind == p2.kind && p1.name == p2.name ? ((!has(p1.sectionName) || p1.sectionName == '') == (!has(p2.sectionName) || p2.sectionName == '')) : true))"
122122
// +kubebuilder:validation:XValidation:message="sectionName must be unique when targetRefs includes 2 or more references to the same target",rule="self.all(p1, self.exists_one(p2, p1.group == p2.group && p1.kind == p2.kind && p1.name == p2.name && (((!has(p1.sectionName) || p1.sectionName == '') && (!has(p2.sectionName) || p2.sectionName == '')) || (has(p1.sectionName) && has(p2.sectionName) && p1.sectionName == p2.sectionName))))"
123-
TargetRefs []LocalPolicyTargetReferenceWithSectionName `json:"targetRefs"`
123+
TargetRefs []LocalPolicyTargetReferenceWithSectionName `json:"targetRefs,omitempty"`
124124

125125
// Validation contains backend TLS validation configuration.
126126
// +required

apis/v1/gateway_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ type Gateway struct {
4545
//
4646
// +kubebuilder:default={conditions: {{type: "Accepted", status: "Unknown", reason:"Pending", message:"Waiting for controller", lastTransitionTime: "1970-01-01T00:00:00Z"},{type: "Programmed", status: "Unknown", reason:"Pending", message:"Waiting for controller", lastTransitionTime: "1970-01-01T00:00:00Z"}}}
4747
// +optional
48-
Status GatewayStatus `json:"status,omitempty"`
48+
Status GatewayStatus `json:"status,omitempty,omitzero"`
4949
}
5050

5151
// +kubebuilder:object:root=true

apis/v1/gatewayclass_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ type GatewayClass struct {
6464
//
6565
// +kubebuilder:default={conditions: {{type: "Accepted", status: "Unknown", message: "Waiting for controller", reason: "Pending", lastTransitionTime: "1970-01-01T00:00:00Z"}}}
6666
// +optional
67-
Status GatewayClassStatus `json:"status,omitempty"`
67+
Status GatewayClassStatus `json:"status,omitempty,omitzero"`
6868
}
6969

7070
const (

apis/v1/object_reference_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ type SecretObjectReference struct {
5454
//
5555
// +optional
5656
// +kubebuilder:default=""
57-
Group *Group `json:"group"`
57+
Group *Group `json:"group,omitempty"`
5858

5959
// Kind is kind of the referent. For example "Secret".
6060
//
6161
// +optional
6262
// +kubebuilder:default=Secret
63-
Kind *Kind `json:"kind"`
63+
Kind *Kind `json:"kind,omitempty"`
6464

6565
// Name is the name of the referent.
6666
// +required

apis/v1alpha2/tcproute_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ type TCPRouteSpec struct {
5555
// +kubebuilder:validation:MinItems=1
5656
// +kubebuilder:validation:MaxItems=16
5757
// <gateway:experimental:validation:XValidation:message="Rule name must be unique within the route",rule="self.all(l1, !has(l1.name) || self.exists_one(l2, has(l2.name) && l1.name == l2.name))">
58-
Rules []TCPRouteRule `json:"rules"`
58+
Rules []TCPRouteRule `json:"rules,omitempty"`
5959
}
6060

6161
// TCPRouteStatus defines the observed state of TCPRoute

apisx/v1alpha1/shared_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ type ParentGatewayReference struct {
4747
//
4848
// +optional
4949
// +kubebuilder:default="gateway.networking.k8s.io"
50-
Group *Group `json:"group"`
50+
Group *Group `json:"group,omitempty"`
5151

5252
// Kind is kind of the referent. For example "Gateway".
5353
//
5454
// +optional
5555
// +kubebuilder:default=Gateway
56-
Kind *Kind `json:"kind"`
56+
Kind *Kind `json:"kind,omitempty"`
5757

5858
// Name is the name of the referent.
5959
// +required

apisx/v1alpha1/xlistenerset_types.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,20 @@ type XListenerSet struct {
6464

6565
// Spec defines the desired state of ListenerSet.
6666
// +required
67-
Spec ListenerSetSpec `json:"spec"`
67+
Spec ListenerSetSpec `json:"spec,omitzero"`
6868

6969
// Status defines the current state of ListenerSet.
7070
//
7171
// +kubebuilder:default={conditions: {{type: "Accepted", status: "Unknown", reason:"Pending", message:"Waiting for controller", lastTransitionTime: "1970-01-01T00:00:00Z"},{type: "Programmed", status: "Unknown", reason:"Pending", message:"Waiting for controller", lastTransitionTime: "1970-01-01T00:00:00Z"}}}
7272
// +optional
73-
Status ListenerSetStatus `json:"status,omitempty"`
73+
Status ListenerSetStatus `json:"status,omitempty,omitzero"`
7474
}
7575

7676
// ListenerSetSpec defines the desired state of a ListenerSet.
7777
type ListenerSetSpec struct {
7878
// ParentRef references the Gateway that the listeners are attached to.
7979
// +required
80-
ParentRef ParentGatewayReference `json:"parentRef"`
80+
ParentRef ParentGatewayReference `json:"parentRef,omitempty"`
8181

8282
// Listeners associated with this ListenerSet. Listeners define
8383
// logical endpoints that are bound on this referenced parent Gateway's addresses.
@@ -117,7 +117,7 @@ type ListenerSetSpec struct {
117117
// +kubebuilder:validation:XValidation:message="Listener name must be unique within the Gateway",rule="self.all(l1, self.exists_one(l2, l1.name == l2.name))"
118118
// +kubebuilder:validation:XValidation:message="Combination of port, protocol and hostname must be unique for each listener",rule="self.all(l1, !has(l1.port) || self.exists_one(l2, has(l2.port) && l1.port == l2.port && l1.protocol == l2.protocol && (has(l1.hostname) && has(l2.hostname) ? l1.hostname == l2.hostname : !has(l1.hostname) && !has(l2.hostname))))"
119119
// +required
120-
Listeners []ListenerEntry `json:"listeners"`
120+
Listeners []ListenerEntry `json:"listeners,omitempty"`
121121
}
122122

123123
type ListenerEntry struct {
@@ -128,7 +128,7 @@ type ListenerEntry struct {
128128
// Routes can attach to a Listener by having a ListenerSet as a parentRef
129129
// and setting the SectionName
130130
// +required
131-
Name SectionName `json:"name"`
131+
Name SectionName `json:"name,omitempty"`
132132

133133
// Hostname specifies the virtual hostname to match for protocol types that
134134
// define this concept. When unspecified, all hostnames are matched. This
@@ -165,11 +165,11 @@ type ListenerEntry struct {
165165
// +kubebuilder:validation:Maximum=65535
166166
//
167167
// +required
168-
Port PortNumber `json:"port"`
168+
Port PortNumber `json:"port,omitempty"`
169169

170170
// Protocol specifies the network protocol this listener expects to receive.
171171
// +required
172-
Protocol ProtocolType `json:"protocol"`
172+
Protocol ProtocolType `json:"protocol,omitempty"`
173173

174174
// TLS is the TLS configuration for the Listener. This field is required if
175175
// the Protocol field is "HTTPS" or "TLS". It is invalid to set this field
@@ -245,7 +245,7 @@ type ListenerSetStatus struct {
245245
type ListenerEntryStatus struct {
246246
// Name is the name of the Listener that this status corresponds to.
247247
// +required
248-
Name SectionName `json:"name"`
248+
Name SectionName `json:"name,omitempty"`
249249

250250
// SupportedKinds is the list indicating the Kinds supported by this
251251
// listener. This MUST represent the kinds supported by an implementation for
@@ -260,7 +260,7 @@ type ListenerEntryStatus struct {
260260
// +required
261261
// +listType=atomic
262262
// +kubebuilder:validation:MaxItems=8
263-
SupportedKinds []RouteGroupKind `json:"supportedKinds"`
263+
SupportedKinds []RouteGroupKind `json:"supportedKinds,omitempty"`
264264

265265
// AttachedRoutes represents the total number of Routes that have been
266266
// successfully attached to this Listener.
@@ -291,7 +291,7 @@ type ListenerEntryStatus struct {
291291
// +listMapKey=type
292292
// +kubebuilder:validation:MaxItems=8
293293
// +required
294-
Conditions []metav1.Condition `json:"conditions"`
294+
Conditions []metav1.Condition `json:"conditions,omitempty"`
295295
}
296296

297297
// ListenerSetConditionType is a type of condition associated with a

0 commit comments

Comments
 (0)