Skip to content

Commit 3a70529

Browse files
committed
api: make optional fields pointers for proper zero value handling
Bump kube-api-linter version and enable the optionalfields linter check. This enforces that optional fields use pointers to properly distinguish between unset values and zero values. Changes include: - Enable optionalfields linter in .golangci.yml - Convert optional string/bool/int fields to pointers across API types - Update controller code to use ptr.Deref() for pointer fields - Fix test assertions to use HaveValue() for pointer comparisons
1 parent 013e887 commit 3a70529

100 files changed

Lines changed: 1454 additions & 428 deletions

File tree

Some content is hidden

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

.golangci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@ linters:
3636
disable:
3737
# NOTE: conflicts with the lack of validation in the Status structs
3838
- arrayofstruct
39-
# NOTE: The following checks are currently failing
40-
- optionalfields
4139
enable:
4240
- commentstart
4341
- conditions

api/v1alpha1/controller_options.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ type ManagedOptions struct {
5252
// default is `delete`.
5353
// +kubebuilder:default:=delete
5454
// +optional
55-
OnDelete OnDelete `json:"onDelete,omitempty"`
55+
OnDelete *OnDelete `json:"onDelete,omitempty"`
5656
}
5757

5858
// GetOnDelete returns the delete behaviour from ManagedOptions. If called on a
5959
// nil receiver it safely returns the default.
6060
func (o *ManagedOptions) GetOnDelete() OnDelete {
61-
if o == nil {
61+
if o == nil || o.OnDelete == nil {
6262
return OnDeleteDelete
6363
}
64-
return o.OnDelete
64+
return *o.OnDelete
6565
}

api/v1alpha1/domain_types.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ type DomainResourceStatus struct {
5353
// name is a Human-readable name for the resource. Might not be unique.
5454
// +kubebuilder:validation:MaxLength=1024
5555
// +optional
56-
Name string `json:"name,omitempty"`
56+
Name *string `json:"name,omitempty"`
5757

5858
// description is a human-readable description for the resource.
5959
// +kubebuilder:validation:MaxLength=1024
6060
// +optional
61-
Description string `json:"description,omitempty"`
61+
Description *string `json:"description,omitempty"`
6262

6363
// enabled defines whether a domain is enabled or not. Default is true.
6464
// Note: Users can only authorize against an enabled domain (and any of its projects).

api/v1alpha1/flavor_types.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ type FlavorResourceSpec struct {
5656
// MiB. If 0 (the default), no dedicated swap disk will be created.
5757
// +kubebuilder:validation:Minimum=0
5858
// +optional
59-
Swap int32 `json:"swap,omitempty"`
59+
Swap *int32 `json:"swap,omitempty"`
6060

6161
// isPublic flags a flavor as being available to all projects or not.
6262
// +optional
@@ -68,7 +68,7 @@ type FlavorResourceSpec struct {
6868
// limitations. Defaults to 0.
6969
// +kubebuilder:validation:Minimum=0
7070
// +optional
71-
Ephemeral int32 `json:"ephemeral,omitempty"`
71+
Ephemeral *int32 `json:"ephemeral,omitempty"`
7272
}
7373

7474
// FlavorFilter defines an existing resource by its properties
@@ -99,12 +99,12 @@ type FlavorResourceStatus struct {
9999
// name is a Human-readable name for the flavor. Might not be unique.
100100
// +kubebuilder:validation:MaxLength=1024
101101
// +optional
102-
Name string `json:"name,omitempty"`
102+
Name *string `json:"name,omitempty"`
103103

104104
// description is a human-readable description for the resource.
105105
// +kubebuilder:validation:MaxLength:=65535
106106
// +optional
107-
Description string `json:"description,omitempty"`
107+
Description *string `json:"description,omitempty"`
108108

109109
// ram is the memory of the flavor, measured in MB.
110110
// +optional

api/v1alpha1/floatingip_types.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type FloatingIPFilter struct {
4343
// status is the status of the floatingip.
4444
// +kubebuilder:validation:MaxLength=1024
4545
// +optional
46-
Status string `json:"status,omitempty"`
46+
Status *string `json:"status,omitempty"`
4747

4848
FilterByNeutronTags `json:",inline"`
4949
}
@@ -98,47 +98,47 @@ type FloatingIPResourceStatus struct {
9898
// description is a human-readable description for the resource.
9999
// +kubebuilder:validation:MaxLength=1024
100100
// +optional
101-
Description string `json:"description,omitempty"`
101+
Description *string `json:"description,omitempty"`
102102

103103
// floatingNetworkID is the ID of the network to which the floatingip is associated.
104104
// +kubebuilder:validation:MaxLength=1024
105105
// +optional
106-
FloatingNetworkID string `json:"floatingNetworkID,omitempty"`
106+
FloatingNetworkID *string `json:"floatingNetworkID,omitempty"`
107107

108108
// floatingIP is the IP address of the floatingip.
109109
// +kubebuilder:validation:MaxLength=1024
110110
// +optional
111-
FloatingIP string `json:"floatingIP,omitempty"`
111+
FloatingIP *string `json:"floatingIP,omitempty"`
112112

113113
// portID is the ID of the port to which the floatingip is associated.
114114
// +kubebuilder:validation:MaxLength=1024
115115
// +optional
116-
PortID string `json:"portID,omitempty"`
116+
PortID *string `json:"portID,omitempty"`
117117

118118
// fixedIP is the IP address of the port to which the floatingip is associated.
119119
// +kubebuilder:validation:MaxLength=1024
120120
// +optional
121-
FixedIP string `json:"fixedIP,omitempty"`
121+
FixedIP *string `json:"fixedIP,omitempty"`
122122

123123
// tenantID is the project owner of the resource.
124124
// +kubebuilder:validation:MaxLength=1024
125125
// +optional
126-
TenantID string `json:"tenantID,omitempty"`
126+
TenantID *string `json:"tenantID,omitempty"`
127127

128128
// projectID is the project owner of the resource.
129129
// +kubebuilder:validation:MaxLength=1024
130130
// +optional
131-
ProjectID string `json:"projectID,omitempty"`
131+
ProjectID *string `json:"projectID,omitempty"`
132132

133133
// status indicates the current status of the resource.
134134
// +kubebuilder:validation:MaxLength=1024
135135
// +optional
136-
Status string `json:"status,omitempty"`
136+
Status *string `json:"status,omitempty"`
137137

138138
// routerID is the ID of the router to which the floatingip is associated.
139139
// +kubebuilder:validation:MaxLength=1024
140140
// +optional
141-
RouterID string `json:"routerID,omitempty"`
141+
RouterID *string `json:"routerID,omitempty"`
142142

143143
// tags is the list of tags on the resource.
144144
// +kubebuilder:validation:MaxItems:=64

api/v1alpha1/group_types.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@ type GroupResourceStatus struct {
5252
// name is a Human-readable name for the resource. Might not be unique.
5353
// +kubebuilder:validation:MaxLength=1024
5454
// +optional
55-
Name string `json:"name,omitempty"`
55+
Name *string `json:"name,omitempty"`
5656

5757
// description is a human-readable description for the resource.
5858
// +kubebuilder:validation:MaxLength=1024
5959
// +optional
60-
Description string `json:"description,omitempty"`
60+
Description *string `json:"description,omitempty"`
6161

6262
// domainID is the ID of the Domain to which the resource is associated.
6363
// +kubebuilder:validation:MaxLength=1024
6464
// +optional
65-
DomainID string `json:"domainID,omitempty"`
65+
DomainID *string `json:"domainID,omitempty"`
6666
}

api/v1alpha1/image_types.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ type ImageContent struct {
257257
// Permitted values are ami, ari, aki, bare, compressed, ovf, ova, and docker.
258258
// +kubebuilder:default:=bare
259259
// +optional
260-
ContainerFormat ImageContainerFormat `json:"containerFormat,omitempty"`
260+
ContainerFormat *ImageContainerFormat `json:"containerFormat,omitempty"`
261261

262262
// diskFormat is the format of the disk image.
263263
// Normal values are "qcow2", or "raw". Glance may be configured to support others.
@@ -363,21 +363,21 @@ type ImageResourceStatus struct {
363363
// name is a Human-readable name for the image. Might not be unique.
364364
// +kubebuilder:validation:MaxLength=1024
365365
// +optional
366-
Name string `json:"name,omitempty"`
366+
Name *string `json:"name,omitempty"`
367367

368368
// status is the image status as reported by Glance
369369
// +kubebuilder:validation:MaxLength=1024
370370
// +optional
371-
Status string `json:"status,omitempty"`
371+
Status *string `json:"status,omitempty"`
372372

373373
// protected specifies that the image is protected from deletion.
374374
// +optional
375-
Protected bool `json:"protected,omitempty"`
375+
Protected *bool `json:"protected,omitempty"`
376376

377377
// visibility of the image
378378
// +kubebuilder:validation:MaxLength=1024
379379
// +optional
380-
Visibility string `json:"visibility,omitempty"`
380+
Visibility *string `json:"visibility,omitempty"`
381381

382382
// hash is the hash of the image data published by Glance. Note that this is
383383
// a hash of the data stored internally by Glance, which will have been

api/v1alpha1/keypair_types.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,20 @@ type KeyPairResourceStatus struct {
4949
// name is a Human-readable name for the resource. Might not be unique.
5050
// +kubebuilder:validation:MaxLength=1024
5151
// +optional
52-
Name string `json:"name,omitempty"`
52+
Name *string `json:"name,omitempty"`
5353

5454
// fingerprint is the fingerprint of the public key
5555
// +kubebuilder:validation:MaxLength=1024
5656
// +optional
57-
Fingerprint string `json:"fingerprint,omitempty"`
57+
Fingerprint *string `json:"fingerprint,omitempty"`
5858

5959
// publicKey is the public key of the Keypair
6060
// +kubebuilder:validation:MaxLength=16384
6161
// +optional
62-
PublicKey string `json:"publicKey,omitempty"`
62+
PublicKey *string `json:"publicKey,omitempty"`
6363

6464
// type is the type of the Keypair (ssh or x509)
6565
// +kubebuilder:validation:MaxLength=64
6666
// +optional
67-
Type string `json:"type,omitempty"`
67+
Type *string `json:"type,omitempty"`
6868
}

api/v1alpha1/network_types.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type ProviderPropertiesStatus struct {
2222
// Valid values depend on the networking back-end.
2323
// +kubebuilder:validation:MaxLength=1024
2424
// +optional
25-
NetworkType string `json:"networkType,omitempty"`
25+
NetworkType *string `json:"networkType,omitempty"`
2626

2727
// physicalNetwork is the physical network where this network
2828
// should be implemented. The Networking API v2.0 does not provide a
@@ -31,7 +31,7 @@ type ProviderPropertiesStatus struct {
3131
// to specific bridges on each compute host.
3232
// +kubebuilder:validation:MaxLength=1024
3333
// +optional
34-
PhysicalNetwork string `json:"physicalNetwork,omitempty"`
34+
PhysicalNetwork *string `json:"physicalNetwork,omitempty"`
3535

3636
// segmentationID is the ID of the isolated segment on the
3737
// physical network. The network_type attribute defines the
@@ -146,24 +146,24 @@ type NetworkResourceStatus struct {
146146
// name is a Human-readable name for the network. Might not be unique.
147147
// +kubebuilder:validation:MaxLength=1024
148148
// +optional
149-
Name string `json:"name,omitempty"`
149+
Name *string `json:"name,omitempty"`
150150

151151
// description is a human-readable description for the resource.
152152
// +kubebuilder:validation:MaxLength=1024
153153
// +optional
154-
Description string `json:"description,omitempty"`
154+
Description *string `json:"description,omitempty"`
155155

156156
// projectID is the project owner of the network.
157157
// +kubebuilder:validation:MaxLength=1024
158158
// +optional
159-
ProjectID string `json:"projectID,omitempty"`
159+
ProjectID *string `json:"projectID,omitempty"`
160160

161161
// status indicates whether network is currently operational. Possible values
162162
// include `ACTIVE', `DOWN', `BUILD', or `ERROR'. Plug-ins might define
163163
// additional values.
164164
// +kubebuilder:validation:MaxLength=1024
165165
// +optional
166-
Status string `json:"status,omitempty"`
166+
Status *string `json:"status,omitempty"`
167167

168168
// tags is the list of tags on the resource.
169169
// +kubebuilder:validation:MaxItems=64
@@ -177,7 +177,7 @@ type NetworkResourceStatus struct {
177177
// adminStateUp is the administrative state of the network,
178178
// which is up (true) or down (false).
179179
// +optional
180-
AdminStateUp *bool `json:"adminStateUp"`
180+
AdminStateUp *bool `json:"adminStateUp,omitempty"`
181181

182182
// availabilityZoneHints is the availability zone candidate for the
183183
// network.
@@ -190,7 +190,7 @@ type NetworkResourceStatus struct {
190190
// dnsDomain is the DNS domain of the network
191191
// +kubebuilder:validation:MaxLength=1024
192192
// +optional
193-
DNSDomain string `json:"dnsDomain,omitempty"`
193+
DNSDomain *string `json:"dnsDomain,omitempty"`
194194

195195
// mtu is the the maximum transmission unit value to address
196196
// fragmentation. Minimum value is 68 for IPv4, and 1280 for IPv6.

0 commit comments

Comments
 (0)