Skip to content

Commit 7cf3797

Browse files
committed
fixup! refactor: Apply KAL fixes
1 parent 1157285 commit 7cf3797

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+504
-213
lines changed

.golangci-kal.yml

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ linters:
2222
- "maxlength" # Ensure all strings and arrays have maximum lengths/maximum items.
2323
- "nobools" # Bools do not evolve over time, should use enums instead.
2424
- "nofloats" # Ensure floats are not used.
25-
- "nomaps" # Ensure maps are not used.
26-
# "nophase" # Ensure phases are not used, as they are not extensible.
25+
# - "nomaps" # Ensure maps are not used.
26+
# - "nophase" # Ensure phases are not used, as they are not extensible.
2727
- "optionalfields" # Ensure that all fields marked as optional adhere to being pointers and
2828
# having the `omitempty` value in their `json` tag where appropriate.
2929
- "optionalorrequired" # Every field should be marked as `+optional` or `+required`.
@@ -40,8 +40,8 @@ linters:
4040
optionalfields:
4141
pointers:
4242
preference: WhenRequired # Always | WhenRequired # Whether to always require pointers, or only when required. Defaults to `Always`.
43-
# jsontags:
44-
# jsonTagRegex: "^[a-z][a-z0-9]*(?:[A-Z][a-z0-9]*)*$" # The default regex is appropriate for our use case.
43+
jsontags:
44+
jsonTagRegex: "^[a-z][a-z0-9-]*(?:[A-Z][a-z0-9]*)*$" # The default regex is appropriate for our use case.
4545
optionalorrequired:
4646
preferredOptionalMarker: kubebuilder:validation:Optional # The preferred optional marker to use, fixes will suggest to use this marker. Defaults to `optional`.
4747
preferredRequiredMarker: kubebuilder:validation:Required # The preferred required marker to use, fixes will suggest to use this marker. Defaults to `required`.
@@ -55,6 +55,33 @@ linters:
5555
- external/
5656
# Ignore test files.
5757
- '.+_test\.go$'
58+
# Ignore aggregate types.
59+
- 'aggregate_types\.go$'
60+
rules:
61+
- path: ".*"
62+
text: "optionalorrequired: embedded field must be marked as kubebuilder:validation:Optional or kubebuilder:validation:Required"
63+
linters:
64+
- kubeapilinter
65+
66+
# kube-api-linter does not handle formats correctly yet.
67+
- path: '/addon_types\.go$'
68+
text: "maxlength: field (Start|End) must have a maximum length, add kubebuilder:validation:MaxLength marker"
69+
linters:
70+
- kubeapilinter
71+
- path: '/common_types\.go$'
72+
text: "maxlength: field Address must have a maximum length, add kubebuilder:validation:MaxLength marker"
73+
linters:
74+
- kubeapilinter
75+
76+
# kube-api-linter does not handle patterns correctly yet.
77+
- path: '/aws_(clusterconfig|node)_types\.go$'
78+
text: "maxlength: field (ID|IAMInstanceProfile|InstanceType|Org) must have a maximum length, add kubebuilder:validation:MaxLength marker"
79+
linters:
80+
- kubeapilinter
81+
- path: '/(nutanix_)?(clusterconfig)_types\.go$'
82+
text: "maxlength: field (URL|Tag) must have a maximum length, add kubebuilder:validation:MaxLength marker"
83+
linters:
84+
- kubeapilinter
5885

5986
issues:
6087
max-same-issues: 0

