Skip to content

Commit 525d476

Browse files
committed
Convert Image to use ImageFilfter instead of string
Right now, the image for an OpenStackMachine can be defined either its name via Spec.Image or via Spec.ImageUUID. Now we will use a single parameter which would be of type ImageFilter.
1 parent 3707a7c commit 525d476

Some content is hidden

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

42 files changed

+578
-186
lines changed

api/v1alpha5/conversion.go

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,21 @@ func Convert_v1alpha8_PortOpts_To_v1alpha5_PortOpts(in *infrav1.PortOpts, out *P
213213
}
214214

215215
func Convert_v1alpha5_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec(in *OpenStackMachineSpec, out *infrav1.OpenStackMachineSpec, s conversion.Scope) error {
216-
return autoConvert_v1alpha5_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec(in, out, s)
216+
err := autoConvert_v1alpha5_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec(in, out, s)
217+
if err != nil {
218+
return err
219+
}
220+
221+
imageFilter := infrav1.ImageFilter{}
222+
if in.Image != "" {
223+
imageFilter.Name = in.Image
224+
}
225+
if in.ImageUUID != "" {
226+
imageFilter.ID = in.ImageUUID
227+
}
228+
out.Image = imageFilter
229+
230+
return nil
217231
}
218232

219233
func Convert_v1alpha8_APIServerLoadBalancer_To_v1alpha5_APIServerLoadBalancer(in *infrav1.APIServerLoadBalancer, out *APIServerLoadBalancer, s conversion.Scope) error {
@@ -435,5 +449,18 @@ func Convert_v1alpha5_OpenStackClusterStatus_To_v1alpha8_OpenStackClusterStatus(
435449
}
436450

437451
func Convert_v1alpha8_OpenStackMachineSpec_To_v1alpha5_OpenStackMachineSpec(in *infrav1.OpenStackMachineSpec, out *OpenStackMachineSpec, s conversion.Scope) error {
438-
return autoConvert_v1alpha8_OpenStackMachineSpec_To_v1alpha5_OpenStackMachineSpec(in, out, s)
452+
err := autoConvert_v1alpha8_OpenStackMachineSpec_To_v1alpha5_OpenStackMachineSpec(in, out, s)
453+
if err != nil {
454+
return err
455+
}
456+
457+
if in.Image.Name != "" {
458+
out.Image = in.Image.Name
459+
}
460+
461+
if in.Image.ID != "" {
462+
out.ImageUUID = in.Image.ID
463+
}
464+
465+
return nil
439466
}

api/v1alpha5/conversion_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func TestConvertFrom(t *testing.T) {
7979
Spec: OpenStackMachineSpec{},
8080
ObjectMeta: metav1.ObjectMeta{
8181
Annotations: map[string]string{
82-
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"cloudName\":\"\",\"flavor\":\"\"},\"status\":{\"ready\":false}}",
82+
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"cloudName\":\"\",\"flavor\":\"\",\"image\":{}},\"status\":{\"ready\":false}}",
8383
},
8484
},
8585
},
@@ -94,7 +94,7 @@ func TestConvertFrom(t *testing.T) {
9494
Spec: OpenStackMachineTemplateSpec{},
9595
ObjectMeta: metav1.ObjectMeta{
9696
Annotations: map[string]string{
97-
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"template\":{\"spec\":{\"cloudName\":\"\",\"flavor\":\"\"}}}}",
97+
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"template\":{\"spec\":{\"cloudName\":\"\",\"flavor\":\"\",\"image\":{}}}}}",
9898
},
9999
},
100100
},

api/v1alpha5/zz_generated.conversion.go

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha6/conversion.go

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,33 @@ func Convert_v1alpha6_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec(in *
362362
// Networks were previously created first, so need to come before ports
363363
out.Ports = append(ports, out.Ports...)
364364
}
365+
366+
imageFilter := infrav1.ImageFilter{}
367+
if in.Image != "" {
368+
imageFilter.Name = in.Image
369+
}
370+
if in.ImageUUID != "" {
371+
imageFilter.ID = in.ImageUUID
372+
}
373+
out.Image = imageFilter
374+
375+
return nil
376+
}
377+
378+
func Convert_v1alpha8_OpenStackMachineSpec_To_v1alpha6_OpenStackMachineSpec(in *infrav1.OpenStackMachineSpec, out *OpenStackMachineSpec, s apiconversion.Scope) error {
379+
err := autoConvert_v1alpha8_OpenStackMachineSpec_To_v1alpha6_OpenStackMachineSpec(in, out, s)
380+
if err != nil {
381+
return err
382+
}
383+
384+
if in.Image.Name != "" {
385+
out.Image = in.Image.Name
386+
}
387+
388+
if in.Image.ID != "" {
389+
out.ImageUUID = in.Image.ID
390+
}
391+
365392
return nil
366393
}
367394

