Skip to content

Commit 2bbfc63

Browse files
committed
enable the requiredfields linter and make spec fields required
1 parent 39efc02 commit 2bbfc63

36 files changed

+290
-99
lines changed

.golangci-kal.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ linters:
2222
- "integers"
2323
# jsontags linter will force the json fields to go from _ usage to camelCase, we will wait for v1beta1 to enable this
2424
- "jsontags"
25-
- "requiredfields"
2625
- "optionalfields"
2726
lintersConfig: { }
2827
exclusions:

api/v1alpha2/addressset_types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
)
2222

2323
// AddressSetSpec defines the desired state of AddressSet
24+
// +kubebuilder:validation:MinProperties=1
2425
type AddressSetSpec struct {
2526
// ipv4 defines a list of IPv4 address strings
2627
// +optional
@@ -46,8 +47,8 @@ type AddressSet struct {
4647
// +optional
4748
metav1.ObjectMeta `json:"metadata,omitempty"`
4849
// spec is the desired state of the AddressSet
49-
// +optional
50-
Spec AddressSetSpec `json:"spec,omitempty"`
50+
// +required
51+
Spec AddressSetSpec `json:"spec,omitzero,omitempty"`
5152
// status is the observed state of the AddressSet
5253
// +optional
5354
Status AddressSetStatus `json:"status,omitempty"`

api/v1alpha2/firewallrule_types.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,14 @@ import (
2525
// FirewallRuleSpec defines the desired state of FirewallRule.
2626
type FirewallRuleSpec struct {
2727
// action is the action to take when the rule matches.
28+
// +kubebuilder:validation:Enum=ACCEPT;DROP
2829
// +required
29-
Action string `json:"action"`
30+
Action string `json:"action,omitempty"`
3031

3132
// label is the label of the rule.
33+
// +kubebuilder:validation:MinLength=3
3234
// +required
33-
Label string `json:"label"`
35+
Label string `json:"label,omitempty"`
3436

3537
// description is the description of the rule.
3638
// +optional
@@ -43,7 +45,7 @@ type FirewallRuleSpec struct {
4345
// protocol is the protocol to apply the rule to.
4446
// +kubebuilder:validation:Enum=TCP;UDP;ICMP;IPENCAP
4547
// +required
46-
Protocol linodego.NetworkProtocol `json:"protocol"`
48+
Protocol linodego.NetworkProtocol `json:"protocol,omitempty"`
4749

4850
// addresses is a list of addresses to apply the rule to.
4951
// +optional
@@ -89,8 +91,8 @@ type FirewallRule struct {
8991
metav1.ObjectMeta `json:"metadata,omitempty"`
9092

9193
// spec is the desired state of the FirewallRule.
92-
// +optional
93-
Spec FirewallRuleSpec `json:"spec,omitempty"`
94+
// +required
95+
Spec FirewallRuleSpec `json:"spec,omitzero,omitempty"`
9496

9597
// status is the observed state of the FirewallRule.
9698
// +optional

api/v1alpha2/linodecluster_types.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ const (
3232
// LinodeClusterSpec defines the desired state of LinodeCluster
3333
type LinodeClusterSpec struct {
3434
// region the LinodeCluster lives in.
35+
// +kubebuilder:validation:MinLength=1
3536
// +required
36-
Region string `json:"region"`
37+
Region string `json:"region,omitempty"`
3738

3839
// controlPlaneEndpoint represents the endpoint used to communicate with the LinodeCluster control plane
3940
// If ControlPlaneEndpoint is unset then the Nodebalancer ip will be used.
@@ -114,8 +115,8 @@ type LinodeCluster struct {
114115
metav1.ObjectMeta `json:"metadata,omitempty"`
115116

116117
// spec is the desired state of the LinodeCluster.
117-
// +optional
118-
Spec LinodeClusterSpec `json:"spec,omitempty"`
118+
// +required
119+
Spec LinodeClusterSpec `json:"spec,omitzero,omitempty"`
119120

120121
// status is the observed state of the LinodeCluster.
121122
// +optional
@@ -247,7 +248,7 @@ type LinodeNBPortConfig struct {
247248
// +kubebuilder:validation:Minimum=1
248249
// +kubebuilder:validation:Maximum=65535
249250
// +required
250-
Port int `json:"port"`
251+
Port int `json:"port,omitempty"`
251252

252253
// nodeBalancerConfigID is the config ID of port's NodeBalancer config.
253254
// +optional

api/v1alpha2/linodeclustertemplate_types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ import (
2424
type LinodeClusterTemplateSpec struct {
2525
// template defines the specification for a LinodeCluster.
2626
// +required
27-
Template LinodeClusterTemplateResource `json:"template"`
27+
Template LinodeClusterTemplateResource `json:"template,omitzero"`
2828
}
2929

3030
// LinodeClusterTemplateResource describes the data needed to create a LinodeCluster from a template.
3131
type LinodeClusterTemplateResource struct {
3232
// spec is the specification of the LinodeCluster.
3333
// +required
34-
Spec LinodeClusterSpec `json:"spec"`
34+
Spec LinodeClusterSpec `json:"spec,omitzero,omitempty"`
3535
}
3636

3737
// +kubebuilder:object:root=true
@@ -47,7 +47,7 @@ type LinodeClusterTemplate struct {
4747

4848
// spec is the desired state of the LinodeClusterTemplate.
4949
// +optional
50-
Spec LinodeClusterTemplateSpec `json:"spec,omitempty"`
50+
Spec LinodeClusterTemplateSpec `json:"spec,omitzero,omitempty"`
5151
}
5252

5353
// +kubebuilder:object:root=true

api/v1alpha2/linodefirewall_types.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const (
2828
)
2929

3030
// LinodeFirewallSpec defines the desired state of LinodeFirewall
31+
// +kubebuilder:validation:MinProperties=1
3132
type LinodeFirewallSpec struct {
3233
// firewallID is the ID of the Firewall.
3334
// +optional
@@ -147,8 +148,8 @@ type LinodeFirewall struct {
147148
metav1.ObjectMeta `json:"metadata,omitempty"`
148149

149150
// spec is the desired state of the LinodeFirewall.
150-
// +optional
151-
Spec LinodeFirewallSpec `json:"spec,omitempty"`
151+
// +required
152+
Spec LinodeFirewallSpec `json:"spec,omitzero,omitempty"`
152153

153154
// status is the observed state of the LinodeFirewall.
154155
// +optional

api/v1alpha2/linodemachine_types.go

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,16 @@ type LinodeMachineSpec struct {
4242
InstanceID *int `json:"instanceID,omitempty"`
4343

4444
// region is the Linode region to create the instance in.
45+
// +kubebuilder:validation:MinLength=1
4546
// +required
4647
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
47-
Region string `json:"region"`
48+
Region string `json:"region,omitempty"`
4849

4950
// type is the Linode instance type to create.
51+
// +kubebuilder:validation:MinLength=1
5052
// +required
5153
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
52-
Type string `json:"type"`
54+
Type string `json:"type,omitempty"`
5355

5456
// group is the Linode group to create the instance in.
5557
// +optional
@@ -364,8 +366,9 @@ type PublicInterfaceIPv4CreateOptions struct {
364366
// PublicInterfaceIPv4AddressCreateOptions defines the public IPv4 address and whether it is primary
365367
type PublicInterfaceIPv4AddressCreateOptions struct {
366368
// address is the IPv4 address for the public interface.
369+
// +kubebuilder:validation:MinLength=1
367370
// +required
368-
Address string `json:"address"`
371+
Address string `json:"address,omitempty"`
369372

370373
// primary is a boolean indicating whether the address is primary.
371374
// +optional
@@ -384,15 +387,17 @@ type PublicInterfaceIPv6CreateOptions struct {
384387
// PublicInterfaceIPv6RangeCreateOptions defines the IPv6 range for a public interface
385388
type PublicInterfaceIPv6RangeCreateOptions struct {
386389
// range is the IPv6 range for the public interface.
390+
// +kubebuilder:validation:MinLength=1
387391
// +required
388-
Range string `json:"range"`
392+
Range string `json:"range,omitempty"`
389393
}
390394

391395
// VPCInterfaceCreateOptions defines the VPC interface configuration for an instance
392396
type VPCInterfaceCreateOptions struct {
393397
// subnet_id is the ID of the subnet to use for the interface.
398+
// +kubebuilder:validation:Minimum=1
394399
// +required
395-
SubnetID int `json:"subnet_id"`
400+
SubnetID int `json:"subnet_id,omitempty"`
396401

397402
// ipv4 is the IPv4 configuration for the interface.
398403
// +optional
@@ -419,21 +424,23 @@ type VPCInterfaceIPv6CreateOptions struct {
419424

420425
// is_public is a boolean indicating whether the interface is public.
421426
// +required
422-
IsPublic bool `json:"is_public"`
427+
IsPublic *bool `json:"is_public,omitempty"`
423428
}
424429

425430
// VPCInterfaceIPv6SLAACCreateOptions defines the Range for IPv6 SLAAC
426431
type VPCInterfaceIPv6SLAACCreateOptions struct {
427432
// range is the IPv6 range for the interface.
433+
// +kubebuilder:validation:MinLength=1
428434
// +required
429-
Range string `json:"range"`
435+
Range string `json:"range,omitempty"`
430436
}
431437

432438
// VPCInterfaceIPv6RangeCreateOptions defines the IPv6 range for a VPC interface
433439
type VPCInterfaceIPv6RangeCreateOptions struct {
434440
// range is the IPv6 range for the interface.
441+
// +kubebuilder:validation:MinLength=1
435442
// +required
436-
Range string `json:"range"`
443+
Range string `json:"range,omitempty"`
437444
}
438445

439446
// VPCInterfaceIPv4CreateOptions defines the IPv4 address and range configuration for a VPC interface
@@ -454,8 +461,9 @@ type VPCInterfaceIPv4CreateOptions struct {
454461
// VPCInterfaceIPv4AddressCreateOptions defines the IPv4 configuration for a VPC interface
455462
type VPCInterfaceIPv4AddressCreateOptions struct {
456463
// address is the IPv4 address for the interface.
464+
// +kubebuilder:validation:MinLength=1
457465
// +required
458-
Address string `json:"address"`
466+
Address string `json:"address,omitempty"`
459467

460468
// primary is a boolean indicating whether the address is primary.
461469
// +optional
@@ -469,15 +477,17 @@ type VPCInterfaceIPv4AddressCreateOptions struct {
469477
// VPCInterfaceIPv4RangeCreateOptions defines the IPv4 range for a VPC interface
470478
type VPCInterfaceIPv4RangeCreateOptions struct {
471479
// range is the IPv4 range for the interface.
480+
// +kubebuilder:validation:MinLength=1
472481
// +required
473-
Range string `json:"range"`
482+
Range string `json:"range,omitempty"`
474483
}
475484

476485
// VLANInterface defines the VLAN interface configuration for an instance
477486
type VLANInterface struct {
478487
// vlan_label is the label of the VLAN.
488+
// +kubebuilder:validation:MinLength=1
479489
// +required
480-
VLANLabel string `json:"vlan_label"`
490+
VLANLabel string `json:"vlan_label,omitempty"`
481491

482492
// ipam_address is the IP address to assign to the interface.
483493
// +optional
@@ -589,8 +599,8 @@ type LinodeMachine struct {
589599
metav1.ObjectMeta `json:"metadata,omitempty"`
590600

591601
// spec defines the specification of desired behavior for the LinodeMachine.
592-
// +optional
593-
Spec LinodeMachineSpec `json:"spec,omitempty"`
602+
// +required
603+
Spec LinodeMachineSpec `json:"spec,omitzero,omitempty"`
594604

595605
// status defines the observed state of LinodeMachine.
596606
// +optional

api/v1alpha2/linodemachinetemplate_types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
type LinodeMachineTemplateSpec struct {
2525
// template defines the specification for a LinodeMachine.
2626
// +required
27-
Template LinodeMachineTemplateResource `json:"template"`
27+
Template LinodeMachineTemplateResource `json:"template,omitempty,omitzero"`
2828
}
2929

3030
// LinodeMachineTemplateStatus defines the observed state of LinodeMachineTemplate
@@ -52,7 +52,7 @@ type LinodeMachineTemplateStatus struct {
5252
type LinodeMachineTemplateResource struct {
5353
// spec is the specification of the desired behavior of the machine.
5454
// +required
55-
Spec LinodeMachineSpec `json:"spec"`
55+
Spec LinodeMachineSpec `json:"spec,omitempty,omitzero"`
5656
}
5757

5858
// +kubebuilder:object:root=true
@@ -70,7 +70,7 @@ type LinodeMachineTemplate struct {
7070

7171
// spec is the desired state of the LinodeMachineTemplate.
7272
// +optional
73-
Spec LinodeMachineTemplateSpec `json:"spec,omitempty"`
73+
Spec LinodeMachineTemplateSpec `json:"spec,omitzero,omitempty"`
7474

7575
// status is the observed state of the LinodeMachineTemplate.
7676
// +optional

api/v1alpha2/linodeobjectstoragebucket_types.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ type LinodeObjectStorageBucketSpec struct {
3838

3939
// region is the ID of the Object Storage region for the bucket.
4040
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
41+
// +kubebuilder:validation:MinLength=1
4142
// +required
42-
Region string `json:"region"`
43+
Region string `json:"region,omitempty"`
4344

4445
// acl sets the Access Control Level of the bucket using a canned ACL string
4546
// +optional
@@ -114,8 +115,8 @@ type LinodeObjectStorageBucket struct {
114115
metav1.ObjectMeta `json:"metadata,omitempty"`
115116

116117
// spec is the desired state of the LinodeObjectStorageBucket.
117-
// +optional
118-
Spec LinodeObjectStorageBucketSpec `json:"spec,omitempty"`
118+
// +required
119+
Spec LinodeObjectStorageBucketSpec `json:"spec,omitzero,omitempty"`
119120

120121
// status is the observed state of the LinodeObjectStorageBucket.
121122
// +optional

api/v1alpha2/linodeobjectstoragekey_types.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,20 @@ const (
2929

3030
type BucketAccessRef struct {
3131
// bucketName is the name of the bucket to grant access to.
32+
// +kubebuilder:validation:MinLength=3
33+
// +kubebuilder:validation:MaxLength=63
3234
// +required
33-
BucketName string `json:"bucketName"`
35+
BucketName string `json:"bucketName,omitempty"`
3436

3537
// permissions is the permissions to grant to the bucket.
38+
// +kubebuilder:validation:Enum=read_only;read_write
3639
// +required
37-
Permissions string `json:"permissions"`
40+
Permissions string `json:"permissions,omitempty"`
3841

3942
// region is the region of the bucket.
43+
// +kubebuilder:validation:MinLength=1
4044
// +required
41-
Region string `json:"region"`
45+
Region string `json:"region,omitempty"`
4246
}
4347

4448
type GeneratedSecret struct {
@@ -69,17 +73,17 @@ type LinodeObjectStorageKeySpec struct {
6973
// +kubebuilder:validation:MinItems=1
7074
// +required
7175
// +listType=atomic
72-
BucketAccess []BucketAccessRef `json:"bucketAccess"`
76+
BucketAccess []BucketAccessRef `json:"bucketAccess,omitempty"`
7377

7478
// credentialsRef is a reference to a Secret that contains the credentials to use for generating access keys.
75-
// If not supplied then the credentials of the controller will be used.
79+
// If not supplied, then the credentials of the controller will be used.
7680
// +optional
7781
CredentialsRef *corev1.SecretReference `json:"credentialsRef,omitempty"`
7882

7983
// keyGeneration may be modified to trigger a rotation of the access key.
8084
// +kubebuilder:default=0
81-
// +required
82-
KeyGeneration int `json:"keyGeneration"`
85+
// +optional
86+
KeyGeneration *int `json:"keyGeneration,omitempty"`
8387

8488
// generatedSecret configures the Secret to generate containing access key details.
8589
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value is immutable"
@@ -151,8 +155,8 @@ type LinodeObjectStorageKey struct {
151155
metav1.ObjectMeta `json:"metadata,omitempty"`
152156

153157
// spec is the desired state of the LinodeObjectStorageKey.
154-
// +optional
155-
Spec LinodeObjectStorageKeySpec `json:"spec,omitempty"`
158+
// +required
159+
Spec LinodeObjectStorageKeySpec `json:"spec,omitzero,omitempty"`
156160

157161
// status is the observed state of the LinodeObjectStorageKey.
158162
// +optional

0 commit comments

Comments
 (0)