api/v1alpha1/addon_types.go

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,9 @@ type CNI struct {
118118

119119
// Addon strategy used to deploy the CNI provider to the workload cluster.
120120
// +kubebuilder:default=HelmAddon
121+
// +kubebuilder:validation:Optional
121122
// +kubebuilder:validation:Enum=ClusterResourceSet;HelmAddon
122-
Strategy *AddonStrategy `json:"strategy,omitempty"`
123+
Strategy AddonStrategy `json:"strategy,omitempty"`
123124

124125
// AddonConfig contains the configuration for the CNI provider.
125126
// +kubebuilder:validation:Optional
@@ -153,24 +154,27 @@ type ValuesReference struct {
153154
// Name is the name of resource being referenced.
154155
// +kubebuilder:validation:Required
155156
// +kubebuilder:validation:MinLength=1
157+
// +kubebuilder:validation:MaxLength=253
156158
Name string `json:"name"`
157159
}
158160

159161
// NFD tells us to enable or disable the node feature discovery addon.
160162
type NFD struct {
161163
// Addon strategy used to deploy Node Feature Discovery (NFD) to the workload cluster.
162164
// +kubebuilder:default=HelmAddon
165+
// +kubebuilder:validation:Optional
163166
// +kubebuilder:validation:Enum=ClusterResourceSet;HelmAddon
164-
Strategy *AddonStrategy `json:"strategy,omitempty"`
167+
Strategy AddonStrategy `json:"strategy,omitempty"`
165168
}
166169

167170
// ClusterAutoscaler tells us to enable or disable the cluster-autoscaler addon.
168171
type ClusterAutoscaler struct {
169172
// Addon strategy used to deploy cluster-autoscaler to the management cluster
170173
// targeting the workload cluster.
171174
// +kubebuilder:default=HelmAddon
175+
// +kubebuilder:validation:Optional
172176
// +kubebuilder:validation:Enum=ClusterResourceSet;HelmAddon
173-
Strategy *AddonStrategy `json:"strategy,omitempty"`
177+
Strategy AddonStrategy `json:"strategy,omitempty"`
174178
}
175179

176180
type GenericCSI struct {
@@ -185,15 +189,17 @@ type GenericCSI struct {
185189
type GenericCOSI struct {
186190
// Addon strategy used to deploy the COSI controller to the workload cluster.
187191
// +kubebuilder:default=HelmAddon
192+
// +kubebuilder:validation:Optional
188193
// +kubebuilder:validation:Enum=HelmAddon
189-
Strategy *AddonStrategy `json:"strategy,omitempty"`
194+
Strategy AddonStrategy `json:"strategy,omitempty"`
190195
}
191196

192197
type SnapshotController struct {
193198
// Addon strategy used to deploy the snapshot controller to the workload cluster.
194199
// +kubebuilder:default=HelmAddon
200+
// +kubebuilder:validation:Optional
195201
// +kubebuilder:validation:Enum=ClusterResourceSet;HelmAddon
196-
Strategy *AddonStrategy `json:"strategy,omitempty"`
202+
Strategy AddonStrategy `json:"strategy,omitempty"`
197203
}
198204

199205
type DefaultStorage struct {
@@ -205,6 +211,7 @@ type DefaultStorage struct {
205211
// Name of the default storage class config the specified default provider.
206212
// +kubebuilder:validation:Required
207213
// +kubebuilder:validation:MinLength=1
214+
// +kubebuilder:validation:MaxLength=242
208215
StorageClassConfig string `json:"storageClassConfig"`
209216
}
210217

@@ -251,8 +258,9 @@ type CSIProvider struct {
251258

252259
// Addon strategy used to deploy the CSI provider to the workload cluster.
253260
// +kubebuilder:default=HelmAddon
261+
// +kubebuilder:validation:Optional
254262
// +kubebuilder:validation:Enum=ClusterResourceSet;HelmAddon
255-
Strategy *AddonStrategy `json:"strategy,omitempty"`
263+
Strategy AddonStrategy `json:"strategy,omitempty"`
256264

257265
// The reference to any secret used by the CSI Provider.
258266
// +kubebuilder:validation:Optional
@@ -276,8 +284,7 @@ type StorageClassConfig struct {
276284

277285
// If the storage class should allow volume expanding
278286
// +kubebuilder:validation:Optional
279-
// +kubebuilder:default=false
280-
AllowExpansion bool `json:"allowExpansion,omitempty"`
287+
AllowExpansion bool `json:"allowExpansion,omitempty"` //nolint:kubeapilinter,lll // Leave as bool for backward compatibility and this comment makes it a long line.
281288
}
282289

283290
type CSICredentials struct {
@@ -302,8 +309,9 @@ type CCM struct {
302309

303310
// Addon strategy used to deploy the CCM to the workload cluster.
304311
// +kubebuilder:default=HelmAddon
312+
// +kubebuilder:validation:Optional
305313
// +kubebuilder:validation:Enum=ClusterResourceSet;HelmAddon
306-
Strategy *AddonStrategy `json:"strategy,omitempty"`
314+
Strategy AddonStrategy `json:"strategy,omitempty"`
307315
}
308316

309317
type CCMCredentials struct {
@@ -329,21 +337,25 @@ type ServiceLoadBalancerConfiguration struct {
329337
// provider uses to choose an address for a load balancer.
330338
// +kubebuilder:validation:Required
331339
// +kubebuilder:validation:MinItems=1
340+
// +kubebuilder:validation:MaxItems=10
332341
AddressRanges []AddressRange `json:"addressRanges"`
333342
}
334343

335344
// AddressRange defines an IPv4 range.
336345
type AddressRange struct {
337346
// +kubebuilder:validation:Format=ipv4
347+
// +kubebuilder:validation:Required
338348
Start string `json:"start"`
339349

340350
// +kubebuilder:validation:Format=ipv4
351+
// +kubebuilder:validation:Required
341352
End string `json:"end"`
342353
}
343354

344355
type RegistryAddon struct {
345356
// The OCI registry provider to deploy.
346357
// +kubebuilder:default="CNCF Distribution"
358+
// +kubebuilder:validation:Required
347359
// +kubebuilder:validation:Enum="CNCF Distribution"
348360
Provider string `json:"provider"`
349361
}

api/v1alpha1/aws_clusterconfig_types.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ type AWSSpec struct {
2020
ControlPlaneLoadBalancer *AWSLoadBalancerSpec `json:"controlPlaneLoadBalancer,omitempty"`
2121
}
2222

23+
// +kubebuilder:validation:MinLength=4
24+
// +kubebuilder:validation:MaxLength=16
2325
type Region string
2426

2527
type AWSNetwork struct {
@@ -34,17 +36,18 @@ type AWSNetwork struct {
3436
type VPC struct {
3537
// Existing VPC ID to use for the cluster.
3638
// +kubebuilder:validation:Required
37-
// +kubebuilder:validation:MinLength=1
39+
// +kubebuilder:validation:Format=`^vpc-[0-9a-f]{8}(?:[0-9a-f]{9})?$`
3840
ID string `json:"id"`
3941
}
4042

43+
// +kubebuilder:validation:MaxItems=10
4144
type Subnets []SubnetSpec
4245

4346
// SubnetSpec configures an AWS Subnet.
4447
type SubnetSpec struct {
4548
// Existing Subnet ID to use for the cluster.
4649
// +kubebuilder:validation:Required
47-
// +kubebuilder:validation:MinLength=1
50+
// +kubebuilder:validation:Format=`^subnet-[0-9a-f]{8}(?:[0-9a-f]{9})?$`
4851
ID string `json:"id"`
4952
}
5053

api/v1alpha1/aws_node_types.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ type AWSControlPlaneNodeSpec struct {
77
// The IAM instance profile to use for the cluster Machines.
88
// +kubebuilder:validation:Optional
99
// +kubebuilder:default=control-plane.cluster-api-provider-aws.sigs.k8s.io
10+
// +kubebuilder:validation:MinLength=1
11+
// +kubebuilder:validation:MaxLength=128
1012
IAMInstanceProfile string `json:"iamInstanceProfile,omitempty"`
1113

1214
// +kubebuilder:validation:Optional
1315
// +kubebuilder:default=m5.xlarge
16+
// +kubebuilder:validation:MinLength=1
17+
// +kubebuilder:validation:MaxLength=32
1418
InstanceType string `json:"instanceType,omitempty"`
1519

1620
AWSGenericNodeSpec `json:",inline"`
@@ -20,11 +24,15 @@ type AWSWorkerNodeSpec struct {
2024
// The IAM instance profile to use for the cluster Machines.
2125
// +kubebuilder:validation:Optional
2226
// +kubebuilder:default=nodes.cluster-api-provider-aws.sigs.k8s.io
27+
// +kubebuilder:validation:MinLength=1
28+
// +kubebuilder:validation:MaxLength=128
2329
IAMInstanceProfile string `json:"iamInstanceProfile,omitempty"`
2430

2531
// The AWS instance type to use for the cluster Machines.
2632
// +kubebuilder:validation:Optional
2733
// +kubebuilder:default=m5.2xlarge
34+
// +kubebuilder:validation:MinLength=1
35+
// +kubebuilder:validation:MaxLength=32
2836
InstanceType string `json:"instanceType,omitempty"`
2937

3038
AWSGenericNodeSpec `json:",inline"`
@@ -40,17 +48,22 @@ type AWSGenericNodeSpec struct {
4048
AdditionalSecurityGroups AdditionalSecurityGroup `json:"additionalSecurityGroups,omitempty"`
4149
}
4250

51+
// +kubebuilder:validation:MaxItems=32
4352
type AdditionalSecurityGroup []SecurityGroup
4453

4554
type SecurityGroup struct {
4655
// ID is the id of the security group
4756
// +kubebuilder:validation:Optional
57+
// +kubebuilder:validation:Format=`^sg-[0-9a-f]{8}(?:[0-9a-f]{9})?$`
58+
// +kubebuilder:validation:MinLength=1
4859
ID string `json:"id,omitempty"`
4960
}
5061

5162
type AMISpec struct {
5263
// AMI ID is the reference to the AMI from which to create the machine instance.
5364
// +kubebuilder:validation:Optional
65+
// +kubebuilder:validation:Format=`^ami-[0-9a-f]{8}(?:[0-9a-f]{9})?$`
66+
// +kubebuilder:validation:MinLength=1
5467
ID string `json:"id,omitempty"`
5568

5669
// Lookup is the lookup arguments for the AMI.
@@ -63,13 +76,20 @@ type AMILookup struct {
6376
// base OS and kubernetes version.
6477
// +kubebuilder:validation:Optional
6578
// +kubebuilder:example=`capa-ami-{{.BaseOS}}-?{{.K8sVersion}}-*`
79+
// +kubebuilder:validation:MinLength=1
80+
// +kubebuilder:validation:MaxLength=128
6681
Format string `json:"format,omitempty"`
6782

6883
// The AWS Organization ID to use for image lookup.
6984
// +kubebuilder:validation:Optional
85+
// +kubebuilder:validation:Format=`^o-[0-9a-z]{10,32}$`
86+
// +kubebuilder:validation:MinLength=12
87+
// +kubebuilder:validation:MaxLength=34
7088
Org string `json:"org,omitempty"`
7189

7290
// The name of the base os for image lookup
7391
// +kubebuilder:validation:Optional
92+
// +kubebuilder:validation:MinLength=1
93+
// +kubebuilder:validation:MaxLength=32
7494
BaseOS string `json:"baseOS,omitempty"`
7595
}

0 commit comments

Comments
 (0)