Skip to content

Commit a9e6c9e

Browse files
authored
Merge pull request #3221 from Nordix/lentzi90/kal-requiredfields
🌱 Enable requiredfields linter
2 parents 834083f + 41c933d commit a9e6c9e

19 files changed

Lines changed: 217 additions & 655 deletions

.golangci-kal.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ linters:
3131
# - "optionalfields" # Ensure that all fields marked as optional adhere to being pointers and
3232
# having the omitempty value in their json tag where appropriate.
3333
- "optionalorrequired" # Every field should be marked as optional or required.
34-
# - "requiredfields" # Required fields should not be pointers, and should not have omitempty.
34+
- "requiredfields" # Required fields should have omitempty/omitzero, and should only be pointers when the zero value is valid.
3535
# - "ssatags" # Ensure array fields have the appropriate listType markers.
3636
- "statusoptional" # Ensure all first children within status should be optional.
3737
- "statussubresource" # All root objects that have a status field should have a status subresource.

api/v1beta2/identity_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ type OpenStackIdentityReference struct {
3232
// The Secret may optionally contain a key named `cacert` containing a PEM-encoded CA certificate.
3333
// +required
3434
// +kubebuilder:validation:MinLength=1
35-
Name string `json:"name"`
35+
Name string `json:"name,omitempty"`
3636

3737
// cloudName specifies the name of the entry in the clouds.yaml file to use.
3838
// +required
3939
// +kubebuilder:validation:MinLength=1
40-
CloudName string `json:"cloudName"`
40+
CloudName string `json:"cloudName,omitempty"`
4141

4242
// region specifies an OpenStack region to use. If specified, it overrides
4343
// any value in clouds.yaml. If specified for an OpenStackMachine, its

api/v1beta2/openstackcluster_types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ type OpenStackClusterSpec struct {
156156
// to be used when reconciling this cluster. It is also to reconcile
157157
// machines unless overridden in the machine spec.
158158
// +required
159-
IdentityRef OpenStackIdentityReference `json:"identityRef"`
159+
IdentityRef OpenStackIdentityReference `json:"identityRef,omitzero"`
160160
}
161161

162162
type APIServer struct {
@@ -348,8 +348,8 @@ type ManagedSecurityGroups struct {
348348

349349
// allowAllInClusterTraffic allows all ingress and egress traffic between cluster nodes when set to true.
350350
// +kubebuilder:default=false
351-
// +required
352-
AllowAllInClusterTraffic bool `json:"allowAllInClusterTraffic"`
351+
// +optional
352+
AllowAllInClusterTraffic bool `json:"allowAllInClusterTraffic,omitempty"`
353353
}
354354

355355
var _ IdentityRefProvider = &OpenStackCluster{}

api/v1beta2/openstackclustertemplate_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ import (
2424
type OpenStackClusterTemplateResource struct {
2525
// spec is the desired state of the OpenStackCluster.
2626
// +required
27-
Spec OpenStackClusterSpec `json:"spec"`
27+
Spec OpenStackClusterSpec `json:"spec,omitzero"`
2828
}
2929

3030
// OpenStackClusterTemplateSpec defines the desired state of OpenStackClusterTemplate.
3131
type OpenStackClusterTemplateSpec struct {
3232
// template is the OpenStackClusterTemplate resource data.
3333
// +required
34-
Template OpenStackClusterTemplateResource `json:"template"`
34+
Template OpenStackClusterTemplateResource `json:"template,omitzero"`
3535
}
3636

3737
// +genclient

api/v1beta2/openstackmachine_types.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type SchedulerHintAdditionalValue struct {
5353
// Valid values are Bool, String, and Number.
5454
// +required
5555
// +unionDiscriminator
56-
Type SchedulerHintValueType `json:"type"`
56+
Type SchedulerHintValueType `json:"type,omitempty"`
5757

5858
// bool is the boolean value of the scheduler hint, used when Type is "Bool".
5959
// This field is required if type is 'Bool', and must not be set otherwise.
@@ -83,12 +83,12 @@ type SchedulerHintAdditionalProperty struct {
8383
// It is a unique identifier for the property.
8484
// +kubebuilder:validation:MinLength:=1
8585
// +required
86-
Name string `json:"name"`
86+
Name string `json:"name,omitempty"`
8787

8888
// value is the value of the scheduler hint property, which can be of various types
8989
// (e.g., bool, string, int). The type is indicated by the Value.Type field.
9090
// +required
91-
Value SchedulerHintAdditionalValue `json:"value"`
91+
Value SchedulerHintAdditionalValue `json:"value,omitzero"`
9292
}
9393

9494
// OpenStackMachineSpec defines the desired state of OpenStackMachine.
@@ -99,12 +99,12 @@ type OpenStackMachineSpec struct {
9999

100100
// flavor is the flavor to use for this machine.
101101
// +required
102-
Flavor FlavorParam `json:"flavor"`
102+
Flavor FlavorParam `json:"flavor,omitzero"`
103103

104104
// image is the image to use for the server instance.
105105
// If the rootVolume is specified, this will be used when creating the root volume.
106106
// +required
107-
Image ImageParam `json:"image"`
107+
Image ImageParam `json:"image,omitzero"`
108108

109109
// sshKeyName is the name of the SSH key to inject in the instance.
110110
// +optional
@@ -179,13 +179,15 @@ type OpenStackMachineSpec struct {
179179
type ServerMetadata struct {
180180
// key is the server metadata key
181181
// +kubebuilder:validation:MaxLength:=255
182+
// +kubebuilder:validation:MinLength=1
182183
// +required
183-
Key string `json:"key"`
184+
Key string `json:"key,omitempty"`
184185

185186
// value is the server metadata value
186187
// +kubebuilder:validation:MaxLength:=255
188+
// +kubebuilder:validation:MinLength=1
187189
// +required
188-
Value string `json:"value"`
190+
Value string `json:"value,omitempty"`
189191
}
190192

191193
// MachineInitialization contains information about the initialization status of the machine.

api/v1beta2/openstackmachinetemplate_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
type OpenStackMachineTemplateSpec struct {
2626
// template is the OpenStackMachineTemplate resource data.
2727
// +required
28-
Template OpenStackMachineTemplateResource `json:"template"`
28+
Template OpenStackMachineTemplateResource `json:"template,omitzero"`
2929
}
3030

3131
// OpenStackMachineTemplateStatus defines the observed state of OpenStackMachineTemplate.

api/v1beta2/types.go

Lines changed: 61 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,14 @@ import (
2828
type OpenStackMachineTemplateResource struct {
2929
// spec is the specification of the desired behavior of the machine.
3030
// +required
31-
Spec OpenStackMachineSpec `json:"spec"`
31+
Spec OpenStackMachineSpec `json:"spec,omitzero"`
3232
}
3333

3434
type ResourceReference struct {
3535
// name is the name of the referenced resource
3636
// +required
37-
Name string `json:"name"`
37+
// +kubebuilder:validation:MinLength=1
38+
Name string `json:"name,omitempty"`
3839
}
3940

4041
// ImageParam describes a glance image. It can be specified by ID, filter, or a
@@ -116,7 +117,7 @@ type ExternalRouterIPParam struct {
116117
FixedIP string `json:"fixedIP,omitempty"`
117118
// subnet is the subnet in which the FixedIP is used for the Gateway of this router.
118119
// +required
119-
Subnet SubnetParam `json:"subnet"`
120+
Subnet SubnetParam `json:"subnet,omitzero"`
120121
}
121122

122123
// NeutronTag represents a tag on a Neutron resource.
@@ -340,7 +341,8 @@ type SubnetSpec struct {
340341
// cidr is representing the IP address range used to create the subnet, e.g. 10.0.0.0/24.
341342
// This field is required when defining a subnet.
342343
// +required
343-
CIDR string `json:"cidr"`
344+
// +kubebuilder:validation:MinLength=1
345+
CIDR string `json:"cidr,omitempty"`
344346

345347
// dnsNameservers holds a list of DNS server addresses that will be provided when creating
346348
// the subnet. These addresses need to have the same IP version as CIDR.
@@ -357,11 +359,13 @@ type SubnetSpec struct {
357359
type AllocationPool struct {
358360
// start represents the start of the AllocationPool, that is the lowest IP of the pool.
359361
// +required
360-
Start string `json:"start"`
362+
// +kubebuilder:validation:MinLength=1
363+
Start string `json:"start,omitempty"`
361364

362365
// end represents the end of the AlloctionPool, that is the highest IP of the pool.
363366
// +required
364-
End string `json:"end"`
367+
// +kubebuilder:validation:MinLength=1
368+
End string `json:"end,omitempty"`
365369
}
366370

367371
type PortOpts struct {
@@ -470,15 +474,17 @@ type ResolvedPortSpecFields struct {
470474
type ResolvedPortSpec struct {
471475
// name is the name of the port.
472476
// +required
473-
Name string `json:"name"`
477+
// +kubebuilder:validation:MinLength=1
478+
Name string `json:"name,omitempty"`
474479

475480
// description is a human-readable description for the port.
476481
// +optional
477482
Description string `json:"description"`
478483

479484
// networkID is the ID of the network the port will be created in.
480485
// +required
481-
NetworkID string `json:"networkID"`
486+
// +kubebuilder:validation:MinLength=1
487+
NetworkID string `json:"networkID,omitempty"`
482488

483489
// tags applied to the port (and corresponding trunk, if a trunk is configured.)
484490
// +listType=set
@@ -505,7 +511,8 @@ type ResolvedPortSpec struct {
505511
type PortStatus struct {
506512
// id is the unique identifier of the port.
507513
// +required
508-
ID string `json:"id"`
514+
// +kubebuilder:validation:MinLength=1
515+
ID string `json:"id,omitempty"`
509516
}
510517

511518
type BindingProfile struct {
@@ -553,7 +560,8 @@ type AddressPair struct {
553560
// the configuration of Neutron, it may be supported to specify a CIDR
554561
// instead of a specific IP address.
555562
// +required
556-
IPAddress string `json:"ipAddress"`
563+
// +kubebuilder:validation:MinLength=1
564+
IPAddress string `json:"ipAddress,omitempty"`
557565

558566
// macAddress is the MAC address of the allowed address pair. If not
559567
// specified, the MAC address will be the MAC address of the port.
@@ -595,7 +603,7 @@ type RootVolume struct {
595603
// sizeGiB is the size of the block device in gibibytes (GiB).
596604
// +required
597605
// +kubebuilder:validation:Minimum:=1
598-
SizeGiB int32 `json:"sizeGiB"`
606+
SizeGiB int32 `json:"sizeGiB,omitempty"`
599607

600608
BlockDeviceVolume `json:",inline"`
601609
}
@@ -610,7 +618,8 @@ type BlockDeviceStorage struct {
610618
// This can be either "Volume" or "Local".
611619
// +unionDiscriminator
612620
// +required
613-
Type BlockDeviceType `json:"type"`
621+
// +kubebuilder:validation:Enum=Local;Volume
622+
Type BlockDeviceType `json:"type,omitempty"`
614623

615624
// volume contains additional storage options for a volume block device.
616625
// +optional
@@ -676,17 +685,18 @@ type AdditionalBlockDevice struct {
676685
// metadata API or the config drive.
677686
// Name cannot be 'root', which is reserved for the root volume.
678687
// +required
679-
Name string `json:"name"`
688+
// +kubebuilder:validation:MinLength=1
689+
Name string `json:"name,omitempty"`
680690

681691
// sizeGiB is the size of the block device in gibibytes (GiB).
682692
// +required
683693
// +kubebuilder:validation:Minimum:=1
684-
SizeGiB int32 `json:"sizeGiB"`
694+
SizeGiB int32 `json:"sizeGiB,omitempty"`
685695

686696
// storage specifies the storage type of the block device and
687697
// additional storage options.
688698
// +required
689-
Storage BlockDeviceStorage `json:"storage"`
699+
Storage BlockDeviceStorage `json:"storage,omitzero"`
690700
}
691701

692702
// ServerGroupParam specifies an OpenStack server group. It may be specified by ID or filter, but not both.
@@ -733,10 +743,12 @@ const (
733743
type NetworkStatus struct {
734744
// name is the name of the network.
735745
// +required
736-
Name string `json:"name"`
746+
// +kubebuilder:validation:MinLength=1
747+
Name string `json:"name,omitempty"`
737748
// id is the unique identifier of the network.
738749
// +required
739-
ID string `json:"id"`
750+
// +kubebuilder:validation:MinLength=1
751+
ID string `json:"id,omitempty"`
740752

741753
// tags is a list of tags on the network.
742754
// +optional
@@ -756,14 +768,17 @@ type NetworkStatusWithSubnets struct {
756768
type Subnet struct {
757769
// name is the name of the subnet.
758770
// +required
759-
Name string `json:"name"`
771+
// +kubebuilder:validation:MinLength=1
772+
Name string `json:"name,omitempty"`
760773
// id is the unique identifier of the subnet.
761774
// +required
762-
ID string `json:"id"`
775+
// +kubebuilder:validation:MinLength=1
776+
ID string `json:"id,omitempty"`
763777

764778
// cidr is the CIDR of the subnet.
765779
// +required
766-
CIDR string `json:"cidr"`
780+
// +kubebuilder:validation:MinLength=1
781+
CIDR string `json:"cidr,omitempty"`
767782

768783
// tags is a list of tags on the subnet.
769784
// +optional
@@ -774,10 +789,12 @@ type Subnet struct {
774789
type Router struct {
775790
// name is the name of the router.
776791
// +required
777-
Name string `json:"name"`
792+
// +kubebuilder:validation:MinLength=1
793+
Name string `json:"name,omitempty"`
778794
// id is the unique identifier of the router.
779795
// +required
780-
ID string `json:"id"`
796+
// +kubebuilder:validation:MinLength=1
797+
ID string `json:"id,omitempty"`
781798
// tags is a list of tags on the router.
782799
// +optional
783800
Tags []string `json:"tags,omitempty"`
@@ -790,16 +807,20 @@ type Router struct {
790807
type LoadBalancer struct {
791808
// name is the name of the load balancer.
792809
// +required
793-
Name string `json:"name"`
810+
// +kubebuilder:validation:MinLength=1
811+
Name string `json:"name,omitempty"`
794812
// id is the unique identifier of the load balancer.
795813
// +required
796-
ID string `json:"id"`
814+
// +kubebuilder:validation:MinLength=1
815+
ID string `json:"id,omitempty"`
797816
// ip is the IP address of the load balancer.
798817
// +required
799-
IP string `json:"ip"`
818+
// +kubebuilder:validation:MinLength=1
819+
IP string `json:"ip,omitempty"`
800820
// internalIP is the internal IP address of the load balancer.
801821
// +required
802-
InternalIP string `json:"internalIP"`
822+
// +kubebuilder:validation:MinLength=1
823+
InternalIP string `json:"internalIP,omitempty"`
803824
// allowedCIDRs is a list of CIDRs that are allowed to access the load balancer.
804825
// +optional
805826
AllowedCIDRs []string `json:"allowedCIDRs,omitempty"`
@@ -819,11 +840,13 @@ type LoadBalancer struct {
819840
type SecurityGroupStatus struct {
820841
// name of the security group
821842
// +required
822-
Name string `json:"name"`
843+
// +kubebuilder:validation:MinLength=1
844+
Name string `json:"name,omitempty"`
823845

824846
// id of the security group
825847
// +required
826-
ID string `json:"id"`
848+
// +kubebuilder:validation:MinLength=1
849+
ID string `json:"id,omitempty"`
827850
}
828851

829852
// SecurityGroupRuleSpec represent the basic information of the associated OpenStack
@@ -835,7 +858,8 @@ type SecurityGroupRuleSpec struct {
835858
// name of the security group rule.
836859
// It's used to identify the rule so it can be patched and will not be sent to the OpenStack API.
837860
// +required
838-
Name string `json:"name"`
861+
// +kubebuilder:validation:MinLength=1
862+
Name string `json:"name,omitempty"`
839863

840864
// description of the security group rule.
841865
// +optional
@@ -847,7 +871,7 @@ type SecurityGroupRuleSpec struct {
847871
// instance. An egress rule is applied to traffic leaving the instance.
848872
// +required
849873
// +kubebuilder:validation:Enum=ingress;egress
850-
Direction string `json:"direction"`
874+
Direction string `json:"direction,omitempty"`
851875

852876
// etherType must be IPv4 or IPv6, and addresses represented in CIDR must match the
853877
// ingress or egress rules.
@@ -971,7 +995,7 @@ type APIServerLoadBalancer struct {
971995
//
972996
// +required
973997
// +kubebuilder:default:=true
974-
Enabled *bool `json:"enabled"`
998+
Enabled *bool `json:"enabled,omitempty"`
975999

9761000
// additionalPorts adds additional tcp ports to the load balancer.
9771001
// +optional
@@ -1082,13 +1106,16 @@ type ValueSpec struct {
10821106
// name is the name of the key-value pair.
10831107
// This is just for identifying the pair and will not be sent to the OpenStack API.
10841108
// +required
1085-
Name string `json:"name"`
1109+
// +kubebuilder:validation:MinLength=1
1110+
Name string `json:"name,omitempty"`
10861111
// key is the key in the key-value pair.
10871112
// +required
1088-
Key string `json:"key"`
1113+
// +kubebuilder:validation:MinLength=1
1114+
Key string `json:"key,omitempty"`
10891115
// value is the value in the key-value pair.
10901116
// +required
1091-
Value string `json:"value"`
1117+
// +kubebuilder:validation:MinLength=1
1118+
Value string `json:"value,omitempty"`
10921119
}
10931120

10941121
// JoinTags joins a slice of tags into a comma separated list of tags.

0 commit comments

Comments
 (0)