Skip to content

Commit 657b265

Browse files
authored
Lint required optional (#3929)
* Add missing required markers on gateway types * Add missing required markers on grpcroute types * Add missing required markers on httproute types * Add missing required markers on obj_reference types * Add missing required markers on shared types * Add missing required markers on experimental types * Add missing required markers on v1beta1 types * Add missing required markers on v1alpha3 types * Add missing required markers on v1alpha2 types * Enable optionalorrequired linter * Revert objectmeta field doc * Revert minItems changes
1 parent 0f6f9a3 commit 657b265

31 files changed

+180
-14
lines changed

.github/workflows/kal.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ jobs:
1515
fail-fast: false
1616
steps:
1717
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # tag=v4.2.2
18+
name: Checkout code
19+
with:
20+
persist-credentials: false
1821
- name: Set up Go
1922
uses: actions/setup-go@d35c59abb061a4a6fb18e82ac0862c26744d6ab5 # tag=v5.5.0
2023
- name: Install Golang CI Lint

.golangci-kal.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ linters:
1616
- "nofloats" # Ensure floats are not used.
1717
- "nomaps" # Ensure maps are not used.
1818
- "nophase" # Phase fields are discouraged by the Kube API conventions, use conditions instead.
19+
- "optionalorrequired" # Every field should be marked as `+optional` or `+required`.
1920
- "statussubresource" # All root objects that have a `status` field should have a status subresource.
2021
- "uniquemarkers" # Ensure that types and fields do not contain more than a single definition of a marker that should only be present once.
2122
disable:

apis/v1/gateway_types.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,18 @@ import (
3333
// Gateway represents an instance of a service-traffic handling infrastructure
3434
// by binding Listeners to a set of IP addresses.
3535
type Gateway struct {
36-
metav1.TypeMeta `json:",inline"`
36+
metav1.TypeMeta `json:",inline"`
37+
// +optional
3738
metav1.ObjectMeta `json:"metadata,omitempty"`
3839

3940
// Spec defines the desired state of Gateway.
41+
// +required
4042
Spec GatewaySpec `json:"spec"`
4143

4244
// Status defines the current state of Gateway.
4345
//
4446
// +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"}}}
47+
// +optional
4548
Status GatewayStatus `json:"status,omitempty"`
4649
}
4750

@@ -63,6 +66,7 @@ type GatewayList struct {
6366
type GatewaySpec struct {
6467
// GatewayClassName used for this Gateway. This is the name of a
6568
// GatewayClass resource.
69+
// +required
6670
GatewayClassName ObjectName `json:"gatewayClassName"`
6771

6872
// Listeners associated with this Gateway. Listeners define
@@ -236,6 +240,7 @@ type GatewaySpec struct {
236240
// +kubebuilder:validation:XValidation:message="hostname must not be specified for protocols ['TCP', 'UDP']",rule="self.all(l, l.protocol in ['TCP', 'UDP'] ? (!has(l.hostname) || l.hostname == '') : true)"
237241
// +kubebuilder:validation:XValidation:message="Listener name must be unique within the Gateway",rule="self.all(l1, self.exists_one(l2, l1.name == l2.name))"
238242
// +kubebuilder:validation:XValidation:message="Combination of port, protocol and hostname must be unique for each listener",rule="self.all(l1, self.exists_one(l2, l1.port == l2.port && l1.protocol == l2.protocol && (has(l1.hostname) && has(l2.hostname) ? l1.hostname == l2.hostname : !has(l1.hostname) && !has(l2.hostname))))"
243+
// +required
239244
Listeners []Listener `json:"listeners"`
240245

241246
// Addresses requested for this Gateway. This is optional and behavior can
@@ -333,6 +338,7 @@ type Listener struct {
333338
// Gateway.
334339
//
335340
// Support: Core
341+
// +required
336342
Name SectionName `json:"name"`
337343

338344
// Hostname specifies the virtual hostname to match for protocol types that
@@ -390,11 +396,13 @@ type Listener struct {
390396
// same port, subject to the Listener compatibility rules.
391397
//
392398
// Support: Core
399+
// +required
393400
Port PortNumber `json:"port"`
394401

395402
// Protocol specifies the network protocol this listener expects to receive.
396403
//
397404
// Support: Core
405+
// +required
398406
Protocol ProtocolType `json:"protocol"`
399407

400408
// TLS is the TLS configuration for the Listener. This field is required if
@@ -637,6 +645,7 @@ type FrontendTLSValidation struct {
637645
//
638646
// +kubebuilder:validation:MaxItems=8
639647
// +kubebuilder:validation:MinItems=1
648+
// +required
640649
CACertificateRefs []ObjectReference `json:"caCertificateRefs,omitempty"`
641650
}
642651

@@ -721,6 +730,7 @@ type RouteGroupKind struct {
721730
Group *Group `json:"group,omitempty"`
722731

723732
// Kind is the kind of the Route.
733+
// +required
724734
Kind Kind `json:"kind"`
725735
}
726736

@@ -764,6 +774,7 @@ type GatewayStatusAddress struct {
764774
//
765775
// +kubebuilder:validation:MinLength=1
766776
// +kubebuilder:validation:MaxLength=253
777+
// +required
767778
Value string `json:"value"`
768779
}
769780

@@ -873,15 +884,18 @@ type GatewayInfrastructure struct {
873884
// configuration resource within the namespace.
874885
type LocalParametersReference struct {
875886
// Group is the group of the referent.
887+
// +required
876888
Group Group `json:"group"`
877889

878890
// Kind is kind of the referent.
891+
// +required
879892
Kind Kind `json:"kind"`
880893

881894
// Name is the name of the referent.
882895
//
883896
// +kubebuilder:validation:MinLength=1
884897
// +kubebuilder:validation:MaxLength=253
898+
// +required
885899
Name string `json:"name"`
886900
}
887901

@@ -1096,6 +1110,7 @@ const (
10961110
// ListenerStatus is the status associated with a Listener.
10971111
type ListenerStatus struct {
10981112
// Name is the name of the Listener that this status corresponds to.
1113+
// +required
10991114
Name SectionName `json:"name"`
11001115

11011116
// SupportedKinds is the list indicating the Kinds supported by this
@@ -1109,6 +1124,7 @@ type ListenerStatus struct {
11091124
// reference the valid Route kinds that have been specified.
11101125
//
11111126
// +kubebuilder:validation:MaxItems=8
1127+
// +required
11121128
SupportedKinds []RouteGroupKind `json:"supportedKinds"`
11131129

11141130
// AttachedRoutes represents the total number of Routes that have been
@@ -1128,13 +1144,15 @@ type ListenerStatus struct {
11281144
//
11291145
// Uses for this field include troubleshooting Route attachment and
11301146
// measuring blast radius/impact of changes to a Listener.
1147+
// +required
11311148
AttachedRoutes int32 `json:"attachedRoutes"`
11321149

11331150
// Conditions describe the current condition of this listener.
11341151
//
11351152
// +listType=map
11361153
// +listMapKey=type
11371154
// +kubebuilder:validation:MaxItems=8
1155+
// +required
11381156
Conditions []metav1.Condition `json:"conditions"`
11391157
}
11401158

apis/v1/gatewayclass_types.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ import (
4949
//
5050
// GatewayClass is a Cluster level resource.
5151
type GatewayClass struct {
52-
metav1.TypeMeta `json:",inline"`
52+
metav1.TypeMeta `json:",inline"`
53+
// +optional
5354
metav1.ObjectMeta `json:"metadata,omitempty"`
5455

5556
// Spec defines the desired state of GatewayClass.
57+
// +required
5658
Spec GatewayClassSpec `json:"spec"`
5759

5860
// Status defines the current state of GatewayClass.
@@ -61,6 +63,7 @@ type GatewayClass struct {
6163
// specify their controller name.
6264
//
6365
// +kubebuilder:default={conditions: {{type: "Accepted", status: "Unknown", message: "Waiting for controller", reason: "Pending", lastTransitionTime: "1970-01-01T00:00:00Z"}}}
66+
// +optional
6467
Status GatewayClassStatus `json:"status,omitempty"`
6568
}
6669

@@ -83,6 +86,7 @@ type GatewayClassSpec struct {
8386
// Support: Core
8487
//
8588
// +kubebuilder:validation:XValidation:message="Value is immutable",rule="self == oldSelf"
89+
// +required
8690
ControllerName GatewayController `json:"controllerName"`
8791

8892
// ParametersRef is a reference to a resource that contains the configuration
@@ -118,15 +122,18 @@ type GatewayClassSpec struct {
118122
// configuration resource within the cluster.
119123
type ParametersReference struct {
120124
// Group is the group of the referent.
125+
// +required
121126
Group Group `json:"group"`
122127

123128
// Kind is kind of the referent.
129+
// +required
124130
Kind Kind `json:"kind"`
125131

126132
// Name is the name of the referent.
127133
//
128134
// +kubebuilder:validation:MinLength=1
129135
// +kubebuilder:validation:MaxLength=253
136+
// +required
130137
Name string `json:"name"`
131138

132139
// Namespace is the namespace of the referent.
@@ -287,5 +294,6 @@ type GatewayClassList struct {
287294
type FeatureName string
288295

289296
type SupportedFeature struct {
297+
// +required
290298
Name FeatureName `json:"name"`
291299
}

apis/v1/gatewayclass_types_overrides.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ func (s *SupportedFeature) UnmarshalJSON(data []byte) error {
5151
// This is solely for the purpose of ensuring backward compatibility and
5252
// SHOULD NOT be used elsewhere.
5353
type supportedFeatureInternal struct {
54+
// +required
5455
Name FeatureName `json:"name"`
5556
}
5657

apis/v1/grpcroute_types.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,16 @@ import (
5656
// Implementations MAY also accept HTTP/2 connections with an upgrade from
5757
// HTTP/1, i.e. without prior knowledge.
5858
type GRPCRoute struct {
59-
metav1.TypeMeta `json:",inline"`
59+
metav1.TypeMeta `json:",inline"`
60+
// +optional
6061
metav1.ObjectMeta `json:"metadata,omitempty"`
6162

6263
// Spec defines the desired state of GRPCRoute.
6364
// +required
6465
Spec GRPCRouteSpec `json:"spec,omitempty"`
6566

6667
// Status defines the current state of GRPCRoute.
68+
// +optional
6769
Status GRPCRouteStatus `json:"status,omitempty"`
6870
}
6971

@@ -405,12 +407,14 @@ type GRPCHeaderMatch struct {
405407
// entries with an equivalent header name MUST be ignored. Due to the
406408
// case-insensitivity of header names, "foo" and "Foo" are considered
407409
// equivalent.
410+
// +required
408411
Name GRPCHeaderName `json:"name"`
409412

410413
// Value is the value of the gRPC Header to be matched.
411414
//
412415
// +kubebuilder:validation:MinLength=1
413416
// +kubebuilder:validation:MaxLength=4096
417+
// +required
414418
Value string `json:"value"`
415419
}
416420

@@ -521,6 +525,7 @@ type GRPCRouteFilter struct {
521525
// +unionDiscriminator
522526
// +kubebuilder:validation:Enum=ResponseHeaderModifier;RequestHeaderModifier;RequestMirror;ExtensionRef
523527
// <gateway:experimental:validation:Enum=ResponseHeaderModifier;RequestHeaderModifier;RequestMirror;ExtensionRef>
528+
// +required
524529
Type GRPCRouteFilterType `json:"type"`
525530

526531
// RequestHeaderModifier defines a schema for a filter that modifies request

apis/v1/httproute_types.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,16 @@ import (
3333
// used to specify additional processing steps. Backends specify where matching
3434
// requests should be routed.
3535
type HTTPRoute struct {
36-
metav1.TypeMeta `json:",inline"`
36+
metav1.TypeMeta `json:",inline"`
37+
// +optional
3738
metav1.ObjectMeta `json:"metadata,omitempty"`
3839

3940
// Spec defines the desired state of HTTPRoute.
41+
// +required
4042
Spec HTTPRouteSpec `json:"spec"`
4143

4244
// Status defines the current state of HTTPRoute.
45+
// +optional
4346
Status HTTPRouteStatus `json:"status,omitempty"`
4447
}
4548

@@ -608,12 +611,14 @@ type HTTPHeaderMatch struct {
608611
// Generally, proxies should follow the guidance from the RFC:
609612
// https://www.rfc-editor.org/rfc/rfc7230.html#section-3.2.2 regarding
610613
// processing a repeated header, with special handling for "Set-Cookie".
614+
// +required
611615
Name HTTPHeaderName `json:"name"`
612616

613617
// Value is the value of HTTP Header to be matched.
614618
//
615619
// +kubebuilder:validation:MinLength=1
616620
// +kubebuilder:validation:MaxLength=4096
621+
// +required
617622
Value string `json:"value"`
618623
}
619624

@@ -675,12 +680,14 @@ type HTTPQueryParamMatch struct {
675680
//
676681
// Users SHOULD NOT route traffic based on repeated query params to guard
677682
// themselves against potential differences in the implementations.
683+
// +required
678684
Name HTTPHeaderName `json:"name"`
679685

680686
// Value is the value of HTTP query param to be matched.
681687
//
682688
// +kubebuilder:validation:MinLength=1
683689
// +kubebuilder:validation:MaxLength=1024
690+
// +required
684691
Value string `json:"value"`
685692
}
686693

@@ -830,6 +837,7 @@ type HTTPRouteFilter struct {
830837
// +unionDiscriminator
831838
// +kubebuilder:validation:Enum=RequestHeaderModifier;ResponseHeaderModifier;RequestMirror;RequestRedirect;URLRewrite;ExtensionRef
832839
// <gateway:experimental:validation:Enum=RequestHeaderModifier;ResponseHeaderModifier;RequestMirror;RequestRedirect;URLRewrite;ExtensionRef;CORS>
840+
// +required
833841
Type HTTPRouteFilterType `json:"type"`
834842

835843
// RequestHeaderModifier defines a schema for a filter that modifies request
@@ -977,12 +985,14 @@ type HTTPHeader struct {
977985
// with an equivalent header name MUST be ignored. Due to the
978986
// case-insensitivity of header names, "foo" and "Foo" are considered
979987
// equivalent.
988+
// +required
980989
Name HTTPHeaderName `json:"name"`
981990

982991
// Value is the value of HTTP Header to be matched.
983992
//
984993
// +kubebuilder:validation:MinLength=1
985994
// +kubebuilder:validation:MaxLength=4096
995+
// +required
986996
Value string `json:"value"`
987997
}
988998

@@ -1101,6 +1111,7 @@ type HTTPPathModifier struct {
11011111
// Reason of `UnsupportedValue`.
11021112
//
11031113
// +kubebuilder:validation:Enum=ReplaceFullPath;ReplacePrefixMatch
1114+
// +required
11041115
Type HTTPPathModifierType `json:"type"`
11051116

11061117
// ReplaceFullPath specifies the value with which to replace the full path
@@ -1274,6 +1285,7 @@ type HTTPRequestMirrorFilter struct {
12741285
// Support: Extended for Kubernetes Service
12751286
//
12761287
// Support: Implementation-specific for any other resource
1288+
// +required
12771289
BackendRef BackendObjectReference `json:"backendRef"`
12781290

12791291
// Percent represents the percentage of requests that should be
@@ -1356,6 +1368,7 @@ type HTTPCORSFilter struct {
13561368
// Support: Extended
13571369
// +listType=set
13581370
// +kubebuilder:validation:MaxItems=64
1371+
// +optional
13591372
AllowOrigins []AbsoluteURI `json:"allowOrigins,omitempty"`
13601373

13611374
// AllowCredentials indicates whether the actual cross-origin request allows
@@ -1417,6 +1430,7 @@ type HTTPCORSFilter struct {
14171430
// +listType=set
14181431
// +kubebuilder:validation:MaxItems=9
14191432
// +kubebuilder:validation:XValidation:message="AllowMethods cannot contain '*' alongside other methods",rule="!('*' in self && self.size() > 1)"
1433+
// +optional
14201434
AllowMethods []HTTPMethodWithWildcard `json:"allowMethods,omitempty"`
14211435

14221436
// AllowHeaders indicates which HTTP request headers are supported for
@@ -1458,6 +1472,7 @@ type HTTPCORSFilter struct {
14581472
//
14591473
// +listType=set
14601474
// +kubebuilder:validation:MaxItems=64
1475+
// +optional
14611476
AllowHeaders []HTTPHeaderName `json:"allowHeaders,omitempty"`
14621477

14631478
// ExposeHeaders indicates which HTTP response headers can be exposed

0 commit comments

Comments
 (0)