@@ -655,7 +682,3 @@ func Convert_v1alpha6_OpenStackClusterStatus_To_v1alpha8_OpenStackClusterStatus(
655682

656683
return nil
657684
}
658-
659-
func Convert_v1alpha8_OpenStackMachineSpec_To_v1alpha6_OpenStackMachineSpec(in *infrav1.OpenStackMachineSpec, out *OpenStackMachineSpec, s apiconversion.Scope) error {
660-
return autoConvert_v1alpha8_OpenStackMachineSpec_To_v1alpha6_OpenStackMachineSpec(in, out, s)
661-
}

api/v1alpha6/conversion_test.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,38 @@ func TestFuzzyConversion(t *testing.T) {
8888
status.ExternalNetwork.APIServerLoadBalancer = nil
8989
}
9090
},
91+
92+
func(v1alpha8Machine *infrav1.OpenStackMachine, c fuzz.Continue) {
93+
c.FuzzNoCustom(v1alpha8Machine)
94+
95+
// None of the following fields have ever been set in v1alpha6
96+
v1alpha8Machine.Spec.Image.Tags = []string{}
97+
},
98+
99+
func(v1alpha8MachineTemplate *infrav1.OpenStackMachineTemplate, c fuzz.Continue) {
100+
c.FuzzNoCustom(v1alpha8MachineTemplate)
101+
102+
// None of the following fields have ever been set in v1alpha6
103+
v1alpha8MachineTemplate.Spec.Template.Spec.Image.Tags = []string{}
104+
},
105+
106+
func(v1alpha8Cluster *infrav1.OpenStackCluster, c fuzz.Continue) {
107+
c.FuzzNoCustom(v1alpha8Cluster)
108+
109+
// None of the following fields have ever been set in v1alpha6
110+
if v1alpha8Cluster.Spec.Bastion != nil {
111+
v1alpha8Cluster.Spec.Bastion.Instance.Image.Tags = []string{}
112+
}
113+
},
114+
115+
func(v1alpha8ClusterTemplate *infrav1.OpenStackClusterTemplate, c fuzz.Continue) {
116+
c.FuzzNoCustom(v1alpha8ClusterTemplate)
117+
118+
// None of the following fields have ever been set in v1alpha6
119+
if v1alpha8ClusterTemplate.Spec.Template.Spec.Bastion != nil {
120+
v1alpha8ClusterTemplate.Spec.Template.Spec.Bastion.Instance.Image.Tags = []string{}
121+
}
122+
},
91123
}
92124
}
93125

@@ -112,6 +144,7 @@ func TestFuzzyConversion(t *testing.T) {
112144
Hub: &infrav1.OpenStackClusterTemplate{},
113145
Spoke: &OpenStackClusterTemplate{},
114146
HubAfterMutation: ignoreDataAnnotation,
147+
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
115148
})))
116149

117150
t.Run("for OpenStackClusterTemplate with mutate", runParallel(testhelpers.FuzzMutateTestFunc(testhelpers.FuzzMutateTestFuncInput{
@@ -120,34 +153,41 @@ func TestFuzzyConversion(t *testing.T) {
120153
Spoke: &OpenStackClusterTemplate{},
121154
HubAfterMutation: ignoreDataAnnotation,
122155
},
156+
MutateFuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
123157
})))
124158

125159
t.Run("for OpenStackMachine", runParallel(utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
126160
Hub: &infrav1.OpenStackMachine{},
127161
Spoke: &OpenStackMachine{},
128162
HubAfterMutation: ignoreDataAnnotation,
163+
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
129164
})))
130165

131166
t.Run("for OpenStackMachine with mutate", runParallel(testhelpers.FuzzMutateTestFunc(testhelpers.FuzzMutateTestFuncInput{
132167
FuzzTestFuncInput: utilconversion.FuzzTestFuncInput{
133168
Hub: &infrav1.OpenStackMachine{},
134169
Spoke: &OpenStackMachine{},
135170
HubAfterMutation: ignoreDataAnnotation,
171+
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
136172
},
173+
MutateFuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
137174
})))
138175

