Skip to content

✨ Change API for OpenStackMachine.Spec.Image #1796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions api/v1alpha5/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,15 @@ func Convert_v1alpha5_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec(in *
out.ServerGroup = &infrav1.ServerGroupFilter{}
}

imageFilter := infrav1.ImageFilter{}
if in.Image != "" {
imageFilter.Name = in.Image
}
if in.ImageUUID != "" {
imageFilter.ID = in.ImageUUID
}
out.Image = imageFilter

return nil
}

Expand Down Expand Up @@ -480,6 +489,14 @@ func Convert_v1alpha8_OpenStackMachineSpec_To_v1alpha5_OpenStackMachineSpec(in *
out.ServerGroupID = in.ServerGroup.ID
}

if in.Image.Name != "" {
out.Image = in.Image.Name
}

if in.Image.ID != "" {
out.ImageUUID = in.Image.ID
}

return nil
}

Expand Down
4 changes: 2 additions & 2 deletions api/v1alpha5/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestConvertFrom(t *testing.T) {
Spec: OpenStackMachineSpec{},
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"cloudName\":\"\",\"flavor\":\"\"},\"status\":{\"ready\":false,\"referencedResources\":{}}}",
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"cloudName\":\"\",\"flavor\":\"\",\"image\":{}},\"status\":{\"ready\":false,\"referencedResources\":{}}}",
},
},
},
Expand All @@ -94,7 +94,7 @@ func TestConvertFrom(t *testing.T) {
Spec: OpenStackMachineTemplateSpec{},
ObjectMeta: metav1.ObjectMeta{
Annotations: map[string]string{
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"template\":{\"spec\":{\"cloudName\":\"\",\"flavor\":\"\"}}}}",
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"template\":{\"spec\":{\"cloudName\":\"\",\"flavor\":\"\",\"image\":{}}}}}",
},
},
},
Expand Down
7 changes: 3 additions & 4 deletions api/v1alpha5/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions api/v1alpha6/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func restorev1alpha8MachineSpec(previous *infrav1.OpenStackMachineSpec, dst *inf
dst.Ports = previous.Ports
dst.AdditionalBlockDevices = previous.AdditionalBlockDevices
dst.ServerGroup = previous.ServerGroup
dst.Image = previous.Image
}

func restorev1alpha8Bastion(previous **infrav1.Bastion, dst **infrav1.Bastion) {
Expand Down Expand Up @@ -393,6 +394,15 @@ func Convert_v1alpha6_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec(in *
out.ServerGroup = nil
}

imageFilter := infrav1.ImageFilter{}
if in.Image != "" {
imageFilter.Name = in.Image
}
if in.ImageUUID != "" {
imageFilter.ID = in.ImageUUID
}
out.Image = imageFilter

return nil
}

Expand Down Expand Up @@ -721,6 +731,14 @@ func Convert_v1alpha8_OpenStackMachineSpec_To_v1alpha6_OpenStackMachineSpec(in *
out.ServerGroupID = in.ServerGroup.ID
}

if in.Image.Name != "" {
out.Image = in.Image.Name
}

if in.Image.ID != "" {
out.ImageUUID = in.Image.ID
}

return nil
}

Expand Down
7 changes: 3 additions & 4 deletions api/v1alpha6/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions api/v1alpha7/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ var v1alpha8OpenStackClusterRestorer = conversion.RestorerFor[*infrav1.OpenStack

func restorev1alpha8MachineSpec(previous *infrav1.OpenStackMachineSpec, dst *infrav1.OpenStackMachineSpec) {
dst.ServerGroup = previous.ServerGroup
dst.Image = previous.Image
}

func restorev1alpha8Bastion(previous **infrav1.Bastion, dst **infrav1.Bastion) {
Expand Down Expand Up @@ -273,6 +274,14 @@ func Convert_v1alpha8_OpenStackMachineSpec_To_v1alpha7_OpenStackMachineSpec(in *
out.ServerGroupID = in.ServerGroup.ID
}

if in.Image.Name != "" {
out.Image = in.Image.Name
}

if in.Image.ID != "" {
out.ImageUUID = in.Image.ID
}

return nil
}

Expand All @@ -288,6 +297,15 @@ func Convert_v1alpha7_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec(in *
out.ServerGroup = nil
}

imageFilter := infrav1.ImageFilter{}
if in.Image != "" {
imageFilter.Name = in.Image
}
if in.ImageUUID != "" {
imageFilter.ID = in.ImageUUID
}
out.Image = imageFilter

return nil
}

Expand Down
7 changes: 3 additions & 4 deletions api/v1alpha7/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions api/v1alpha8/filter_convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1alpha8

import (
"github.com/gophercloud/gophercloud/openstack/imageservice/v2/images"
"github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/layer3/routers"
securitygroups "github.com/gophercloud/gophercloud/openstack/networking/v2/extensions/security/groups"
"github.com/gophercloud/gophercloud/openstack/networking/v2/networks"
Expand Down Expand Up @@ -79,3 +80,11 @@ func (routerFilter RouterFilter) ToListOpt() routers.ListOpts {
NotTagsAny: routerFilter.NotTagsAny,
}
}

