diff --git a/api/v1alpha5/conversion.go b/api/v1alpha5/conversion.go index 77e39fa2eb..434312e887 100644 --- a/api/v1alpha5/conversion.go +++ b/api/v1alpha5/conversion.go @@ -213,7 +213,21 @@ func Convert_v1alpha8_PortOpts_To_v1alpha5_PortOpts(in *infrav1.PortOpts, out *P } func Convert_v1alpha5_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec(in *OpenStackMachineSpec, out *infrav1.OpenStackMachineSpec, s conversion.Scope) error { - return autoConvert_v1alpha5_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec(in, out, s) + err := autoConvert_v1alpha5_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec(in, out, s) + if err != nil { + return err + } + + imageFilter := infrav1.ImageFilter{} + if in.Image != "" { + imageFilter.Name = in.Image + } + if in.ImageUUID != "" { + imageFilter.ID = in.ImageUUID + } + out.Image = imageFilter + + return nil } 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( } func Convert_v1alpha8_OpenStackMachineSpec_To_v1alpha5_OpenStackMachineSpec(in *infrav1.OpenStackMachineSpec, out *OpenStackMachineSpec, s conversion.Scope) error { - return autoConvert_v1alpha8_OpenStackMachineSpec_To_v1alpha5_OpenStackMachineSpec(in, out, s) + err := autoConvert_v1alpha8_OpenStackMachineSpec_To_v1alpha5_OpenStackMachineSpec(in, out, s) + if err != nil { + return err + } + + if in.Image.Name != "" { + out.Image = in.Image.Name + } + + if in.Image.ID != "" { + out.ImageUUID = in.Image.ID + } + + return nil } diff --git a/api/v1alpha5/conversion_test.go b/api/v1alpha5/conversion_test.go index 95f83052dd..cf1a0afe0f 100644 --- a/api/v1alpha5/conversion_test.go +++ b/api/v1alpha5/conversion_test.go @@ -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}}", + "cluster.x-k8s.io/conversion-data": "{\"spec\":{\"cloudName\":\"\",\"flavor\":\"\",\"image\":{}},\"status\":{\"ready\":false}}", }, }, }, @@ -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\":{}}}}}", }, }, }, diff --git a/api/v1alpha5/zz_generated.conversion.go b/api/v1alpha5/zz_generated.conversion.go index 5ef62e512e..cff0137599 100644 --- a/api/v1alpha5/zz_generated.conversion.go +++ b/api/v1alpha5/zz_generated.conversion.go @@ -1061,8 +1061,8 @@ func autoConvert_v1alpha5_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec( out.InstanceID = (*string)(unsafe.Pointer(in.InstanceID)) out.CloudName = in.CloudName out.Flavor = in.Flavor - out.Image = in.Image - out.ImageUUID = in.ImageUUID + // WARNING: in.Image requires manual conversion: inconvertible types (string vs sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha8.ImageFilter) + // WARNING: in.ImageUUID requires manual conversion: does not exist in peer-type out.SSHKeyName = in.SSHKeyName // WARNING: in.Networks requires manual conversion: does not exist in peer-type if in.Ports != nil { @@ -1104,8 +1104,7 @@ func autoConvert_v1alpha8_OpenStackMachineSpec_To_v1alpha5_OpenStackMachineSpec( out.InstanceID = (*string)(unsafe.Pointer(in.InstanceID)) out.CloudName = in.CloudName out.Flavor = in.Flavor - out.Image = in.Image - out.ImageUUID = in.ImageUUID + // WARNING: in.Image requires manual conversion: inconvertible types (sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha8.ImageFilter vs string) out.SSHKeyName = in.SSHKeyName if in.Ports != nil { in, out := &in.Ports, &out.Ports diff --git a/api/v1alpha6/conversion.go b/api/v1alpha6/conversion.go index 66f77e3076..7f520f3c16 100644 --- a/api/v1alpha6/conversion.go +++ b/api/v1alpha6/conversion.go @@ -362,6 +362,33 @@ func Convert_v1alpha6_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec(in * // Networks were previously created first, so need to come before ports out.Ports = append(ports, out.Ports...) } + + imageFilter := infrav1.ImageFilter{} + if in.Image != "" { + imageFilter.Name = in.Image + } + if in.ImageUUID != "" { + imageFilter.ID = in.ImageUUID + } + out.Image = imageFilter + + return nil +} + +func Convert_v1alpha8_OpenStackMachineSpec_To_v1alpha6_OpenStackMachineSpec(in *infrav1.OpenStackMachineSpec, out *OpenStackMachineSpec, s apiconversion.Scope) error { + err := autoConvert_v1alpha8_OpenStackMachineSpec_To_v1alpha6_OpenStackMachineSpec(in, out, s) + if err != nil { + return err + } + + if in.Image.Name != "" { + out.Image = in.Image.Name + } + + if in.Image.ID != "" { + out.ImageUUID = in.Image.ID + } + return nil } @@ -655,7 +682,3 @@ func Convert_v1alpha6_OpenStackClusterStatus_To_v1alpha8_OpenStackClusterStatus( return nil } - -func Convert_v1alpha8_OpenStackMachineSpec_To_v1alpha6_OpenStackMachineSpec(in *infrav1.OpenStackMachineSpec, out *OpenStackMachineSpec, s apiconversion.Scope) error { - return autoConvert_v1alpha8_OpenStackMachineSpec_To_v1alpha6_OpenStackMachineSpec(in, out, s) -} diff --git a/api/v1alpha6/conversion_test.go b/api/v1alpha6/conversion_test.go index 7f67ad9ef9..83c5adb10f 100644 --- a/api/v1alpha6/conversion_test.go +++ b/api/v1alpha6/conversion_test.go @@ -88,6 +88,38 @@ func TestFuzzyConversion(t *testing.T) { status.ExternalNetwork.APIServerLoadBalancer = nil } }, + + func(v1alpha8Machine *infrav1.OpenStackMachine, c fuzz.Continue) { + c.FuzzNoCustom(v1alpha8Machine) + + // None of the following fields have ever been set in v1alpha6 + v1alpha8Machine.Spec.Image.Tags = []string{} + }, + + func(v1alpha8MachineTemplate *infrav1.OpenStackMachineTemplate, c fuzz.Continue) { + c.FuzzNoCustom(v1alpha8MachineTemplate) + + // None of the following fields have ever been set in v1alpha6 + v1alpha8MachineTemplate.Spec.Template.Spec.Image.Tags = []string{} + }, + + func(v1alpha8Cluster *infrav1.OpenStackCluster, c fuzz.Continue) { + c.FuzzNoCustom(v1alpha8Cluster) + + // None of the following fields have ever been set in v1alpha6 + if v1alpha8Cluster.Spec.Bastion != nil { + v1alpha8Cluster.Spec.Bastion.Instance.Image.Tags = []string{} + } + }, + + func(v1alpha8ClusterTemplate *infrav1.OpenStackClusterTemplate, c fuzz.Continue) { + c.FuzzNoCustom(v1alpha8ClusterTemplate) + + // None of the following fields have ever been set in v1alpha6 + if v1alpha8ClusterTemplate.Spec.Template.Spec.Bastion != nil { + v1alpha8ClusterTemplate.Spec.Template.Spec.Bastion.Instance.Image.Tags = []string{} + } + }, } } @@ -112,6 +144,7 @@ func TestFuzzyConversion(t *testing.T) { Hub: &infrav1.OpenStackClusterTemplate{}, Spoke: &OpenStackClusterTemplate{}, HubAfterMutation: ignoreDataAnnotation, + FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs}, }))) t.Run("for OpenStackClusterTemplate with mutate", runParallel(testhelpers.FuzzMutateTestFunc(testhelpers.FuzzMutateTestFuncInput{ @@ -120,12 +153,14 @@ func TestFuzzyConversion(t *testing.T) { Spoke: &OpenStackClusterTemplate{}, HubAfterMutation: ignoreDataAnnotation, }, + MutateFuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs}, }))) t.Run("for OpenStackMachine", runParallel(utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{ Hub: &infrav1.OpenStackMachine{}, Spoke: &OpenStackMachine{}, HubAfterMutation: ignoreDataAnnotation, + FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs}, }))) t.Run("for OpenStackMachine with mutate", runParallel(testhelpers.FuzzMutateTestFunc(testhelpers.FuzzMutateTestFuncInput{ @@ -133,13 +168,16 @@ func TestFuzzyConversion(t *testing.T) { Hub: &infrav1.OpenStackMachine{}, Spoke: &OpenStackMachine{}, HubAfterMutation: ignoreDataAnnotation, + FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs}, }, + MutateFuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs}, }))) t.Run("for OpenStackMachineTemplate", runParallel(utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{ Hub: &infrav1.OpenStackMachineTemplate{}, Spoke: &OpenStackMachineTemplate{}, HubAfterMutation: ignoreDataAnnotation, + FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs}, }))) t.Run("for OpenStackMachineTemplate with mutate", runParallel(testhelpers.FuzzMutateTestFunc(testhelpers.FuzzMutateTestFuncInput{ @@ -147,7 +185,9 @@ func TestFuzzyConversion(t *testing.T) { Hub: &infrav1.OpenStackMachineTemplate{}, Spoke: &OpenStackMachineTemplate{}, HubAfterMutation: ignoreDataAnnotation, + FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs}, }, + MutateFuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs}, }))) } diff --git a/api/v1alpha6/zz_generated.conversion.go b/api/v1alpha6/zz_generated.conversion.go index ec1a8020f7..ac6eb13876 100644 --- a/api/v1alpha6/zz_generated.conversion.go +++ b/api/v1alpha6/zz_generated.conversion.go @@ -1084,8 +1084,8 @@ func autoConvert_v1alpha6_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec( out.InstanceID = (*string)(unsafe.Pointer(in.InstanceID)) out.CloudName = in.CloudName out.Flavor = in.Flavor - out.Image = in.Image - out.ImageUUID = in.ImageUUID + // WARNING: in.Image requires manual conversion: inconvertible types (string vs sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha8.ImageFilter) + // WARNING: in.ImageUUID requires manual conversion: does not exist in peer-type out.SSHKeyName = in.SSHKeyName // WARNING: in.Networks requires manual conversion: does not exist in peer-type if in.Ports != nil { @@ -1127,8 +1127,7 @@ func autoConvert_v1alpha8_OpenStackMachineSpec_To_v1alpha6_OpenStackMachineSpec( out.InstanceID = (*string)(unsafe.Pointer(in.InstanceID)) out.CloudName = in.CloudName out.Flavor = in.Flavor - out.Image = in.Image - out.ImageUUID = in.ImageUUID + // WARNING: in.Image requires manual conversion: inconvertible types (sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha8.ImageFilter vs string) out.SSHKeyName = in.SSHKeyName if in.Ports != nil { in, out := &in.Ports, &out.Ports diff --git a/api/v1alpha7/conversion.go b/api/v1alpha7/conversion.go index 6b17160fdf..7c0f1ec465 100644 --- a/api/v1alpha7/conversion.go +++ b/api/v1alpha7/conversion.go @@ -17,6 +17,7 @@ limitations under the License. package v1alpha7 import ( + apiconversion "k8s.io/apimachinery/pkg/conversion" ctrlconversion "sigs.k8s.io/controller-runtime/pkg/conversion" infrav1 "sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha8" @@ -25,6 +26,10 @@ import ( var _ ctrlconversion.Convertible = &OpenStackCluster{} +func restorev1alpha8MachineSpec(previous *infrav1.OpenStackMachineSpec, dst *infrav1.OpenStackMachineSpec) { + dst.Image = previous.Image +} + var v1alpha7OpenStackClusterRestorer = conversion.RestorerFor[*OpenStackCluster]{ "spec": conversion.HashedFieldRestorer[*OpenStackCluster, OpenStackClusterSpec]{ GetField: func(c *OpenStackCluster) *OpenStackClusterSpec { @@ -144,6 +149,7 @@ var v1alpha8OpenStackMachineRestorer = conversion.RestorerFor[*infrav1.OpenStack GetField: func(c *infrav1.OpenStackMachine) *infrav1.OpenStackMachineSpec { return &c.Spec }, + RestoreField: restorev1alpha8MachineSpec, }, } @@ -196,6 +202,7 @@ var v1alpha8OpenStackMachineTemplateRestorer = conversion.RestorerFor[*infrav1.O GetField: func(c *infrav1.OpenStackMachineTemplate) *infrav1.OpenStackMachineSpec { return &c.Spec.Template.Spec }, + RestoreField: restorev1alpha8MachineSpec, }, } @@ -232,3 +239,38 @@ func (r *OpenStackMachineTemplateList) ConvertFrom(srcRaw ctrlconversion.Hub) er src := srcRaw.(*infrav1.OpenStackMachineTemplateList) return Convert_v1alpha8_OpenStackMachineTemplateList_To_v1alpha7_OpenStackMachineTemplateList(src, r, nil) } + +func Convert_v1alpha7_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec(in *OpenStackMachineSpec, out *infrav1.OpenStackMachineSpec, s apiconversion.Scope) error { + err := autoConvert_v1alpha7_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec(in, out, s) + if err != nil { + return err + } + + imageFilter := infrav1.ImageFilter{} + if in.Image != "" { + imageFilter.Name = in.Image + } + if in.ImageUUID != "" { + imageFilter.ID = in.ImageUUID + } + out.Image = imageFilter + + return nil +} + +func Convert_v1alpha8_OpenStackMachineSpec_To_v1alpha7_OpenStackMachineSpec(in *infrav1.OpenStackMachineSpec, out *OpenStackMachineSpec, s apiconversion.Scope) error { + err := autoConvert_v1alpha8_OpenStackMachineSpec_To_v1alpha7_OpenStackMachineSpec(in, out, s) + if err != nil { + return err + } + + if in.Image.Name != "" { + out.Image = in.Image.Name + } + + if in.Image.ID != "" { + out.ImageUUID = in.Image.ID + } + + return nil +} diff --git a/api/v1alpha7/conversion_test.go b/api/v1alpha7/conversion_test.go index ab032f20ff..5b335a1170 100644 --- a/api/v1alpha7/conversion_test.go +++ b/api/v1alpha7/conversion_test.go @@ -60,6 +60,38 @@ func TestFuzzyConversion(t *testing.T) { func(status *OpenStackClusterStatus, c fuzz.Continue) { c.FuzzNoCustom(status) }, + + func(v1alpha8Machine *infrav1.OpenStackMachine, c fuzz.Continue) { + c.FuzzNoCustom(v1alpha8Machine) + + // None of the following fields have ever been set in v1alpha7 + v1alpha8Machine.Spec.Image.Tags = []string{} + }, + + func(v1alpha8MachineTemplate *infrav1.OpenStackMachineTemplate, c fuzz.Continue) { + c.FuzzNoCustom(v1alpha8MachineTemplate) + + // None of the following fields have ever been set in v1alpha7 + v1alpha8MachineTemplate.Spec.Template.Spec.Image.Tags = []string{} + }, + + func(v1alpha8Cluster *infrav1.OpenStackCluster, c fuzz.Continue) { + c.FuzzNoCustom(v1alpha8Cluster) + + // None of the following fields have ever been set in v1alpha7 + if v1alpha8Cluster.Spec.Bastion != nil { + v1alpha8Cluster.Spec.Bastion.Instance.Image.Tags = []string{} + } + }, + + func(v1alpha8ClusterTemplate *infrav1.OpenStackClusterTemplate, c fuzz.Continue) { + c.FuzzNoCustom(v1alpha8ClusterTemplate) + + // None of the following fields have ever been set in v1alpha7 + if v1alpha8ClusterTemplate.Spec.Template.Spec.Bastion != nil { + v1alpha8ClusterTemplate.Spec.Template.Spec.Bastion.Instance.Image.Tags = []string{} + } + }, } } @@ -84,6 +116,7 @@ func TestFuzzyConversion(t *testing.T) { Hub: &infrav1.OpenStackClusterTemplate{}, Spoke: &OpenStackClusterTemplate{}, HubAfterMutation: ignoreDataAnnotation, + FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs}, }))) t.Run("for OpenStackClusterTemplate with mutate", runParallel(testhelpers.FuzzMutateTestFunc(testhelpers.FuzzMutateTestFuncInput{ @@ -91,13 +124,16 @@ func TestFuzzyConversion(t *testing.T) { Hub: &infrav1.OpenStackClusterTemplate{}, Spoke: &OpenStackClusterTemplate{}, HubAfterMutation: ignoreDataAnnotation, + FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs}, }, + MutateFuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs}, }))) t.Run("for OpenStackMachine", runParallel(utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{ Hub: &infrav1.OpenStackMachine{}, Spoke: &OpenStackMachine{}, HubAfterMutation: ignoreDataAnnotation, + FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs}, }))) t.Run("for OpenStackMachine with mutate", runParallel(testhelpers.FuzzMutateTestFunc(testhelpers.FuzzMutateTestFuncInput{ @@ -105,13 +141,16 @@ func TestFuzzyConversion(t *testing.T) { Hub: &infrav1.OpenStackMachine{}, Spoke: &OpenStackMachine{}, HubAfterMutation: ignoreDataAnnotation, + FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs}, }, + MutateFuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs}, }))) t.Run("for OpenStackMachineTemplate", runParallel(utilconversion.FuzzTestFunc(utilconversion.FuzzTestFuncInput{ Hub: &infrav1.OpenStackMachineTemplate{}, Spoke: &OpenStackMachineTemplate{}, HubAfterMutation: ignoreDataAnnotation, + FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs}, }))) t.Run("for OpenStackMachineTemplate with mutate", runParallel(testhelpers.FuzzMutateTestFunc(testhelpers.FuzzMutateTestFuncInput{ @@ -119,7 +158,9 @@ func TestFuzzyConversion(t *testing.T) { Hub: &infrav1.OpenStackMachineTemplate{}, Spoke: &OpenStackMachineTemplate{}, HubAfterMutation: ignoreDataAnnotation, + FuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs}, }, + MutateFuzzerFuncs: []fuzzer.FuzzerFuncs{fuzzerFuncs}, }))) } diff --git a/api/v1alpha7/zz_generated.conversion.go b/api/v1alpha7/zz_generated.conversion.go index 2d4a574a69..4bf07feaf2 100644 --- a/api/v1alpha7/zz_generated.conversion.go +++ b/api/v1alpha7/zz_generated.conversion.go @@ -289,16 +289,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*OpenStackMachineSpec)(nil), (*v1alpha8.OpenStackMachineSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha7_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec(a.(*OpenStackMachineSpec), b.(*v1alpha8.OpenStackMachineSpec), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*v1alpha8.OpenStackMachineSpec)(nil), (*OpenStackMachineSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha8_OpenStackMachineSpec_To_v1alpha7_OpenStackMachineSpec(a.(*v1alpha8.OpenStackMachineSpec), b.(*OpenStackMachineSpec), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*OpenStackMachineStatus)(nil), (*v1alpha8.OpenStackMachineStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha7_OpenStackMachineStatus_To_v1alpha8_OpenStackMachineStatus(a.(*OpenStackMachineStatus), b.(*v1alpha8.OpenStackMachineStatus), scope) }); err != nil { @@ -449,6 +439,16 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*OpenStackMachineSpec)(nil), (*v1alpha8.OpenStackMachineSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha7_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec(a.(*OpenStackMachineSpec), b.(*v1alpha8.OpenStackMachineSpec), scope) + }); err != nil { + return err + } + if err := s.AddConversionFunc((*v1alpha8.OpenStackMachineSpec)(nil), (*OpenStackMachineSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha8_OpenStackMachineSpec_To_v1alpha7_OpenStackMachineSpec(a.(*v1alpha8.OpenStackMachineSpec), b.(*OpenStackMachineSpec), scope) + }); err != nil { + return err + } return nil } @@ -848,7 +848,17 @@ func Convert_v1alpha8_OpenStackCluster_To_v1alpha7_OpenStackCluster(in *v1alpha8 func autoConvert_v1alpha7_OpenStackClusterList_To_v1alpha8_OpenStackClusterList(in *OpenStackClusterList, out *v1alpha8.OpenStackClusterList, s conversion.Scope) error { out.ListMeta = in.ListMeta - out.Items = *(*[]v1alpha8.OpenStackCluster)(unsafe.Pointer(&in.Items)) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]v1alpha8.OpenStackCluster, len(*in)) + for i := range *in { + if err := Convert_v1alpha7_OpenStackCluster_To_v1alpha8_OpenStackCluster(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } return nil } @@ -859,7 +869,17 @@ func Convert_v1alpha7_OpenStackClusterList_To_v1alpha8_OpenStackClusterList(in * func autoConvert_v1alpha8_OpenStackClusterList_To_v1alpha7_OpenStackClusterList(in *v1alpha8.OpenStackClusterList, out *OpenStackClusterList, s conversion.Scope) error { out.ListMeta = in.ListMeta - out.Items = *(*[]OpenStackCluster)(unsafe.Pointer(&in.Items)) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]OpenStackCluster, len(*in)) + for i := range *in { + if err := Convert_v1alpha8_OpenStackCluster_To_v1alpha7_OpenStackCluster(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } return nil } @@ -896,7 +916,15 @@ func autoConvert_v1alpha7_OpenStackClusterSpec_To_v1alpha8_OpenStackClusterSpec( out.ControlPlaneEndpoint = in.ControlPlaneEndpoint out.ControlPlaneAvailabilityZones = *(*[]string)(unsafe.Pointer(&in.ControlPlaneAvailabilityZones)) out.ControlPlaneOmitAvailabilityZone = in.ControlPlaneOmitAvailabilityZone - out.Bastion = (*v1alpha8.Bastion)(unsafe.Pointer(in.Bastion)) + if in.Bastion != nil { + in, out := &in.Bastion, &out.Bastion + *out = new(v1alpha8.Bastion) + if err := Convert_v1alpha7_Bastion_To_v1alpha8_Bastion(*in, *out, s); err != nil { + return err + } + } else { + out.Bastion = nil + } out.IdentityRef = (*v1alpha8.OpenStackIdentityReference)(unsafe.Pointer(in.IdentityRef)) return nil } @@ -934,7 +962,15 @@ func autoConvert_v1alpha8_OpenStackClusterSpec_To_v1alpha7_OpenStackClusterSpec( out.ControlPlaneEndpoint = in.ControlPlaneEndpoint out.ControlPlaneAvailabilityZones = *(*[]string)(unsafe.Pointer(&in.ControlPlaneAvailabilityZones)) out.ControlPlaneOmitAvailabilityZone = in.ControlPlaneOmitAvailabilityZone - out.Bastion = (*Bastion)(unsafe.Pointer(in.Bastion)) + if in.Bastion != nil { + in, out := &in.Bastion, &out.Bastion + *out = new(Bastion) + if err := Convert_v1alpha8_Bastion_To_v1alpha7_Bastion(*in, *out, s); err != nil { + return err + } + } else { + out.Bastion = nil + } out.IdentityRef = (*OpenStackIdentityReference)(unsafe.Pointer(in.IdentityRef)) return nil } @@ -1014,7 +1050,17 @@ func Convert_v1alpha8_OpenStackClusterTemplate_To_v1alpha7_OpenStackClusterTempl func autoConvert_v1alpha7_OpenStackClusterTemplateList_To_v1alpha8_OpenStackClusterTemplateList(in *OpenStackClusterTemplateList, out *v1alpha8.OpenStackClusterTemplateList, s conversion.Scope) error { out.ListMeta = in.ListMeta - out.Items = *(*[]v1alpha8.OpenStackClusterTemplate)(unsafe.Pointer(&in.Items)) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]v1alpha8.OpenStackClusterTemplate, len(*in)) + for i := range *in { + if err := Convert_v1alpha7_OpenStackClusterTemplate_To_v1alpha8_OpenStackClusterTemplate(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } return nil } @@ -1025,7 +1071,17 @@ func Convert_v1alpha7_OpenStackClusterTemplateList_To_v1alpha8_OpenStackClusterT func autoConvert_v1alpha8_OpenStackClusterTemplateList_To_v1alpha7_OpenStackClusterTemplateList(in *v1alpha8.OpenStackClusterTemplateList, out *OpenStackClusterTemplateList, s conversion.Scope) error { out.ListMeta = in.ListMeta - out.Items = *(*[]OpenStackClusterTemplate)(unsafe.Pointer(&in.Items)) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]OpenStackClusterTemplate, len(*in)) + for i := range *in { + if err := Convert_v1alpha8_OpenStackClusterTemplate_To_v1alpha7_OpenStackClusterTemplate(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } return nil } @@ -1138,7 +1194,17 @@ func Convert_v1alpha8_OpenStackMachine_To_v1alpha7_OpenStackMachine(in *v1alpha8 func autoConvert_v1alpha7_OpenStackMachineList_To_v1alpha8_OpenStackMachineList(in *OpenStackMachineList, out *v1alpha8.OpenStackMachineList, s conversion.Scope) error { out.ListMeta = in.ListMeta - out.Items = *(*[]v1alpha8.OpenStackMachine)(unsafe.Pointer(&in.Items)) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]v1alpha8.OpenStackMachine, len(*in)) + for i := range *in { + if err := Convert_v1alpha7_OpenStackMachine_To_v1alpha8_OpenStackMachine(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } return nil } @@ -1149,7 +1215,17 @@ func Convert_v1alpha7_OpenStackMachineList_To_v1alpha8_OpenStackMachineList(in * func autoConvert_v1alpha8_OpenStackMachineList_To_v1alpha7_OpenStackMachineList(in *v1alpha8.OpenStackMachineList, out *OpenStackMachineList, s conversion.Scope) error { out.ListMeta = in.ListMeta - out.Items = *(*[]OpenStackMachine)(unsafe.Pointer(&in.Items)) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]OpenStackMachine, len(*in)) + for i := range *in { + if err := Convert_v1alpha8_OpenStackMachine_To_v1alpha7_OpenStackMachine(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } return nil } @@ -1163,8 +1239,8 @@ func autoConvert_v1alpha7_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec( out.InstanceID = (*string)(unsafe.Pointer(in.InstanceID)) out.CloudName = in.CloudName out.Flavor = in.Flavor - out.Image = in.Image - out.ImageUUID = in.ImageUUID + // WARNING: in.Image requires manual conversion: inconvertible types (string vs sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha8.ImageFilter) + // WARNING: in.ImageUUID requires manual conversion: does not exist in peer-type out.SSHKeyName = in.SSHKeyName out.Ports = *(*[]v1alpha8.PortOpts)(unsafe.Pointer(&in.Ports)) out.FloatingIP = in.FloatingIP @@ -1180,18 +1256,12 @@ func autoConvert_v1alpha7_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec( return nil } -// Convert_v1alpha7_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec is an autogenerated conversion function. -func Convert_v1alpha7_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec(in *OpenStackMachineSpec, out *v1alpha8.OpenStackMachineSpec, s conversion.Scope) error { - return autoConvert_v1alpha7_OpenStackMachineSpec_To_v1alpha8_OpenStackMachineSpec(in, out, s) -} - func autoConvert_v1alpha8_OpenStackMachineSpec_To_v1alpha7_OpenStackMachineSpec(in *v1alpha8.OpenStackMachineSpec, out *OpenStackMachineSpec, s conversion.Scope) error { out.ProviderID = (*string)(unsafe.Pointer(in.ProviderID)) out.InstanceID = (*string)(unsafe.Pointer(in.InstanceID)) out.CloudName = in.CloudName out.Flavor = in.Flavor - out.Image = in.Image - out.ImageUUID = in.ImageUUID + // WARNING: in.Image requires manual conversion: inconvertible types (sigs.k8s.io/cluster-api-provider-openstack/api/v1alpha8.ImageFilter vs string) out.SSHKeyName = in.SSHKeyName out.Ports = *(*[]PortOpts)(unsafe.Pointer(&in.Ports)) out.FloatingIP = in.FloatingIP @@ -1207,11 +1277,6 @@ func autoConvert_v1alpha8_OpenStackMachineSpec_To_v1alpha7_OpenStackMachineSpec( return nil } -// Convert_v1alpha8_OpenStackMachineSpec_To_v1alpha7_OpenStackMachineSpec is an autogenerated conversion function. -func Convert_v1alpha8_OpenStackMachineSpec_To_v1alpha7_OpenStackMachineSpec(in *v1alpha8.OpenStackMachineSpec, out *OpenStackMachineSpec, s conversion.Scope) error { - return autoConvert_v1alpha8_OpenStackMachineSpec_To_v1alpha7_OpenStackMachineSpec(in, out, s) -} - func autoConvert_v1alpha7_OpenStackMachineStatus_To_v1alpha8_OpenStackMachineStatus(in *OpenStackMachineStatus, out *v1alpha8.OpenStackMachineStatus, s conversion.Scope) error { out.Ready = in.Ready out.Addresses = *(*[]v1.NodeAddress)(unsafe.Pointer(&in.Addresses)) @@ -1270,7 +1335,17 @@ func Convert_v1alpha8_OpenStackMachineTemplate_To_v1alpha7_OpenStackMachineTempl func autoConvert_v1alpha7_OpenStackMachineTemplateList_To_v1alpha8_OpenStackMachineTemplateList(in *OpenStackMachineTemplateList, out *v1alpha8.OpenStackMachineTemplateList, s conversion.Scope) error { out.ListMeta = in.ListMeta - out.Items = *(*[]v1alpha8.OpenStackMachineTemplate)(unsafe.Pointer(&in.Items)) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]v1alpha8.OpenStackMachineTemplate, len(*in)) + for i := range *in { + if err := Convert_v1alpha7_OpenStackMachineTemplate_To_v1alpha8_OpenStackMachineTemplate(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } return nil } @@ -1281,7 +1356,17 @@ func Convert_v1alpha7_OpenStackMachineTemplateList_To_v1alpha8_OpenStackMachineT func autoConvert_v1alpha8_OpenStackMachineTemplateList_To_v1alpha7_OpenStackMachineTemplateList(in *v1alpha8.OpenStackMachineTemplateList, out *OpenStackMachineTemplateList, s conversion.Scope) error { out.ListMeta = in.ListMeta - out.Items = *(*[]OpenStackMachineTemplate)(unsafe.Pointer(&in.Items)) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]OpenStackMachineTemplate, len(*in)) + for i := range *in { + if err := Convert_v1alpha8_OpenStackMachineTemplate_To_v1alpha7_OpenStackMachineTemplate(&(*in)[i], &(*out)[i], s); err != nil { + return err + } + } + } else { + out.Items = nil + } return nil } diff --git a/api/v1alpha8/filter_convert.go b/api/v1alpha8/filter_convert.go index 23e5330588..378642ce5f 100644 --- a/api/v1alpha8/filter_convert.go +++ b/api/v1alpha8/filter_convert.go @@ -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" @@ -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, + } +} diff --git a/api/v1alpha8/openstackcluster_webhook_test.go b/api/v1alpha8/openstackcluster_webhook_test.go index 256988c81a..cf4f33da27 100644 --- a/api/v1alpha8/openstackcluster_webhook_test.go +++ b/api/v1alpha8/openstackcluster_webhook_test.go @@ -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, @@ -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, diff --git a/api/v1alpha8/openstackmachine_types.go b/api/v1alpha8/openstackmachine_types.go index 8a7c97d406..fbb33813d3 100644 --- a/api/v1alpha8/openstackmachine_types.go +++ b/api/v1alpha8/openstackmachine_types.go @@ -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. + // 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"` + Image ImageFilter `json:"image,omitempty"` // The ssh key to inject in the instance SSHKeyName string `json:"sshKeyName,omitempty"` diff --git a/api/v1alpha8/openstackmachinetemplate_webhook_test.go b/api/v1alpha8/openstackmachinetemplate_webhook_test.go index 6728f9d5fe..e441ef0583 100644 --- a/api/v1alpha8/openstackmachinetemplate_webhook_test.go +++ b/api/v1alpha8/openstackmachinetemplate_webhook_test.go @@ -45,7 +45,7 @@ func TestOpenStackMachineTemplate_ValidateUpdate(t *testing.T) { Template: OpenStackMachineTemplateResource{ Spec: OpenStackMachineSpec{ Flavor: "foo", - Image: "bar", + Image: ImageFilter{Name: "bar"}, }, }, }, @@ -55,7 +55,7 @@ func TestOpenStackMachineTemplate_ValidateUpdate(t *testing.T) { Template: OpenStackMachineTemplateResource{ Spec: OpenStackMachineSpec{ Flavor: "foo", - Image: "NewImage", + Image: ImageFilter{Name: "NewImage"}, }, }, }, @@ -70,7 +70,7 @@ func TestOpenStackMachineTemplate_ValidateUpdate(t *testing.T) { Template: OpenStackMachineTemplateResource{ Spec: OpenStackMachineSpec{ Flavor: "foo", - Image: "bar", + Image: ImageFilter{Name: "bar"}, }, }, }, @@ -83,7 +83,7 @@ func TestOpenStackMachineTemplate_ValidateUpdate(t *testing.T) { Template: OpenStackMachineTemplateResource{ Spec: OpenStackMachineSpec{ Flavor: "foo", - Image: "bar", + Image: ImageFilter{Name: "bar"}, }, }, }, @@ -100,7 +100,7 @@ func TestOpenStackMachineTemplate_ValidateUpdate(t *testing.T) { Template: OpenStackMachineTemplateResource{ Spec: OpenStackMachineSpec{ Flavor: "foo", - Image: "bar", + Image: ImageFilter{Name: "bar"}, }, }, }, @@ -110,7 +110,7 @@ func TestOpenStackMachineTemplate_ValidateUpdate(t *testing.T) { Template: OpenStackMachineTemplateResource{ Spec: OpenStackMachineSpec{ Flavor: "foo", - Image: "NewImage", + Image: ImageFilter{Name: "NewImage"}, }, }, }, @@ -125,7 +125,7 @@ func TestOpenStackMachineTemplate_ValidateUpdate(t *testing.T) { Template: OpenStackMachineTemplateResource{ Spec: OpenStackMachineSpec{ Flavor: "foo", - Image: "bar", + Image: ImageFilter{Name: "bar"}, }, }, }, @@ -140,7 +140,7 @@ func TestOpenStackMachineTemplate_ValidateUpdate(t *testing.T) { Template: OpenStackMachineTemplateResource{ Spec: OpenStackMachineSpec{ Flavor: "foo", - Image: "NewImage", + Image: ImageFilter{Name: "NewImage"}, }, }, }, diff --git a/api/v1alpha8/types.go b/api/v1alpha8/types.go index a6d949cb0a..362e141ce3 100644 --- a/api/v1alpha8/types.go +++ b/api/v1alpha8/types.go @@ -22,6 +22,12 @@ type OpenStackMachineTemplateResource struct { Spec OpenStackMachineSpec `json:"spec"` } +type ImageFilter struct { + ID string `json:"id,omitempty"` + Name string `json:"name,omitempty"` + Tags []string `json:"tags,omitempty"` +} + type ExternalRouterIPParam struct { // The FixedIP in the corresponding subnet FixedIP string `json:"fixedIP,omitempty"` diff --git a/api/v1alpha8/zz_generated.deepcopy.go b/api/v1alpha8/zz_generated.deepcopy.go index 3ded212691..e82aa185f1 100644 --- a/api/v1alpha8/zz_generated.deepcopy.go +++ b/api/v1alpha8/zz_generated.deepcopy.go @@ -200,6 +200,26 @@ func (in *FixedIP) DeepCopy() *FixedIP { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ImageFilter) DeepCopyInto(out *ImageFilter) { + *out = *in + if in.Tags != nil { + in, out := &in.Tags, &out.Tags + *out = make([]string, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ImageFilter. +func (in *ImageFilter) DeepCopy() *ImageFilter { + if in == nil { + return nil + } + out := new(ImageFilter) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *LoadBalancer) DeepCopyInto(out *LoadBalancer) { *out = *in @@ -645,6 +665,7 @@ func (in *OpenStackMachineSpec) DeepCopyInto(out *OpenStackMachineSpec) { *out = new(string) **out = **in } + in.Image.DeepCopyInto(&out.Image) if in.Ports != nil { in, out := &in.Ports, &out.Ports *out = make([]PortOpts, len(*in)) diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclusters.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclusters.yaml index 532490a5ea..9aadb93f90 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclusters.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclusters.yaml @@ -4911,14 +4911,19 @@ spec: - name type: object image: - description: The name of the image to use for your server - instance. If the RootVolume is specified, this will be ignored - and use rootVolume directly. - type: string - imageUUID: - description: The uuid of the image to use for your server - instance. if it's empty, Image name will be used - type: string + description: The image to use for your server instance. If + the RootVolume is specified, this will be ignored and use + rootVolume directly. + properties: + id: + type: string + name: + type: string + tags: + items: + type: string + type: array + type: object instanceID: description: InstanceID is the OpenStack instance ID for this machine. diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclustertemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclustertemplates.yaml index 73f10af04d..1071f92d80 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclustertemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclustertemplates.yaml @@ -2443,15 +2443,19 @@ spec: - name type: object image: - description: The name of the image to use for your - server instance. If the RootVolume is specified, - this will be ignored and use rootVolume directly. - type: string - imageUUID: - description: The uuid of the image to use for your - server instance. if it's empty, Image name will - be used - type: string + description: The image to use for your server instance. + If the RootVolume is specified, this will be ignored + and use rootVolume directly. + properties: + id: + type: string + name: + type: string + tags: + items: + type: string + type: array + type: object instanceID: description: InstanceID is the OpenStack instance ID for this machine. diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachines.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachines.yaml index a9b90ba429..09037521f3 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachines.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachines.yaml @@ -1748,14 +1748,18 @@ spec: - name type: object image: - description: The name of the image to use for your server instance. - If the RootVolume is specified, this will be ignored and use rootVolume - directly. - type: string - imageUUID: - description: The uuid of the image to use for your server instance. - if it's empty, Image name will be used - type: string + description: The image to use for your server instance. If the RootVolume + is specified, this will be ignored and use rootVolume directly. + properties: + id: + type: string + name: + type: string + tags: + items: + type: string + type: array + type: object instanceID: description: InstanceID is the OpenStack instance ID for this machine. type: string diff --git a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachinetemplates.yaml b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachinetemplates.yaml index f60aff2895..b1d84b14df 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachinetemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachinetemplates.yaml @@ -1463,14 +1463,19 @@ spec: - name type: object image: - description: The name of the image to use for your server - instance. If the RootVolume is specified, this will be ignored - and use rootVolume directly. - type: string - imageUUID: - description: The uuid of the image to use for your server - instance. if it's empty, Image name will be used - type: string + description: The image to use for your server instance. If + the RootVolume is specified, this will be ignored and use + rootVolume directly. + properties: + id: + type: string + name: + type: string + tags: + items: + type: string + type: array + type: object instanceID: description: InstanceID is the OpenStack instance ID for this machine. diff --git a/controllers/openstackcluster_controller.go b/controllers/openstackcluster_controller.go index f83b8b75a9..c17b8c0c7c 100644 --- a/controllers/openstackcluster_controller.go +++ b/controllers/openstackcluster_controller.go @@ -393,7 +393,6 @@ func bastionToInstanceSpec(openStackCluster *infrav1.OpenStackCluster, clusterNa Flavor: openStackCluster.Spec.Bastion.Instance.Flavor, SSHKeyName: openStackCluster.Spec.Bastion.Instance.SSHKeyName, Image: openStackCluster.Spec.Bastion.Instance.Image, - ImageUUID: openStackCluster.Spec.Bastion.Instance.ImageUUID, FailureDomain: openStackCluster.Spec.Bastion.AvailabilityZone, RootVolume: openStackCluster.Spec.Bastion.Instance.RootVolume, } diff --git a/controllers/openstackmachine_controller.go b/controllers/openstackmachine_controller.go index d5acde67cb..50ae6b47f1 100644 --- a/controllers/openstackmachine_controller.go +++ b/controllers/openstackmachine_controller.go @@ -455,7 +455,6 @@ func machineToInstanceSpec(openStackCluster *infrav1.OpenStackCluster, machine * instanceSpec := compute.InstanceSpec{ Name: openStackMachine.Name, Image: openStackMachine.Spec.Image, - ImageUUID: openStackMachine.Spec.ImageUUID, Flavor: openStackMachine.Spec.Flavor, SSHKeyName: openStackMachine.Spec.SSHKeyName, UserData: userData, diff --git a/controllers/openstackmachine_controller_test.go b/controllers/openstackmachine_controller_test.go index c78ab8643c..7d29b23b50 100644 --- a/controllers/openstackmachine_controller_test.go +++ b/controllers/openstackmachine_controller_test.go @@ -83,7 +83,7 @@ func getDefaultOpenStackMachine() *infrav1.OpenStackMachine { // TODO: Test Networks, Ports, Subnet, and Trunk separately CloudName: "test-cloud", Flavor: flavorName, - Image: imageName, + Image: infrav1.ImageFilter{Name: imageName}, SSHKeyName: sshKeyName, Tags: []string{"test-tag"}, ServerMetadata: map[string]string{ @@ -99,7 +99,7 @@ func getDefaultOpenStackMachine() *infrav1.OpenStackMachine { func getDefaultInstanceSpec() *compute.InstanceSpec { return &compute.InstanceSpec{ Name: openStackMachineName, - Image: imageName, + Image: infrav1.ImageFilter{Name: imageName}, Flavor: flavorName, SSHKeyName: sshKeyName, UserData: "user-data", diff --git a/docs/book/src/SUMMARY.md b/docs/book/src/SUMMARY.md index 0d309b83fc..a03f4c5fc7 100644 --- a/docs/book/src/SUMMARY.md +++ b/docs/book/src/SUMMARY.md @@ -11,5 +11,6 @@ - [v1alpha4 to v1alpha5](./topics/crd-changes/v1alpha4-to-v1alpha5.md) - [v1alpha5 to v1alpha6](./topics/crd-changes/v1alpha5-to-v1alpha6.md) - [v1alpha6 to v1alpha7](./topics/crd-changes/v1alpha6-to-v1alpha7.md) + - [v1alpha7 to v1alpha8](./topics/crd-changes/v1alpha7-to-v1alpha8.md) - [Development](./development/development.md) - [Hacking CI](./development/ci.md) diff --git a/docs/book/src/topics/crd-changes/v1alpha7-to-v1alpha8.md b/docs/book/src/topics/crd-changes/v1alpha7-to-v1alpha8.md new file mode 100644 index 0000000000..4af31701bc --- /dev/null +++ b/docs/book/src/topics/crd-changes/v1alpha7-to-v1alpha8.md @@ -0,0 +1,53 @@ + + +**Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* + +- [v1alpha7 compared to v1alpha8](#v1alpha7-compared-to-v1alpha8) + - [Migration](#migration) + - [API Changes](#api-changes) + - [`OpenStackMachine`](#openstackmachine) + - [Changes to image](#change-to-image) + - [Removal of imageUUID](#removal-of-imageuuid) + + + +# v1alpha7 compared to v1alpha8 + +> ⚠️ v1alpha8 has not been released yet. + +## API Changes + +This only documents backwards incompatible changes. Fields that were added to v1alpha8 are not listed here. + +### `OpenStackMachine` + +#### ⚠️ Change to image + +The field `image` a string anymore but a reference to a `ImageFilter` object. +It is now possible to specify a `ImageFilter` object to select the image to use for the machine. The `ImageFilter` object allows to select the image by name, by ID or by tags. + +```yaml +image: "test-image" +``` + +becomes + +```yaml +image: + name: "test-image" +``` + +#### ⚠️ Removal of imageUUID + +The fild `imageUUID` has been removed in favor of the `image` field. + +```yaml +imageUUID: "72a6a1e6-3e0a-4a8b-9b4c-2d6f9e3e5f0a" +``` + +becomes + +```yaml +image: + id: "72a6a1e6-3e0a-4a8b-9b4c-2d6f9e3e5f0a" +``` diff --git a/kustomize/v1alpha8/default/cluster-template.yaml b/kustomize/v1alpha8/default/cluster-template.yaml index 4bf130b0a9..3ebe3a9067 100644 --- a/kustomize/v1alpha8/default/cluster-template.yaml +++ b/kustomize/v1alpha8/default/cluster-template.yaml @@ -76,7 +76,8 @@ spec: template: spec: flavor: ${OPENSTACK_CONTROL_PLANE_MACHINE_FLAVOR} - image: ${OPENSTACK_IMAGE_NAME} + image: + name: ${OPENSTACK_IMAGE_NAME} sshKeyName: ${OPENSTACK_SSH_KEY_NAME} cloudName: ${OPENSTACK_CLOUD} identityRef: @@ -119,7 +120,8 @@ spec: name: ${CLUSTER_NAME}-cloud-config kind: Secret flavor: ${OPENSTACK_NODE_MACHINE_FLAVOR} - image: ${OPENSTACK_IMAGE_NAME} + image: + name: ${OPENSTACK_IMAGE_NAME} sshKeyName: ${OPENSTACK_SSH_KEY_NAME} --- apiVersion: bootstrap.cluster.x-k8s.io/v1beta1 diff --git a/kustomize/v1alpha8/flatcar/patch-flatcar.yaml b/kustomize/v1alpha8/flatcar/patch-flatcar.yaml index d3750014fb..4fb1c3a8d1 100644 --- a/kustomize/v1alpha8/flatcar/patch-flatcar.yaml +++ b/kustomize/v1alpha8/flatcar/patch-flatcar.yaml @@ -97,7 +97,8 @@ metadata: spec: template: spec: - image: ${OPENSTACK_FLATCAR_IMAGE_NAME} + image: + name: ${OPENSTACK_FLATCAR_IMAGE_NAME} --- apiVersion: infrastructure.cluster.x-k8s.io/v1alpha8 kind: OpenStackMachineTemplate @@ -106,4 +107,5 @@ metadata: spec: template: spec: - image: ${OPENSTACK_FLATCAR_IMAGE_NAME} + image: + name: ${OPENSTACK_FLATCAR_IMAGE_NAME} diff --git a/pkg/cloud/services/compute/instance.go b/pkg/cloud/services/compute/instance.go index 3c3710ee76..2a1597eafd 100644 --- a/pkg/cloud/services/compute/instance.go +++ b/pkg/cloud/services/compute/instance.go @@ -30,7 +30,6 @@ import ( "github.com/gophercloud/gophercloud/openstack/compute/v2/extensions/schedulerhints" "github.com/gophercloud/gophercloud/openstack/compute/v2/flavors" "github.com/gophercloud/gophercloud/openstack/compute/v2/servers" - "github.com/gophercloud/gophercloud/openstack/imageservice/v2/images" "github.com/gophercloud/gophercloud/openstack/networking/v2/ports" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/util/wait" @@ -238,7 +237,7 @@ func (s *Service) createInstanceImpl(eventObject runtime.Object, openStackCluste var server *clients.ServerExt portList := []servers.Network{} - imageID, err := s.getImageID(instanceSpec.ImageUUID, instanceSpec.Image) + imageID, err := s.getImageID(instanceSpec.Image) if err != nil { return nil, fmt.Errorf("error getting image ID: %v", err) } @@ -562,38 +561,22 @@ func applyServerGroupID(opts servers.CreateOptsBuilder, serverGroupID string) se return opts } -// Helper function for getting image id from name. -func (s *Service) getImageIDFromName(imageName string) (string, error) { - var opts images.ListOpts - - opts.Name = imageName - - allImages, err := s.getImageClient().ListImages(opts) +// Helper function for getting image ID from name or ID. +func (s *Service) getImageID(image infrav1.ImageFilter) (string, error) { + allImages, err := s.getImageClient().ListImages(image.ToListOpt()) if err != nil { return "", err } switch len(allImages) { case 0: - return "", fmt.Errorf("no image with the Name %s could be found", imageName) + return "", fmt.Errorf("no images could be found") case 1: return allImages[0].ID, nil default: // this should never happen - return "", fmt.Errorf("too many images with the name, %s, were found", imageName) - } -} - -// Helper function for getting image ID from name or ID. -func (s *Service) getImageID(imageUUID, imageName string) (string, error) { - if imageUUID != "" { - // we return imageUUID without check - return imageUUID, nil - } else if imageName != "" { - return s.getImageIDFromName(imageName) + return "", fmt.Errorf("too many images were found") } - - return "", nil } // GetManagementPort returns the port which is used for management and external diff --git a/pkg/cloud/services/compute/instance_test.go b/pkg/cloud/services/compute/instance_test.go index 814fd807a9..9fc06e4757 100644 --- a/pkg/cloud/services/compute/instance_test.go +++ b/pkg/cloud/services/compute/instance_test.go @@ -119,51 +119,43 @@ func Test_getPortName(t *testing.T) { } func TestService_getImageID(t *testing.T) { - const imageIDA = "ce96e584-7ebc-46d6-9e55-987d72e3806c" - const imageIDB = "8f536889-5198-42d7-8314-cb78f4f4755c" - const imageIDC = "8f536889-5198-42d7-8314-cb78f4f4755d" + const imageID = "ce96e584-7ebc-46d6-9e55-987d72e3806c" + const imageName = "test-image" tests := []struct { - testName string - imageUUID string - imageName string - expect func(m *mock.MockImageClientMockRecorder) - want string - wantErr bool + testName string + image infrav1.ImageFilter + expect func(m *mock.MockImageClientMockRecorder) + want string + wantErr bool }{ { - testName: "Return image uuid if uuid given", - imageUUID: imageIDC, - want: imageIDC, - expect: func(m *mock.MockImageClientMockRecorder) { - }, - wantErr: false, - }, - { - testName: "Return through uuid if both uuid and name given", - imageName: "dummy", - imageUUID: imageIDC, + testName: "Return image ID when ID given", + image: infrav1.ImageFilter{ID: imageID}, + want: imageID, expect: func(m *mock.MockImageClientMockRecorder) { + m.ListImages(images.ListOpts{ID: imageID}).Return( + []images.Image{{ID: imageID, Name: imageName}}, + nil) }, - want: imageIDC, wantErr: false, }, { - testName: "Return image ID", - imageName: "test-image", + testName: "Return image ID when name given", + image: infrav1.ImageFilter{Name: imageName}, + want: imageID, expect: func(m *mock.MockImageClientMockRecorder) { - m.ListImages(images.ListOpts{Name: "test-image"}).Return( - []images.Image{{ID: imageIDA, Name: "test-image"}}, + m.ListImages(images.ListOpts{Name: imageName}).Return( + []images.Image{{ID: imageID, Name: imageName}}, nil) }, - want: imageIDA, wantErr: false, }, { - testName: "Return no results", - imageName: "test-image", + testName: "Return no results", + image: infrav1.ImageFilter{Name: imageName}, expect: func(m *mock.MockImageClientMockRecorder) { - m.ListImages(images.ListOpts{Name: "test-image"}).Return( + m.ListImages(images.ListOpts{Name: imageName}).Return( []images.Image{}, nil) }, @@ -171,21 +163,21 @@ func TestService_getImageID(t *testing.T) { wantErr: true, }, { - testName: "Return multiple results", - imageName: "test-image", + testName: "Return multiple results", + image: infrav1.ImageFilter{Name: imageName}, expect: func(m *mock.MockImageClientMockRecorder) { m.ListImages(images.ListOpts{Name: "test-image"}).Return( []images.Image{ - {ID: imageIDA, Name: "test-image"}, - {ID: imageIDB, Name: "test-image"}, + {ID: imageID, Name: "test-image"}, + {ID: "123", Name: "test-image"}, }, nil) }, want: "", wantErr: true, }, { - testName: "OpenStack returns error", - imageName: "test-image", + testName: "OpenStack returns error", + image: infrav1.ImageFilter{Name: imageName}, expect: func(m *mock.MockImageClientMockRecorder) { m.ListImages(images.ListOpts{Name: "test-image"}).Return( nil, @@ -206,7 +198,7 @@ func TestService_getImageID(t *testing.T) { } tt.expect(mockScopeFactory.ImageClient.EXPECT()) - got, err := s.getImageID(tt.imageUUID, tt.imageName) + got, err := s.getImageID(tt.image) if (err != nil) != tt.wantErr { t.Errorf("Service.getImageID() error = %v, wantErr %v", err, tt.wantErr) return @@ -261,7 +253,7 @@ func getDefaultOpenStackCluster() *infrav1.OpenStackCluster { func getDefaultInstanceSpec() *InstanceSpec { return &InstanceSpec{ Name: openStackMachineName, - Image: imageName, + Image: infrav1.ImageFilter{Name: imageName}, Flavor: flavorName, SSHKeyName: sshKeyName, UserData: "user-data", diff --git a/pkg/cloud/services/compute/instance_types.go b/pkg/cloud/services/compute/instance_types.go index d7b5634605..5b3c73ff74 100644 --- a/pkg/cloud/services/compute/instance_types.go +++ b/pkg/cloud/services/compute/instance_types.go @@ -34,8 +34,7 @@ import ( // all of them can be set on a new instance. type InstanceSpec struct { Name string - Image string - ImageUUID string + Image infrav1.ImageFilter Flavor string SSHKeyName string UserData string diff --git a/templates/cluster-template-flatcar.yaml b/templates/cluster-template-flatcar.yaml index cb3cf1b0eb..23053b2b3f 100644 --- a/templates/cluster-template-flatcar.yaml +++ b/templates/cluster-template-flatcar.yaml @@ -170,7 +170,8 @@ spec: identityRef: kind: Secret name: ${CLUSTER_NAME}-cloud-config - image: ${OPENSTACK_FLATCAR_IMAGE_NAME} + image: + name: ${OPENSTACK_FLATCAR_IMAGE_NAME} sshKeyName: ${OPENSTACK_SSH_KEY_NAME} --- apiVersion: infrastructure.cluster.x-k8s.io/v1alpha8 @@ -185,5 +186,6 @@ spec: identityRef: kind: Secret name: ${CLUSTER_NAME}-cloud-config - image: ${OPENSTACK_FLATCAR_IMAGE_NAME} + image: + name: ${OPENSTACK_FLATCAR_IMAGE_NAME} sshKeyName: ${OPENSTACK_SSH_KEY_NAME} diff --git a/templates/cluster-template-without-lb.yaml b/templates/cluster-template-without-lb.yaml index 4081e804ff..57309d8e73 100644 --- a/templates/cluster-template-without-lb.yaml +++ b/templates/cluster-template-without-lb.yaml @@ -127,7 +127,8 @@ spec: identityRef: kind: Secret name: ${CLUSTER_NAME}-cloud-config - image: ${OPENSTACK_IMAGE_NAME} + image: + name: ${OPENSTACK_IMAGE_NAME} sshKeyName: ${OPENSTACK_SSH_KEY_NAME} --- apiVersion: infrastructure.cluster.x-k8s.io/v1alpha8 @@ -142,5 +143,6 @@ spec: identityRef: kind: Secret name: ${CLUSTER_NAME}-cloud-config - image: ${OPENSTACK_IMAGE_NAME} + image: + name: ${OPENSTACK_IMAGE_NAME} sshKeyName: ${OPENSTACK_SSH_KEY_NAME} diff --git a/templates/cluster-template.yaml b/templates/cluster-template.yaml index 71f9f5695c..d203dcc8e8 100644 --- a/templates/cluster-template.yaml +++ b/templates/cluster-template.yaml @@ -129,7 +129,8 @@ spec: identityRef: kind: Secret name: ${CLUSTER_NAME}-cloud-config - image: ${OPENSTACK_IMAGE_NAME} + image: + name: ${OPENSTACK_IMAGE_NAME} sshKeyName: ${OPENSTACK_SSH_KEY_NAME} --- apiVersion: infrastructure.cluster.x-k8s.io/v1alpha8 @@ -144,5 +145,6 @@ spec: identityRef: kind: Secret name: ${CLUSTER_NAME}-cloud-config - image: ${OPENSTACK_IMAGE_NAME} + image: + name: ${OPENSTACK_IMAGE_NAME} sshKeyName: ${OPENSTACK_SSH_KEY_NAME} diff --git a/test/e2e/data/kustomize/k8s-upgrade/upgrade-from-template.yaml b/test/e2e/data/kustomize/k8s-upgrade/upgrade-from-template.yaml index 4bba2d5165..339b52535a 100644 --- a/test/e2e/data/kustomize/k8s-upgrade/upgrade-from-template.yaml +++ b/test/e2e/data/kustomize/k8s-upgrade/upgrade-from-template.yaml @@ -11,7 +11,8 @@ spec: identityRef: kind: Secret name: ${CLUSTER_NAME}-cloud-config - image: ${OPENSTACK_IMAGE_NAME_UPGRADE_FROM} + image: + name: ${OPENSTACK_IMAGE_NAME_UPGRADE_FROM} sshKeyName: ${OPENSTACK_SSH_KEY_NAME} tags: - control-plane @@ -28,7 +29,8 @@ spec: identityRef: kind: Secret name: ${CLUSTER_NAME}-cloud-config - image: ${OPENSTACK_IMAGE_NAME_UPGRADE_FROM} + image: + name: ${OPENSTACK_IMAGE_NAME_UPGRADE_FROM} sshKeyName: ${OPENSTACK_SSH_KEY_NAME} tags: - machine diff --git a/test/e2e/data/kustomize/k8s-upgrade/upgrade-to-template.yaml b/test/e2e/data/kustomize/k8s-upgrade/upgrade-to-template.yaml index 035aad375a..6e426d14a5 100644 --- a/test/e2e/data/kustomize/k8s-upgrade/upgrade-to-template.yaml +++ b/test/e2e/data/kustomize/k8s-upgrade/upgrade-to-template.yaml @@ -18,7 +18,8 @@ spec: identityRef: kind: Secret name: ${CLUSTER_NAME}-cloud-config - image: ${OPENSTACK_IMAGE_NAME} + image: + name: ${OPENSTACK_IMAGE_NAME} sshKeyName: ${OPENSTACK_SSH_KEY_NAME} tags: - control-plane @@ -37,7 +38,8 @@ spec: identityRef: kind: Secret name: ${CLUSTER_NAME}-cloud-config - image: ${OPENSTACK_IMAGE_NAME} + image: + name: ${OPENSTACK_IMAGE_NAME} sshKeyName: ${OPENSTACK_SSH_KEY_NAME} tags: - machine diff --git a/test/e2e/suites/e2e/e2e_test.go b/test/e2e/suites/e2e/e2e_test.go index 90930a9fd3..1f0af508b5 100644 --- a/test/e2e/suites/e2e/e2e_test.go +++ b/test/e2e/suites/e2e/e2e_test.go @@ -728,8 +728,10 @@ func makeOpenStackMachineTemplate(namespace, clusterName, name string) *infrav1. Spec: infrav1.OpenStackMachineTemplateSpec{ Template: infrav1.OpenStackMachineTemplateResource{ Spec: infrav1.OpenStackMachineSpec{ - Flavor: e2eCtx.E2EConfig.GetVariable(shared.OpenStackNodeMachineFlavor), - Image: e2eCtx.E2EConfig.GetVariable(shared.OpenStackImageName), + Flavor: e2eCtx.E2EConfig.GetVariable(shared.OpenStackNodeMachineFlavor), + Image: infrav1.ImageFilter{ + Name: e2eCtx.E2EConfig.GetVariable(shared.OpenStackImageName), + }, SSHKeyName: shared.DefaultSSHKeyPairName, CloudName: e2eCtx.E2EConfig.GetVariable(shared.OpenStackCloud), IdentityRef: &infrav1.OpenStackIdentityReference{ @@ -751,8 +753,10 @@ func makeOpenStackMachineTemplateWithPortOptions(namespace, clusterName, name st Spec: infrav1.OpenStackMachineTemplateSpec{ Template: infrav1.OpenStackMachineTemplateResource{ Spec: infrav1.OpenStackMachineSpec{ - Flavor: e2eCtx.E2EConfig.GetVariable(shared.OpenStackNodeMachineFlavor), - Image: e2eCtx.E2EConfig.GetVariable(shared.OpenStackImageName), + Flavor: e2eCtx.E2EConfig.GetVariable(shared.OpenStackNodeMachineFlavor), + Image: infrav1.ImageFilter{ + Name: e2eCtx.E2EConfig.GetVariable(shared.OpenStackImageName), + }, SSHKeyName: shared.DefaultSSHKeyPairName, CloudName: e2eCtx.E2EConfig.GetVariable(shared.OpenStackCloud), IdentityRef: &infrav1.OpenStackIdentityReference{