Skip to content

Commit f8ae412

Browse files
mdboothhuxcrux
authored andcommitted
v1alpha6: Simplify v1alpha6 cluster restorer
This is a breaking change, although it should not have any negative effects in practise. The v1alpha6 cluster restorer had become too complex with too many individual fields. This change reduces the number of fields to be consistent with the v1alpha7 restorer. With this change, an object stored as v1alpha6 with previous v1beta1 annotations could have fields in its spec restored to a semantically equivalent but slightly different serialisation when converted to v1beta1. Differences in the bastion and status are not affected. In practise this should not matter for 2 reasons: * The storage version is v1beta1, so the annotation should have been freshly generated in the new format anyway. * Even if it were not, and the v1alpha6 were under external control, the external controller would observe a difference and restore it to the previous version. It would then converted again with the new annotation. Note that if the object is not under external control these differences don't matter anyway.
1 parent 8d1419c commit f8ae412

File tree

3 files changed

+52
-88
lines changed

3 files changed

+52
-88
lines changed

api/v1alpha6/openstackcluster_conversion.go

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -80,55 +80,35 @@ var v1alpha6OpenStackClusterRestorer = conversion.RestorerFor[*OpenStackCluster]
8080
}
8181

8282
var v1beta1OpenStackClusterRestorer = conversion.RestorerFor[*infrav1.OpenStackCluster]{
83-
"externalNetwork": conversion.UnconditionalFieldRestorer(
84-
func(c *infrav1.OpenStackCluster) *infrav1.NetworkFilter {
85-
return &c.Spec.ExternalNetwork
86-
},
87-
),
88-
"disableExternalNetwork": conversion.UnconditionalFieldRestorer(
89-
func(c *infrav1.OpenStackCluster) *bool {
90-
return &c.Spec.DisableExternalNetwork
91-
},
92-
),
93-
"router": conversion.UnconditionalFieldRestorer(
94-
func(c *infrav1.OpenStackCluster) **infrav1.RouterFilter {
95-
return &c.Spec.Router
96-
},
97-
),
98-
"networkMtu": conversion.UnconditionalFieldRestorer(
99-
func(c *infrav1.OpenStackCluster) *int {
100-
return &c.Spec.NetworkMTU
101-
},
102-
),
10383
"bastion": conversion.HashedFieldRestorer(
10484
func(c *infrav1.OpenStackCluster) **infrav1.Bastion {
10585
return &c.Spec.Bastion
10686
},
10787
restorev1beta1Bastion,
10888
),
109-
"subnets": conversion.HashedFieldRestorer(
110-
func(c *infrav1.OpenStackCluster) *[]infrav1.SubnetFilter {
111-
return &c.Spec.Subnets
112-
},
113-
restorev1beta1Subnets,
114-
),
115-
"allNodesSecurityGroupRules": conversion.HashedFieldRestorer(
116-
func(c *infrav1.OpenStackCluster) *infrav1.ManagedSecurityGroups {
117-
return c.Spec.ManagedSecurityGroups
89+
"spec": conversion.HashedFieldRestorer(
90+
func(c *infrav1.OpenStackCluster) *infrav1.OpenStackClusterSpec {
91+
return &c.Spec
11892
},
119-
restorev1beta1ManagedSecurityGroups,
93+
restorev1beta1ClusterSpec,
94+
// Filter out Bastion, which is restored separately
95+
conversion.HashedFilterField[*infrav1.OpenStackCluster, infrav1.OpenStackClusterSpec](
96+
func(s *infrav1.OpenStackClusterSpec) *infrav1.OpenStackClusterSpec {
97+
if s.Bastion != nil {
98+
f := *s
99+
f.Bastion = nil
100+
return &f
101+
}
102+
return s
103+
},
104+
),
120105
),
121106
"status": conversion.HashedFieldRestorer(
122107
func(c *infrav1.OpenStackCluster) *infrav1.OpenStackClusterStatus {
123108
return &c.Status
124109
},
125110
restorev1beta1ClusterStatus,
126111
),
127-
"managedSubnets": conversion.UnconditionalFieldRestorer(
128-
func(c *infrav1.OpenStackCluster) *[]infrav1.SubnetSpec {
129-
return &c.Spec.ManagedSubnets
130-
},
131-
),
132112
}
133113

134114
/* OpenStackClusterSpec */
@@ -179,6 +159,34 @@ func restorev1alpha6ClusterSpec(previous *OpenStackClusterSpec, dst *OpenStackCl
179159
restorev1alpha6NetworkFilter(&previous.Network, &dst.Network)
180160
}
181161

162+
func restorev1beta1ClusterSpec(previous *infrav1.OpenStackClusterSpec, dst *infrav1.OpenStackClusterSpec) {
163+
// Bastion is restored separately
164+
165+
// Restore all fields except ID, which should have been copied over in conversion
166+
dst.ExternalNetwork.Name = previous.ExternalNetwork.Name
167+
dst.ExternalNetwork.Description = previous.ExternalNetwork.Description
168+
dst.ExternalNetwork.ProjectID = previous.ExternalNetwork.ProjectID
169+
dst.ExternalNetwork.Tags = previous.ExternalNetwork.Tags
170+
dst.ExternalNetwork.TagsAny = previous.ExternalNetwork.TagsAny
171+
dst.ExternalNetwork.NotTags = previous.ExternalNetwork.NotTags
172+
dst.ExternalNetwork.NotTagsAny = previous.ExternalNetwork.NotTagsAny
173+
174+
// Restore fields not present in v1alpha6
175+
dst.Router = previous.Router
176+
dst.NetworkMTU = previous.NetworkMTU
177+
dst.DisableExternalNetwork = previous.DisableExternalNetwork
178+
179+
if len(previous.Subnets) > 1 {
180+
dst.Subnets = append(dst.Subnets, previous.Subnets[1:]...)
181+
}
182+
183+
dst.ManagedSubnets = previous.ManagedSubnets
184+
185+
if previous.ManagedSecurityGroups != nil {
186+
dst.ManagedSecurityGroups.AllNodesSecurityGroupRules = previous.ManagedSecurityGroups.AllNodesSecurityGroupRules
187+
}
188+
}
189+
182190
func Convert_v1alpha6_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(in *OpenStackClusterSpec, out *infrav1.OpenStackClusterSpec, s apiconversion.Scope) error {
183191
err := autoConvert_v1alpha6_OpenStackClusterSpec_To_v1beta1_OpenStackClusterSpec(in, out, s)
184192
if err != nil {
@@ -392,9 +400,3 @@ func Convert_v1beta1_Bastion_To_v1alpha6_Bastion(in *infrav1.Bastion, out *Basti
392400
out.Instance.FloatingIP = in.FloatingIP
393401
return nil
394402
}
395-
396-
/* ManagedSecurityGroups */
397-
398-
func restorev1beta1ManagedSecurityGroups(previous *infrav1.ManagedSecurityGroups, dst *infrav1.ManagedSecurityGroups) {
399-
dst.AllNodesSecurityGroupRules = previous.AllNodesSecurityGroupRules
400-
}

api/v1alpha6/openstackclustertemplate_conversion.go

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -69,47 +69,15 @@ var v1alpha6OpenStackClusterTemplateRestorer = conversion.RestorerFor[*OpenStack
6969
}
7070

7171
var v1beta1OpenStackClusterTemplateRestorer = conversion.RestorerFor[*infrav1.OpenStackClusterTemplate]{
72-
"externalNetwork": conversion.UnconditionalFieldRestorer(
73-
func(c *infrav1.OpenStackClusterTemplate) *infrav1.NetworkFilter {
74-
return &c.Spec.Template.Spec.ExternalNetwork
75-
},
76-
),
77-
"disableExternalNetwork": conversion.UnconditionalFieldRestorer(
78-
func(c *infrav1.OpenStackClusterTemplate) *bool {
79-
return &c.Spec.Template.Spec.DisableExternalNetwork
80-
},
81-
),
82-
"router": conversion.UnconditionalFieldRestorer(
83-
func(c *infrav1.OpenStackClusterTemplate) **infrav1.RouterFilter {
84-
return &c.Spec.Template.Spec.Router
85-
},
86-
),
87-
"networkMtu": conversion.UnconditionalFieldRestorer(
88-
func(c *infrav1.OpenStackClusterTemplate) *int {
89-
return &c.Spec.Template.Spec.NetworkMTU
90-
},
91-
),
92-
"bastion": conversion.HashedFieldRestorer(
93-
func(c *infrav1.OpenStackClusterTemplate) **infrav1.Bastion {
94-
return &c.Spec.Template.Spec.Bastion
95-
},
96-
restorev1beta1Bastion,
97-
),
98-
"subnets": conversion.HashedFieldRestorer(
99-
func(c *infrav1.OpenStackClusterTemplate) *[]infrav1.SubnetFilter {
100-
return &c.Spec.Template.Spec.Subnets
101-
},
102-
restorev1beta1Subnets,
103-
),
104-
"allNodesSecurityGroupRules": conversion.HashedFieldRestorer(
105-
func(c *infrav1.OpenStackClusterTemplate) *infrav1.ManagedSecurityGroups {
106-
return c.Spec.Template.Spec.ManagedSecurityGroups
107-
},
108-
restorev1beta1ManagedSecurityGroups,
109-
),
110-
"managedSubnets": conversion.UnconditionalFieldRestorer(
111-
func(c *infrav1.OpenStackClusterTemplate) *[]infrav1.SubnetSpec {
112-
return &c.Spec.Template.Spec.ManagedSubnets
72+
"spec": conversion.HashedFieldRestorer(
73+
func(c *infrav1.OpenStackClusterTemplate) *infrav1.OpenStackClusterTemplateSpec {
74+
return &c.Spec
11375
},
76+
restorev1beta1ClusterTemplateSpec,
11477
),
11578
}
79+
80+
func restorev1beta1ClusterTemplateSpec(previous *infrav1.OpenStackClusterTemplateSpec, dst *infrav1.OpenStackClusterTemplateSpec) {
81+
restorev1beta1Bastion(&previous.Template.Spec.Bastion, &dst.Template.Spec.Bastion)
82+
restorev1beta1ClusterSpec(&previous.Template.Spec, &dst.Template.Spec)
83+
}

api/v1alpha6/types_conversion.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,12 +137,6 @@ func restorev1alpha6SubnetFilter(previous *SubnetFilter, dst *SubnetFilter) {
137137
dst.NotTagsAny = previous.NotTagsAny
138138
}
139139

140-
func restorev1beta1Subnets(previous *[]infrav1.SubnetFilter, dst *[]infrav1.SubnetFilter) {
141-
if len(*previous) > 1 {
142-
*dst = append(*dst, (*previous)[1:]...)
143-
}
144-
}
145-
146140
func Convert_v1alpha6_SubnetParam_To_v1beta1_SubnetFilter(in *SubnetParam, out *infrav1.SubnetFilter, s apiconversion.Scope) error {
147141
if err := Convert_v1alpha6_SubnetFilter_To_v1beta1_SubnetFilter(&in.Filter, out, s); err != nil {
148142
return err

0 commit comments

Comments
 (0)