139176
t.Run("for OpenStackMachineTemplate", runParallel(utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
140177
Hub: &infrav1.OpenStackMachineTemplate{},
141178
Spoke: &OpenStackMachineTemplate{},
142179
HubAfterMutation: ignoreDataAnnotation,
180+
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
143181
})))
144182

145183
t.Run("for OpenStackMachineTemplate with mutate", runParallel(testhelpers.FuzzMutateTestFunc(testhelpers.FuzzMutateTestFuncInput{
146184
FuzzTestFuncInput: utilconversion.FuzzTestFuncInput{
147185
Hub: &infrav1.OpenStackMachineTemplate{},
148186
Spoke: &OpenStackMachineTemplate{},
149187
HubAfterMutation: ignoreDataAnnotation,
188+
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
150189
},
190+
MutateFuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
151191
})))
152192
}
153193

api/v1alpha6/zz_generated.conversion.go

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha7/conversion.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1alpha7
1818

1919
import (
20+
apiconversion "k8s.io/apimachinery/pkg/conversion"
2021
ctrlconversion "sigs.k8s.io/controller-runtime/pkg/conversion"
2122

2223
infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha8"
@@ -25,6 +26,10 @@ import (
2526

2627
var _ ctrlconversion.Convertible = &OpenStackCluster{}
2728

29+
func restorev1alpha8MachineSpec(previous *infrav1.OpenStackMachineSpec, dst *infrav1.OpenStackMachineSpec) {
30+
dst.Image = previous.Image
31+
}
32+
2833
var v1alpha7OpenStackClusterRestorer = conversion.RestorerFor[*OpenStackCluster]{
2934
"spec": conversion.HashedFieldRestorer[*OpenStackCluster, OpenStackClusterSpec]{
3035
GetField: func(c *OpenStackCluster) *OpenStackClusterSpec {
@@ -144,6 +149,7 @@ var v1alpha8OpenStackMachineRestorer = conversion.RestorerFor[*infrav1.OpenStack
144149
GetField: func(c *infrav1.OpenStackMachine) *infrav1.OpenStackMachineSpec {
145150
return &c.Spec
146151
},
152+
RestoreField: restorev1alpha8MachineSpec,
147153
},
148154
}
149155

@@ -196,6 +202,7 @@ var v1alpha8OpenStackMachineTemplateRestorer = conversion.RestorerFor[*infrav1.O
196202
GetField: func(c *infrav1.OpenStackMachineTemplate) *infrav1.OpenStackMachineSpec {
197203
return &c.Spec.Template.Spec
198204
},
205+
RestoreField: restorev1alpha8MachineSpec,
199206
},
200207
}
201208

@@ -232,3 +239,38 @@ func (r *OpenStackMachineTemplateList) ConvertFrom(srcRaw ctrlconversion.Hub) er
232239
src := srcRaw.(*infrav1.OpenStackMachineTemplateList)
233240
return Convert_v1alpha8_OpenStackMachineTemplateList_To_v1alpha7_OpenStackMachineTemplateList(src, r, nil)
234241
}
242+
243+
func Convert_v1alpha7_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec(in *OpenStackMachineSpec, out *infrav1.OpenStackMachineSpec, s apiconversion.Scope) error {
244+
err := autoConvert_v1alpha7_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec(in, out, s)
245+
if err != nil {
246+
return err
247+
}
248+
249+
imageFilter := infrav1.ImageFilter{}
250+
if in.Image != "" {
251+
imageFilter.Name = in.Image
252+
}
253+
if in.ImageUUID != "" {
254+
imageFilter.ID = in.ImageUUID
255+
}
256+
out.Image = imageFilter
257+
258+
return nil
259+
}
260+
261+
func Convert_v1alpha8_OpenStackMachineSpec_To_v1alpha7_OpenStackMachineSpec(in *infrav1.OpenStackMachineSpec, out *OpenStackMachineSpec, s apiconversion.Scope) error {
262+
err := autoConvert_v1alpha8_OpenStackMachineSpec_To_v1alpha7_OpenStackMachineSpec(in, out, s)
263+
if err != nil {
264+
return err
265+
}
266+
267+
if in.Image.Name != "" {
268+
out.Image = in.Image.Name
269+
}
270+
271+
if in.Image.ID != "" {
272+
out.ImageUUID = in.Image.ID
273+
}
274+
275+
return nil
276+
}

api/v1alpha7/conversion_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,38 @@ func TestFuzzyConversion(t *testing.T) {
6060
func(status *OpenStackClusterStatus, c fuzz.Continue) {
6161
c.FuzzNoCustom(status)
6262
},
63+
64+
func(v1alpha8Machine *infrav1.OpenStackMachine, c fuzz.Continue) {
65+
c.FuzzNoCustom(v1alpha8Machine)
66+
67+
// None of the following fields have ever been set in v1alpha7
68+
v1alpha8Machine.Spec.Image.Tags = []string{}
69+
},
70+
71+
func(v1alpha8MachineTemplate *infrav1.OpenStackMachineTemplate, c fuzz.Continue) {
72+
c.FuzzNoCustom(v1alpha8MachineTemplate)
73+
74+
// None of the following fields have ever been set in v1alpha7
75+
v1alpha8MachineTemplate.Spec.Template.Spec.Image.Tags = []string{}
76+
},
77+
78+
func(v1alpha8Cluster *infrav1.OpenStackCluster, c fuzz.Continue) {
79+
c.FuzzNoCustom(v1alpha8Cluster)
80+
81+
// None of the following fields have ever been set in v1alpha7
82+
if v1alpha8Cluster.Spec.Bastion != nil {
83+
v1alpha8Cluster.Spec.Bastion.Instance.Image.Tags = []string{}
84+
}
85+
},
86+
87+
func(v1alpha8ClusterTemplate *infrav1.OpenStackClusterTemplate, c fuzz.Continue) {
88+
c.FuzzNoCustom(v1alpha8ClusterTemplate)
89+
90+
// None of the following fields have ever been set in v1alpha7
91+
if v1alpha8ClusterTemplate.Spec.Template.Spec.Bastion != nil {
92+
v1alpha8ClusterTemplate.Spec.Template.Spec.Bastion.Instance.Image.Tags = []string{}
93+
}
94+
},
6395
}
6496
}
6597

@@ -84,42 +116,51 @@ func TestFuzzyConversion(t *testing.T) {
84116
Hub: &infrav1.OpenStackClusterTemplate{},
85117
Spoke: &OpenStackClusterTemplate{},
86118
HubAfterMutation: ignoreDataAnnotation,
119+
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
87120
})))
88121

89122
t.Run("for OpenStackClusterTemplate with mutate", runParallel(testhelpers.FuzzMutateTestFunc(testhelpers.FuzzMutateTestFuncInput{
90123
FuzzTestFuncInput: utilconversion.FuzzTestFuncInput{
91124
Hub: &infrav1.OpenStackClusterTemplate{},
92125
Spoke: &OpenStackClusterTemplate{},
93126
HubAfterMutation: ignoreDataAnnotation,
127+
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
94128
},
129+
MutateFuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
95130
})))
96131

97132
t.Run("for OpenStackMachine", runParallel(utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
98133
Hub: &infrav1.OpenStackMachine{},
99134
Spoke: &OpenStackMachine{},
100135
HubAfterMutation: ignoreDataAnnotation,
136+
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
101137
})))
102138

103139
t.Run("for OpenStackMachine with mutate", runParallel(testhelpers.FuzzMutateTestFunc(testhelpers.FuzzMutateTestFuncInput{
104140
FuzzTestFuncInput: utilconversion.FuzzTestFuncInput{
105141
Hub: &infrav1.OpenStackMachine{},
106142
Spoke: &OpenStackMachine{},
107143
HubAfterMutation: ignoreDataAnnotation,
144+
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
108145
},
146+
MutateFuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
109147
})))
110148

111149
t.Run("for OpenStackMachineTemplate", runParallel(utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{
112150
Hub: &infrav1.OpenStackMachineTemplate{},
113151
Spoke: &OpenStackMachineTemplate{},
114152
HubAfterMutation: ignoreDataAnnotation,
153+
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
115154
})))
116155

117156
t.Run("for OpenStackMachineTemplate with mutate", runParallel(testhelpers.FuzzMutateTestFunc(testhelpers.FuzzMutateTestFuncInput{
118157
FuzzTestFuncInput: utilconversion.FuzzTestFuncInput{
119158
Hub: &infrav1.OpenStackMachineTemplate{},
120159
Spoke: &OpenStackMachineTemplate{},
121160
HubAfterMutation: ignoreDataAnnotation,
161+
FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
122162
},
163+
MutateFuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs},
123164
})))
124165
}
125166

0 commit comments

Comments
 (0)