Skip to content

Commit 10c68f8

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 55ab11d commit 10c68f8

Some content is hidden

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

43 files changed

+472
-189
lines changed

api/v1alpha5/conversion.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,15 @@ func Convert_v1alpha5_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec(in *
247247
out.ServerGroup = &infrav1.ServerGroupFilter{}
248248
}
249249

250+
imageFilter := infrav1.ImageFilter{}
251+
if in.Image != "" {
252+
imageFilter.Name = in.Image
253+
}
254+
if in.ImageUUID != "" {
255+
imageFilter.ID = in.ImageUUID
256+
}
257+
out.Image = imageFilter
258+
250259
return nil
251260
}
252261

@@ -480,6 +489,14 @@ func Convert_v1alpha8_OpenStackMachineSpec_To_v1alpha5_OpenStackMachineSpec(in *
480489
out.ServerGroupID = in.ServerGroup.ID
481490
}
482491

492+
if in.Image.Name != "" {
493+
out.Image = in.Image.Name
494+
}
495+
496+
if in.Image.ID != "" {
497+
out.ImageUUID = in.Image.ID
498+
}
499+
483500
return nil
484501
}
485502

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,\"referencedResources\":{}}}",
82+
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"cloudName\":\"\",\"flavor\":\"\",\"image\":{}},\"status\":{\"ready\":false,\"referencedResources\":{}}}",
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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ func restorev1alpha8MachineSpec(previous *infrav1.OpenStackMachineSpec, dst *inf
6262
dst.Ports = previous.Ports
6363
dst.AdditionalBlockDevices = previous.AdditionalBlockDevices
6464
dst.ServerGroup = previous.ServerGroup
65+
dst.Image = previous.Image
6566
}
6667

6768
func restorev1alpha8Bastion(previous **infrav1.Bastion, dst **infrav1.Bastion) {
@@ -393,6 +394,15 @@ func Convert_v1alpha6_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec(in *
393394
out.ServerGroup = nil
394395
}
395396

397+
imageFilter := infrav1.ImageFilter{}
398+
if in.Image != "" {
399+
imageFilter.Name = in.Image
400+
}
401+
if in.ImageUUID != "" {
402+
imageFilter.ID = in.ImageUUID
403+
}
404+
out.Image = imageFilter
405+
396406
return nil
397407
}
398408

@@ -721,6 +731,14 @@ func Convert_v1alpha8_OpenStackMachineSpec_To_v1alpha6_OpenStackMachineSpec(in *
721731
out.ServerGroupID = in.ServerGroup.ID
722732
}
723733

734+
if in.Image.Name != "" {
735+
out.Image = in.Image.Name
736+
}
737+
738+
if in.Image.ID != "" {
739+
out.ImageUUID = in.Image.ID
740+
}
741+
724742
return nil
725743
}
726744

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: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ var v1alpha8OpenStackClusterRestorer = conversion.RestorerFor[*infrav1.OpenStack
6767

6868
func restorev1alpha8MachineSpec(previous *infrav1.OpenStackMachineSpec, dst *infrav1.OpenStackMachineSpec) {
6969
dst.ServerGroup = previous.ServerGroup
70+
dst.Image = previous.Image
7071
}
7172

7273
func restorev1alpha8Bastion(previous **infrav1.Bastion, dst **infrav1.Bastion) {
@@ -273,6 +274,14 @@ func Convert_v1alpha8_OpenStackMachineSpec_To_v1alpha7_OpenStackMachineSpec(in *
273274
out.ServerGroupID = in.ServerGroup.ID
274275
}
275276

277+
if in.Image.Name != "" {
278+
out.Image = in.Image.Name
279+
}
280+
281+
if in.Image.ID != "" {
282+
out.ImageUUID = in.Image.ID
283+
}
284+
276285
return nil
277286
}
278287

@@ -288,6 +297,15 @@ func Convert_v1alpha7_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec(in *
288297
out.ServerGroup = nil
289298
}
290299

300+
imageFilter := infrav1.ImageFilter{}
301+
if in.Image != "" {
302+
imageFilter.Name = in.Image
303+
}
304+
if in.ImageUUID != "" {
305+
imageFilter.ID = in.ImageUUID
306+
}
307+
out.Image = imageFilter
308+
291309
return nil
292310
}
293311

api/v1alpha7/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/v1alpha8/filter_convert.go

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

1919
import (
20+
"github.com/gophercloud/gophercloud/openstack/imageservice/v2/images"
2021
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers"
2122
securitygroups "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups"
2223
"github.com/gophercloud/gophercloud/openstack/networking/v2/networks"
@@ -79,3 +80,11 @@ func (routerFilter RouterFilter) ToListOpt() routers.ListOpts {
7980
NotTagsAny: routerFilter.NotTagsAny,
8081
}
8182
}
83+
84+
func (imageFilter ImageFilter) ToListOpt() images.ListOpts {
85+
return images.ListOpts{
86+
ID: imageFilter.ID,
87+
Name: imageFilter.Name,
88+
Tags: imageFilter.Tags,
89+
}
90+
}

api/v1alpha8/openstackcluster_webhook_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func TestOpenStackCluster_ValidateUpdate(t *testing.T) {
119119
Bastion: &Bastion{
120120
Instance: OpenStackMachineSpec{
121121
CloudName: "foobar",
122-
Image: "foobar",
122+
Image: ImageFilter{Name: "foobar"},
123123
Flavor: "minimal",
124124
},
125125
Enabled: true,
@@ -137,7 +137,7 @@ func TestOpenStackCluster_ValidateUpdate(t *testing.T) {
137137
Bastion: &Bastion{
138138
Instance: OpenStackMachineSpec{
139139
CloudName: "foobarbaz",
140-
Image: "foobarbaz",
140+
Image: ImageFilter{Name: "foobarbaz"},
141141
Flavor: "medium",
142142
},
143143
Enabled: true,

api/v1alpha8/openstackmachine_types.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,9 @@ type OpenStackMachineSpec struct {
4545
// The flavor reference for the flavor for your server instance.
4646
Flavor string `json:"flavor"`
4747

48-
// The name of the image to use for your server instance.
49-
// If the RootVolume is specified, this will be ignored and use rootVolume directly.
50-
Image string `json:"image,omitempty"`
51-
52-
// The uuid of the image to use for your server instance.
53-
// if it's empty, Image name will be used
54-
ImageUUID string `json:"imageUUID,omitempty"`
48+
// The image to use for your server instance.
49+
// If the rootVolume is specified, this will be used when creating the root volume.
50+
Image ImageFilter `json:"image,omitempty"`
5551

5652
// The ssh key to inject in the instance
5753
SSHKeyName string `json:"sshKeyName,omitempty"`

api/v1alpha8/openstackmachinetemplate_webhook_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestOpenStackMachineTemplate_ValidateUpdate(t *testing.T) {
4545
Template: OpenStackMachineTemplateResource{
4646
Spec: OpenStackMachineSpec{
4747
Flavor: "foo",
48-
Image: "bar",
48+
Image: ImageFilter{Name: "bar"},
4949
},
5050
},
5151
},
@@ -55,7 +55,7 @@ func TestOpenStackMachineTemplate_ValidateUpdate(t *testing.T) {
5555
Template: OpenStackMachineTemplateResource{
5656
Spec: OpenStackMachineSpec{
5757
Flavor: "foo",
58-
Image: "NewImage",
58+
Image: ImageFilter{Name: "NewImage"},
5959
},
6060
},
6161
},
@@ -70,7 +70,7 @@ func TestOpenStackMachineTemplate_ValidateUpdate(t *testing.T) {
7070
Template: OpenStackMachineTemplateResource{
7171
Spec: OpenStackMachineSpec{
7272
Flavor: "foo",
73-
Image: "bar",
73+
Image: ImageFilter{Name: "bar"},
7474
},
7575
},
7676
},
@@ -83,7 +83,7 @@ func TestOpenStackMachineTemplate_ValidateUpdate(t *testing.T) {
8383
Template: OpenStackMachineTemplateResource{
8484
Spec: OpenStackMachineSpec{
8585
Flavor: "foo",
86-
Image: "bar",
86+
Image: ImageFilter{Name: "bar"},
8787
},
8888
},
8989
},
@@ -100,7 +100,7 @@ func TestOpenStackMachineTemplate_ValidateUpdate(t *testing.T) {
100100
Template: OpenStackMachineTemplateResource{
101101
Spec: OpenStackMachineSpec{
102102
Flavor: "foo",
103-
Image: "bar",
103+
Image: ImageFilter{Name: "bar"},
104104
},
105105
},
106106
},
@@ -110,7 +110,7 @@ func TestOpenStackMachineTemplate_ValidateUpdate(t *testing.T) {
110110
Template: OpenStackMachineTemplateResource{
111111
Spec: OpenStackMachineSpec{
112112
Flavor: "foo",
113-
Image: "NewImage",
113+
Image: ImageFilter{Name: "NewImage"},
114114
},
115115
},
116116
},
@@ -125,7 +125,7 @@ func TestOpenStackMachineTemplate_ValidateUpdate(t *testing.T) {
125125
Template: OpenStackMachineTemplateResource{
126126
Spec: OpenStackMachineSpec{
127127
Flavor: "foo",
128-
Image: "bar",
128+
Image: ImageFilter{Name: "bar"},
129129
},
130130
},
131131
},
@@ -140,7 +140,7 @@ func TestOpenStackMachineTemplate_ValidateUpdate(t *testing.T) {
140140
Template: OpenStackMachineTemplateResource{
141141
Spec: OpenStackMachineSpec{
142142
Flavor: "foo",
143-
Image: "NewImage",
143+
Image: ImageFilter{Name: "NewImage"},
144144
},
145145
},
146146
},

api/v1alpha8/types.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ type OpenStackMachineTemplateResource struct {
2222
Spec OpenStackMachineSpec `json:"spec"`
2323
}
2424

25+
type ImageFilter struct {
26+
// The ID of the desired image. If this is provided, the other filters will be ignored.
27+
ID string `json:"id,omitempty"`
28+
// The name of the desired image. If specified, the combination of name and tags must return a single matching image or an error will be raised.
29+
Name string `json:"name,omitempty"`
30+
// The tags associated with the desired image. If specified, the combination of name and tags must return a single matching image or an error will be raised.
31+
Tags []string `json:"tags,omitempty"`
32+
}
33+
2534
type ExternalRouterIPParam struct {
2635
// The FixedIP in the corresponding subnet
2736
FixedIP string `json:"fixedIP,omitempty"`
@@ -368,6 +377,10 @@ type ReferencedMachineResources struct {
368377
// ServerGroupID is the ID of the server group the machine should be added to and is calculated based on ServerGroupFilter.
369378
// +optional
370379
ServerGroupID string `json:"serverGroupID,omitempty"`
380+
381+
// ImageID is the ID of the image to use for the machine and is calculated based on ImageFilter.
382+
// +optional
383+
ImageID string `json:"imageID,omitempty"`
371384
}
372385

373386
// ValueSpec represents a single value_spec key-value pair.

api/v1alpha8/zz_generated.deepcopy.go

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

0 commit comments

Comments
 (0)