@@ -18,6 +18,7 @@ package v1alpha7
1818
1919import (
2020 apiconversion "k8s.io/apimachinery/pkg/conversion"
21+ "k8s.io/utils/pointer"
2122 ctrlconversion "sigs.k8s.io/controller-runtime/pkg/conversion"
2223
2324 infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha8"
@@ -86,28 +87,30 @@ func restorev1alpha8SecurityGroupStatus(previous *infrav1.SecurityGroupStatus, d
8687 return
8788 }
8889
89- for i , rule := range dst .Rules {
90+ for i := range dst .Rules {
91+ dstRule := & dst .Rules [i ]
92+
9093 // Conversion from scalar to *scalar is lossy for zero values. We need to restore only nil values.
91- if rule .Description != nil && * rule .Description == "" {
92- rule .Description = previous .Rules [i ].Description
94+ if dstRule .Description != nil && * dstRule .Description == "" {
95+ dstRule .Description = previous .Rules [i ].Description
9396 }
94- if rule .EtherType != nil && * rule .EtherType == "" {
95- rule .EtherType = previous .Rules [i ].EtherType
97+ if dstRule .EtherType != nil && * dstRule .EtherType == "" {
98+ dstRule .EtherType = previous .Rules [i ].EtherType
9699 }
97- if rule .PortRangeMin != nil && * rule .PortRangeMin == 0 {
98- rule .PortRangeMin = previous .Rules [i ].PortRangeMin
100+ if dstRule .PortRangeMin != nil && * dstRule .PortRangeMin == 0 {
101+ dstRule .PortRangeMin = previous .Rules [i ].PortRangeMin
99102 }
100- if rule .PortRangeMax != nil && * rule .PortRangeMax == 0 {
101- rule .PortRangeMax = previous .Rules [i ].PortRangeMax
103+ if dstRule .PortRangeMax != nil && * dstRule .PortRangeMax == 0 {
104+ dstRule .PortRangeMax = previous .Rules [i ].PortRangeMax
102105 }
103- if rule .Protocol != nil && * rule .Protocol == "" {
104- rule .Protocol = previous .Rules [i ].Protocol
106+ if dstRule .Protocol != nil && * dstRule .Protocol == "" {
107+ dstRule .Protocol = previous .Rules [i ].Protocol
105108 }
106- if rule .RemoteGroupID != nil && * rule .RemoteGroupID == "" {
107- rule .RemoteGroupID = previous .Rules [i ].RemoteGroupID
109+ if dstRule .RemoteGroupID != nil && * dstRule .RemoteGroupID == "" {
110+ dstRule .RemoteGroupID = previous .Rules [i ].RemoteGroupID
108111 }
109- if rule .RemoteIPPrefix != nil && * rule .RemoteIPPrefix == "" {
110- rule .RemoteIPPrefix = previous .Rules [i ].RemoteIPPrefix
112+ if dstRule .RemoteIPPrefix != nil && * dstRule .RemoteIPPrefix == "" {
113+ dstRule .RemoteIPPrefix = previous .Rules [i ].RemoteIPPrefix
111114 }
112115 }
113116}
@@ -116,6 +119,11 @@ func restorev1alpha8ClusterStatus(previous *infrav1.OpenStackClusterStatus, dst
116119 restorev1alpha8SecurityGroupStatus (previous .ControlPlaneSecurityGroup , dst .ControlPlaneSecurityGroup )
117120 restorev1alpha8SecurityGroupStatus (previous .WorkerSecurityGroup , dst .WorkerSecurityGroup )
118121 restorev1alpha8SecurityGroupStatus (previous .BastionSecurityGroup , dst .BastionSecurityGroup )
122+
123+ // ReferencedResources have no equivalent in v1alpha7
124+ if dst .Bastion != nil {
125+ dst .Bastion .ReferencedResources = previous .Bastion .ReferencedResources
126+ }
119127}
120128
121129var v1alpha8OpenStackClusterRestorer = conversion.RestorerFor [* infrav1.OpenStackCluster ]{
@@ -144,16 +152,6 @@ var v1alpha8OpenStackClusterRestorer = conversion.RestorerFor[*infrav1.OpenStack
144152 ),
145153 ),
146154
147- // No equivalent in v1alpha7
148- "bastionrefresources" : conversion .UnconditionalFieldRestorer (
149- func (c * infrav1.OpenStackCluster ) * infrav1.ReferencedMachineResources {
150- if c .Status .Bastion == nil {
151- return nil
152- }
153- return & c .Status .Bastion .ReferencedResources
154- },
155- ),
156-
157155 "status" : conversion .HashedFieldRestorer (
158156 func (c * infrav1.OpenStackCluster ) * infrav1.OpenStackClusterStatus {
159157 return & c .Status
@@ -658,14 +656,14 @@ func Convert_v1alpha7_SecurityGroup_To_v1alpha8_SecurityGroupStatus(in *Security
658656 for i , rule := range in .Rules {
659657 out .Rules [i ] = infrav1.SecurityGroupRuleStatus {
660658 ID : rule .ID ,
661- Description : & rule .Description ,
659+ Description : pointer . String ( rule .Description ) ,
662660 Direction : rule .Direction ,
663- EtherType : & rule .EtherType ,
664- PortRangeMin : & rule .PortRangeMin ,
665- PortRangeMax : & rule .PortRangeMax ,
666- Protocol : & rule .Protocol ,
667- RemoteGroupID : & rule .RemoteGroupID ,
668- RemoteIPPrefix : & rule .RemoteIPPrefix ,
661+ EtherType : pointer . String ( rule .EtherType ) ,
662+ PortRangeMin : pointer . Int ( rule .PortRangeMin ) ,
663+ PortRangeMax : pointer . Int ( rule .PortRangeMax ) ,
664+ Protocol : pointer . String ( rule .Protocol ) ,
665+ RemoteGroupID : pointer . String ( rule .RemoteGroupID ) ,
666+ RemoteIPPrefix : pointer . String ( rule .RemoteIPPrefix ) ,
669667 }
670668 }
671669
0 commit comments