Skip to content

Commit cc32a8a

Browse files
committed
PortOpts: Use RestoreString optional.String fields
1 parent 0caecf4 commit cc32a8a

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

api/v1alpha7/types_conversion.go

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"k8s.io/utils/pointer"
2222

2323
infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1"
24+
"sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/optional"
2425
)
2526

2627
/* SecurityGroupFilter */
@@ -200,17 +201,9 @@ func restorev1alpha7Port(previous *PortOpts, dst *PortOpts) {
200201
}
201202

202203
func restorev1beta1Port(previous *infrav1.PortOpts, dst *infrav1.PortOpts) {
203-
if dst.NameSuffix == nil || *dst.NameSuffix == "" {
204-
dst.NameSuffix = previous.NameSuffix
205-
}
206-
207-
if dst.Description == nil || *dst.Description == "" {
208-
dst.Description = previous.Description
209-
}
210-
211-
if dst.MACAddress == nil || *dst.MACAddress == "" {
212-
dst.MACAddress = previous.MACAddress
213-
}
204+
optional.RestoreString(&previous.NameSuffix, &dst.NameSuffix)
205+
optional.RestoreString(&previous.Description, &dst.Description)
206+
optional.RestoreString(&previous.MACAddress, &dst.MACAddress)
214207

215208
if len(dst.FixedIPs) == len(previous.FixedIPs) {
216209
for j := range dst.FixedIPs {
@@ -234,13 +227,8 @@ func restorev1beta1Port(previous *infrav1.PortOpts, dst *infrav1.PortOpts) {
234227
}
235228
}
236229

237-
if dst.HostID == nil || *dst.HostID == "" {
238-
dst.HostID = previous.HostID
239-
}
240-
241-
if dst.VNICType == nil || *dst.VNICType == "" {
242-
dst.VNICType = previous.VNICType
243-
}
230+
optional.RestoreString(&previous.HostID, &dst.HostID)
231+
optional.RestoreString(&previous.VNICType, &dst.VNICType)
244232

245233
if dst.Profile == nil && previous.Profile != nil {
246234
dst.Profile = &infrav1.BindingProfile{}

0 commit comments

Comments
 (0)