func (imageFilter ImageFilter) ToListOpt() images.ListOpts {
return images.ListOpts{
ID: imageFilter.ID,
Name: imageFilter.Name,
Tags: imageFilter.Tags,
}
}
4 changes: 2 additions & 2 deletions api/v1alpha8/openstackcluster_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func TestOpenStackCluster_ValidateUpdate(t *testing.T) {
Bastion: &Bastion{
Instance: OpenStackMachineSpec{
CloudName: "foobar",
Image: "foobar",
Image: ImageFilter{Name: "foobar"},
Flavor: "minimal",
},
Enabled: true,
Expand All @@ -137,7 +137,7 @@ func TestOpenStackCluster_ValidateUpdate(t *testing.T) {
Bastion: &Bastion{
Instance: OpenStackMachineSpec{
CloudName: "foobarbaz",
Image: "foobarbaz",
Image: ImageFilter{Name: "foobarbaz"},
Flavor: "medium",
},
Enabled: true,
Expand Down
10 changes: 3 additions & 7 deletions api/v1alpha8/openstackmachine_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,9 @@ type OpenStackMachineSpec struct {
// The flavor reference for the flavor for your server instance.
Flavor string `json:"flavor"`

// The name of the image to use for your server instance.
// If the RootVolume is specified, this will be ignored and use rootVolume directly.
Image string `json:"image,omitempty"`

// The uuid of the image to use for your server instance.
// if it's empty, Image name will be used
ImageUUID string `json:"imageUUID,omitempty"`
// The image to use for your server instance.
// If the rootVolume is specified, this will be used when creating the root volume.
Image ImageFilter `json:"image,omitempty"`

// The ssh key to inject in the instance
SSHKeyName string `json:"sshKeyName,omitempty"`
Expand Down
16 changes: 8 additions & 8 deletions api/v1alpha8/openstackmachinetemplate_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestOpenStackMachineTemplate_ValidateUpdate(t *testing.T) {
Template: OpenStackMachineTemplateResource{
Spec: OpenStackMachineSpec{
Flavor: "foo",
Image: "bar",
Image: ImageFilter{Name: "bar"},
},
},
},
Expand All @@ -55,7 +55,7 @@ func TestOpenStackMachineTemplate_ValidateUpdate(t *testing.T) {
Template: OpenStackMachineTemplateResource{
Spec: OpenStackMachineSpec{
Flavor: "foo",
Image: "NewImage",
Image: ImageFilter{Name: "NewImage"},
},
},
},
Expand All @@ -70,7 +70,7 @@ func TestOpenStackMachineTemplate_ValidateUpdate(t *testing.T) {
Template: OpenStackMachineTemplateResource{
Spec: OpenStackMachineSpec{
Flavor: "foo",
Image: "bar",
Image: ImageFilter{Name: "bar"},
},
},
},
Expand All @@ -83,7 +83,7 @@ func TestOpenStackMachineTemplate_ValidateUpdate(t *testing.T) {
Template: OpenStackMachineTemplateResource{
Spec: OpenStackMachineSpec{
Flavor: "foo",
Image: "bar",
Image: ImageFilter{Name: "bar"},
},
},
},
Expand All @@ -100,7 +100,7 @@ func TestOpenStackMachineTemplate_ValidateUpdate(t *testing.T) {
Template: OpenStackMachineTemplateResource{
Spec: OpenStackMachineSpec{
Flavor: "foo",
Image: "bar",
Image: ImageFilter{Name: "bar"},
},
},
},
Expand All @@ -110,7 +110,7 @@ func TestOpenStackMachineTemplate_ValidateUpdate(t *testing.T) {
Template: OpenStackMachineTemplateResource{
Spec: OpenStackMachineSpec{
Flavor: "foo",
Image: "NewImage",
Image: ImageFilter{Name: "NewImage"},
},
},
},
Expand All @@ -125,7 +125,7 @@ func TestOpenStackMachineTemplate_ValidateUpdate(t *testing.T) {
Template: OpenStackMachineTemplateResource{
Spec: OpenStackMachineSpec{
Flavor: "foo",
Image: "bar",
Image: ImageFilter{Name: "bar"},
},
},
},
Expand All @@ -140,7 +140,7 @@ func TestOpenStackMachineTemplate_ValidateUpdate(t *testing.T) {
Template: OpenStackMachineTemplateResource{
Spec: OpenStackMachineSpec{
Flavor: "foo",
Image: "NewImage",
Image: ImageFilter{Name: "NewImage"},
},
},
},
Expand Down
13 changes: 13 additions & 0 deletions api/v1alpha8/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ type OpenStackMachineTemplateResource struct {
Spec OpenStackMachineSpec `json:"spec"`
}

type ImageFilter struct {
// The ID of the desired image. If this is provided, the other filters will be ignored.
ID string `json:"id,omitempty"`
// 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.
Name string `json:"name,omitempty"`
// 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.
Tags []string `json:"tags,omitempty"`
}

type ExternalRouterIPParam struct {
// The FixedIP in the corresponding subnet
FixedIP string `json:"fixedIP,omitempty"`
Expand Down Expand Up @@ -371,6 +380,10 @@ type ReferencedMachineResources struct {
// ServerGroupID is the ID of the server group the machine should be added to and is calculated based on ServerGroupFilter.
// +optional
ServerGroupID string `json:"serverGroupID,omitempty"`

// ImageID is the ID of the image to use for the machine and is calculated based on ImageFilter.
// +optional
ImageID string `json:"imageID,omitempty"`
}

// ValueSpec represents a single value_spec key-value pair.
Expand Down
21 changes: 21 additions & 0 deletions api/v1alpha8/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading