diff --git a/api/v1alpha5/conversion.go b/api/v1alpha5/conversion.go index 5c2516b891..e03283836d 100644 --- a/api/v1alpha5/conversion.go +++ b/api/v1alpha5/conversion.go @@ -448,11 +448,8 @@ func Convert_v1alpha5_PortOpts_To_v1beta1_PortOpts(in *PortOpts, out *infrav1.Po } func Convert_v1alpha5_Instance_To_v1beta1_BastionStatus(in *Instance, out *infrav1.BastionStatus, _ conversion.Scope) error { - // BastionStatus is the same as Spec with unused fields removed - out.ID = in.ID + // BastionStatus is the same as Instance with unused fields removed out.Name = in.Name - out.SSHKeyName = in.SSHKeyName - out.State = infrav1.InstanceState(in.State) out.IP = in.IP out.FloatingIP = in.FloatingIP out.Resolved.ServerGroupID = in.ServerGroupID @@ -460,11 +457,8 @@ func Convert_v1alpha5_Instance_To_v1beta1_BastionStatus(in *Instance, out *infra } func Convert_v1beta1_BastionStatus_To_v1alpha5_Instance(in *infrav1.BastionStatus, out *Instance, _ conversion.Scope) error { - // BastionStatus is the same as Spec with unused fields removed - out.ID = in.ID + // BastionStatus is the same as Instance with unused fields removed out.Name = in.Name - out.SSHKeyName = in.SSHKeyName - out.State = InstanceState(in.State) out.IP = in.IP out.FloatingIP = in.FloatingIP out.ServerGroupID = in.Resolved.ServerGroupID @@ -661,8 +655,11 @@ func Convert_v1beta1_OpenStackMachineSpec_To_v1alpha5_OpenStackMachineSpec(in *i return nil } +func Convert_v1alpha5_OpenStackMachineStatus_To_v1beta1_OpenStackMachineStatus(in *OpenStackMachineStatus, out *infrav1.OpenStackMachineStatus, s conversion.Scope) error { + return autoConvert_v1alpha5_OpenStackMachineStatus_To_v1beta1_OpenStackMachineStatus(in, out, s) +} + func Convert_v1beta1_OpenStackMachineStatus_To_v1alpha5_OpenStackMachineStatus(in *infrav1.OpenStackMachineStatus, out *OpenStackMachineStatus, s conversion.Scope) error { - // ReferencedResources have no equivalent in v1alpha5 return autoConvert_v1beta1_OpenStackMachineStatus_To_v1alpha5_OpenStackMachineStatus(in, out, s) } diff --git a/api/v1alpha5/zz_generated.conversion.go b/api/v1alpha5/zz_generated.conversion.go index f5d208397e..07cee63090 100644 --- a/api/v1alpha5/zz_generated.conversion.go +++ b/api/v1alpha5/zz_generated.conversion.go @@ -162,11 +162,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*OpenStackMachineStatus)(nil), (*v1beta1.OpenStackMachineStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha5_OpenStackMachineStatus_To_v1beta1_OpenStackMachineStatus(a.(*OpenStackMachineStatus), b.(*v1beta1.OpenStackMachineStatus), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*OpenStackMachineTemplate)(nil), (*v1beta1.OpenStackMachineTemplate)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha5_OpenStackMachineTemplate_To_v1beta1_OpenStackMachineTemplate(a.(*OpenStackMachineTemplate), b.(*v1beta1.OpenStackMachineTemplate), scope) }); err != nil { @@ -282,6 +277,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*OpenStackMachineStatus)(nil), (*v1beta1.OpenStackMachineStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha5_OpenStackMachineStatus_To_v1beta1_OpenStackMachineStatus(a.(*OpenStackMachineStatus), b.(*v1beta1.OpenStackMachineStatus), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*PortOpts)(nil), (*v1beta1.PortOpts)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha5_PortOpts_To_v1beta1_PortOpts(a.(*PortOpts), b.(*v1beta1.PortOpts), scope) }); err != nil { @@ -1096,7 +1096,7 @@ func Convert_v1beta1_OpenStackMachineList_To_v1alpha5_OpenStackMachineList(in *v func autoConvert_v1alpha5_OpenStackMachineSpec_To_v1beta1_OpenStackMachineSpec(in *OpenStackMachineSpec, out *v1beta1.OpenStackMachineSpec, s conversion.Scope) error { out.ProviderID = (*string)(unsafe.Pointer(in.ProviderID)) - out.InstanceID = (*string)(unsafe.Pointer(in.InstanceID)) + // WARNING: in.InstanceID requires manual conversion: does not exist in peer-type // WARNING: in.CloudName requires manual conversion: does not exist in peer-type out.Flavor = in.Flavor // WARNING: in.Image requires manual conversion: inconvertible types (string vs sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1.ImageFilter) @@ -1147,7 +1147,6 @@ func autoConvert_v1alpha5_OpenStackMachineSpec_To_v1beta1_OpenStackMachineSpec(i func autoConvert_v1beta1_OpenStackMachineSpec_To_v1alpha5_OpenStackMachineSpec(in *v1beta1.OpenStackMachineSpec, out *OpenStackMachineSpec, s conversion.Scope) error { out.ProviderID = (*string)(unsafe.Pointer(in.ProviderID)) - out.InstanceID = (*string)(unsafe.Pointer(in.InstanceID)) out.Flavor = in.Flavor // WARNING: in.Image requires manual conversion: inconvertible types (sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1.ImageFilter vs string) out.SSHKeyName = in.SSHKeyName @@ -1196,27 +1195,22 @@ func autoConvert_v1beta1_OpenStackMachineSpec_To_v1alpha5_OpenStackMachineSpec(i func autoConvert_v1alpha5_OpenStackMachineStatus_To_v1beta1_OpenStackMachineStatus(in *OpenStackMachineStatus, out *v1beta1.OpenStackMachineStatus, s conversion.Scope) error { out.Ready = in.Ready out.Addresses = *(*[]corev1.NodeAddress)(unsafe.Pointer(&in.Addresses)) - out.InstanceState = (*v1beta1.InstanceState)(unsafe.Pointer(in.InstanceState)) + // WARNING: in.InstanceState requires manual conversion: does not exist in peer-type out.FailureReason = (*errors.MachineStatusError)(unsafe.Pointer(in.FailureReason)) out.FailureMessage = (*string)(unsafe.Pointer(in.FailureMessage)) out.Conditions = *(*apiv1beta1.Conditions)(unsafe.Pointer(&in.Conditions)) return nil } -// Convert_v1alpha5_OpenStackMachineStatus_To_v1beta1_OpenStackMachineStatus is an autogenerated conversion function. -func Convert_v1alpha5_OpenStackMachineStatus_To_v1beta1_OpenStackMachineStatus(in *OpenStackMachineStatus, out *v1beta1.OpenStackMachineStatus, s conversion.Scope) error { - return autoConvert_v1alpha5_OpenStackMachineStatus_To_v1beta1_OpenStackMachineStatus(in, out, s) -} - func autoConvert_v1beta1_OpenStackMachineStatus_To_v1alpha5_OpenStackMachineStatus(in *v1beta1.OpenStackMachineStatus, out *OpenStackMachineStatus, s conversion.Scope) error { out.Ready = in.Ready out.Addresses = *(*[]corev1.NodeAddress)(unsafe.Pointer(&in.Addresses)) - out.InstanceState = (*InstanceState)(unsafe.Pointer(in.InstanceState)) // WARNING: in.Resolved requires manual conversion: does not exist in peer-type // WARNING: in.Resources requires manual conversion: does not exist in peer-type out.FailureReason = (*errors.MachineStatusError)(unsafe.Pointer(in.FailureReason)) out.FailureMessage = (*string)(unsafe.Pointer(in.FailureMessage)) out.Conditions = *(*apiv1beta1.Conditions)(unsafe.Pointer(&in.Conditions)) + // WARNING: in.Server requires manual conversion: does not exist in peer-type return nil } diff --git a/api/v1alpha6/conversion_test.go b/api/v1alpha6/conversion_test.go index 3e5484cafd..707eb0ba72 100644 --- a/api/v1alpha6/conversion_test.go +++ b/api/v1alpha6/conversion_test.go @@ -684,7 +684,10 @@ func TestMachineConversionControllerSpecFields(t *testing.T) { { name: "Set InstanceID", modifyUp: func(up *infrav1.OpenStackMachine) { - up.Spec.InstanceID = pointer.String("new-instance-id") + up.Status.Server = &infrav1.ServerStatus{ + ID: "new-instance-id", + State: "ACTIVE", + } }, testAfter: func(after *OpenStackMachine) { g.Expect(after.Spec.InstanceID).To(gomega.Equal(pointer.String("new-instance-id"))) diff --git a/api/v1alpha6/openstackcluster_conversion.go b/api/v1alpha6/openstackcluster_conversion.go index 92fe7df622..cfbb488d65 100644 --- a/api/v1alpha6/openstackcluster_conversion.go +++ b/api/v1alpha6/openstackcluster_conversion.go @@ -139,6 +139,7 @@ func restorev1alpha6ClusterSpec(previous *OpenStackClusterSpec, dst *OpenStackCl dstBastion := dst.Bastion if prevBastion != nil && dstBastion != nil { restorev1alpha6MachineSpec(&prevBastion.Instance, &dstBastion.Instance) + dstBastion.Instance.InstanceID = prevBastion.Instance.InstanceID } // To avoid lossy conversion, we need to restore AllowAllInClusterTraffic @@ -338,6 +339,10 @@ func Convert_v1beta1_OpenStackClusterSpec_To_v1alpha6_OpenStackClusterSpec(in *i /* OpenStackClusterStatus */ func restorev1alpha6ClusterStatus(previous *OpenStackClusterStatus, dst *OpenStackClusterStatus) { + if previous == nil || dst == nil { + return + } + // PortOpts.SecurityGroups have been removed in v1beta1 // We restore the whole PortOpts/Networks since they are anyway immutable. if previous.ExternalNetwork != nil { @@ -353,6 +358,8 @@ func restorev1alpha6ClusterStatus(previous *OpenStackClusterStatus, dst *OpenSta restorev1alpha6SecurityGroup(previous.ControlPlaneSecurityGroup, dst.ControlPlaneSecurityGroup) restorev1alpha6SecurityGroup(previous.WorkerSecurityGroup, dst.WorkerSecurityGroup) restorev1alpha6SecurityGroup(previous.BastionSecurityGroup, dst.BastionSecurityGroup) + + restorev1alpha6BastionStatus(previous.Bastion, dst.Bastion) } func restorev1beta1ClusterStatus(previous *infrav1.OpenStackClusterStatus, dst *infrav1.OpenStackClusterStatus) { @@ -418,6 +425,18 @@ func restorev1beta1Bastion(previous **infrav1.Bastion, dst **infrav1.Bastion) { optional.RestoreString(&(*previous).AvailabilityZone, &(*dst).AvailabilityZone) } +/* Bastion status */ + +func restorev1alpha6BastionStatus(previous *Instance, dst *Instance) { + if previous == nil || dst == nil { + return + } + + dst.ID = previous.ID + dst.SSHKeyName = previous.SSHKeyName + dst.State = previous.State +} + func Convert_v1alpha6_Bastion_To_v1beta1_Bastion(in *Bastion, out *infrav1.Bastion, s apiconversion.Scope) error { err := autoConvert_v1alpha6_Bastion_To_v1beta1_Bastion(in, out, s) if err != nil { @@ -481,14 +500,12 @@ func restorev1beta1BastionStatus(previous *infrav1.BastionStatus, dst *infrav1.B // Resolved and resources have no equivalents dst.Resolved = previous.Resolved dst.Resources = previous.Resources + dst.Server = previous.Server } func Convert_v1alpha6_Instance_To_v1beta1_BastionStatus(in *Instance, out *infrav1.BastionStatus, _ apiconversion.Scope) error { // BastionStatus is the same as Spec with unused fields removed - out.ID = in.ID out.Name = in.Name - out.SSHKeyName = in.SSHKeyName - out.State = infrav1.InstanceState(in.State) out.IP = in.IP out.FloatingIP = in.FloatingIP return nil @@ -496,10 +513,7 @@ func Convert_v1alpha6_Instance_To_v1beta1_BastionStatus(in *Instance, out *infra func Convert_v1beta1_BastionStatus_To_v1alpha6_Instance(in *infrav1.BastionStatus, out *Instance, _ apiconversion.Scope) error { // BastionStatus is the same as Spec with unused fields removed - out.ID = in.ID out.Name = in.Name - out.SSHKeyName = in.SSHKeyName - out.State = InstanceState(in.State) out.IP = in.IP out.FloatingIP = in.FloatingIP return nil diff --git a/api/v1alpha6/openstackmachine_conversion.go b/api/v1alpha6/openstackmachine_conversion.go index ad88c7afc0..5582227977 100644 --- a/api/v1alpha6/openstackmachine_conversion.go +++ b/api/v1alpha6/openstackmachine_conversion.go @@ -80,6 +80,12 @@ var v1alpha6OpenStackMachineRestorer = conversion.RestorerFor[*OpenStackMachine] return s }), ), + "status": conversion.HashedFieldRestorer( + func(c *OpenStackMachine) *OpenStackMachineStatus { + return &c.Status + }, + restorev1alpha6MachineStatus, + ), } var v1beta1OpenStackMachineRestorer = conversion.RestorerFor[*infrav1.OpenStackMachine]{ @@ -102,6 +108,39 @@ var v1beta1OpenStackMachineRestorer = conversion.RestorerFor[*infrav1.OpenStackM ), } +/* OpenStackMachine */ + +func Convert_v1alpha6_OpenStackMachine_To_v1beta1_OpenStackMachine(in *OpenStackMachine, out *infrav1.OpenStackMachine, s apiconversion.Scope) error { + if err := autoConvert_v1alpha6_OpenStackMachine_To_v1beta1_OpenStackMachine(in, out, s); err != nil { + return err + } + + if in.Spec.InstanceID != nil { + serverStatus := &infrav1.ServerStatus{ + ID: *in.Spec.InstanceID, + } + if in.Status.InstanceState != nil { + serverStatus.State = (infrav1.InstanceState)(*in.Status.InstanceState) + } + out.Status.Server = serverStatus + } + return nil +} + +func Convert_v1beta1_OpenStackMachine_To_v1alpha6_OpenStackMachine(in *infrav1.OpenStackMachine, out *OpenStackMachine, s apiconversion.Scope) error { + if err := autoConvert_v1beta1_OpenStackMachine_To_v1alpha6_OpenStackMachine(in, out, s); err != nil { + return err + } + + if in.Status.Server != nil { + out.Spec.InstanceID = &in.Status.Server.ID + state := InstanceState(in.Status.Server.State) + out.Status.InstanceState = &state + } + + return nil +} + /* OpenStackMachineSpec */ func restorev1alpha6MachineSpec(previous *OpenStackMachineSpec, dst *OpenStackMachineSpec) { @@ -163,6 +202,10 @@ func restorev1alpha6MachineSpec(previous *OpenStackMachineSpec, dst *OpenStackMa } func restorev1beta1MachineSpec(previous *infrav1.OpenStackMachineSpec, dst *infrav1.OpenStackMachineSpec) { + if previous == nil || dst == nil { + return + } + // PropagateUplinkStatus has been added in v1beta1. // We restore the whole Ports since they are anyway immutable. dst.Ports = previous.Ports @@ -342,7 +385,19 @@ func Convert_v1beta1_OpenStackMachineSpec_To_v1alpha6_OpenStackMachineSpec(in *i /* OpenStackMachineStatus */ +func restorev1alpha6MachineStatus(previous *OpenStackMachineStatus, dst *OpenStackMachineStatus) { + if previous == nil || dst == nil { + return + } + if dst.InstanceState == nil || *dst.InstanceState == "" { + dst.InstanceState = previous.InstanceState + } +} + +func Convert_v1alpha6_OpenStackMachineStatus_To_v1beta1_OpenStackMachineStatus(in *OpenStackMachineStatus, out *infrav1.OpenStackMachineStatus, s apiconversion.Scope) error { + return autoConvert_v1alpha6_OpenStackMachineStatus_To_v1beta1_OpenStackMachineStatus(in, out, s) +} + func Convert_v1beta1_OpenStackMachineStatus_To_v1alpha6_OpenStackMachineStatus(in *infrav1.OpenStackMachineStatus, out *OpenStackMachineStatus, s apiconversion.Scope) error { - // ReferencedResources have no equivalent in v1alpha6 return autoConvert_v1beta1_OpenStackMachineStatus_To_v1alpha6_OpenStackMachineStatus(in, out, s) } diff --git a/api/v1alpha6/openstackmachinetemplate_conversion.go b/api/v1alpha6/openstackmachinetemplate_conversion.go index 0851e5f6b1..51c1bc9c45 100644 --- a/api/v1alpha6/openstackmachinetemplate_conversion.go +++ b/api/v1alpha6/openstackmachinetemplate_conversion.go @@ -64,7 +64,7 @@ var v1alpha6OpenStackMachineTemplateRestorer = conversion.RestorerFor[*OpenStack func(c *OpenStackMachineTemplate) *OpenStackMachineSpec { return &c.Spec.Template.Spec }, - restorev1alpha6MachineSpec, + restorev1alpha6MachineSpecFromTemplate, ), } @@ -76,3 +76,9 @@ var v1beta1OpenStackMachineTemplateRestorer = conversion.RestorerFor[*infrav1.Op restorev1beta1MachineSpec, ), } + +func restorev1alpha6MachineSpecFromTemplate(previous *OpenStackMachineSpec, dst *OpenStackMachineSpec) { + restorev1alpha6MachineSpec(previous, dst) + + dst.InstanceID = previous.InstanceID +} diff --git a/api/v1alpha6/zz_generated.conversion.go b/api/v1alpha6/zz_generated.conversion.go index b35e716ad4..943023a3c8 100644 --- a/api/v1alpha6/zz_generated.conversion.go +++ b/api/v1alpha6/zz_generated.conversion.go @@ -151,16 +151,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*OpenStackMachine)(nil), (*v1beta1.OpenStackMachine)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha6_OpenStackMachine_To_v1beta1_OpenStackMachine(a.(*OpenStackMachine), b.(*v1beta1.OpenStackMachine), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*v1beta1.OpenStackMachine)(nil), (*OpenStackMachine)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta1_OpenStackMachine_To_v1alpha6_OpenStackMachine(a.(*v1beta1.OpenStackMachine), b.(*OpenStackMachine), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*OpenStackMachineList)(nil), (*v1beta1.OpenStackMachineList)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha6_OpenStackMachineList_To_v1beta1_OpenStackMachineList(a.(*OpenStackMachineList), b.(*v1beta1.OpenStackMachineList), scope) }); err != nil { @@ -171,11 +161,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*OpenStackMachineStatus)(nil), (*v1beta1.OpenStackMachineStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha6_OpenStackMachineStatus_To_v1beta1_OpenStackMachineStatus(a.(*OpenStackMachineStatus), b.(*v1beta1.OpenStackMachineStatus), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*OpenStackMachineTemplate)(nil), (*v1beta1.OpenStackMachineTemplate)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha6_OpenStackMachineTemplate_To_v1beta1_OpenStackMachineTemplate(a.(*OpenStackMachineTemplate), b.(*v1beta1.OpenStackMachineTemplate), scope) }); err != nil { @@ -301,6 +286,16 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*OpenStackMachineStatus)(nil), (*v1beta1.OpenStackMachineStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha6_OpenStackMachineStatus_To_v1beta1_OpenStackMachineStatus(a.(*OpenStackMachineStatus), b.(*v1beta1.OpenStackMachineStatus), scope) + }); err != nil { + return err + } + if err := s.AddConversionFunc((*OpenStackMachine)(nil), (*v1beta1.OpenStackMachine)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha6_OpenStackMachine_To_v1beta1_OpenStackMachine(a.(*OpenStackMachine), b.(*v1beta1.OpenStackMachine), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*PortOpts)(nil), (*v1beta1.PortOpts)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha6_PortOpts_To_v1beta1_PortOpts(a.(*PortOpts), b.(*v1beta1.PortOpts), scope) }); err != nil { @@ -381,6 +376,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*v1beta1.OpenStackMachine)(nil), (*OpenStackMachine)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_OpenStackMachine_To_v1alpha6_OpenStackMachine(a.(*v1beta1.OpenStackMachine), b.(*OpenStackMachine), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*v1beta1.PortOpts)(nil), (*PortOpts)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1beta1_PortOpts_To_v1alpha6_PortOpts(a.(*v1beta1.PortOpts), b.(*PortOpts), scope) }); err != nil { @@ -1066,11 +1066,6 @@ func autoConvert_v1alpha6_OpenStackMachine_To_v1beta1_OpenStackMachine(in *OpenS return nil } -// Convert_v1alpha6_OpenStackMachine_To_v1beta1_OpenStackMachine is an autogenerated conversion function. -func Convert_v1alpha6_OpenStackMachine_To_v1beta1_OpenStackMachine(in *OpenStackMachine, out *v1beta1.OpenStackMachine, s conversion.Scope) error { - return autoConvert_v1alpha6_OpenStackMachine_To_v1beta1_OpenStackMachine(in, out, s) -} - func autoConvert_v1beta1_OpenStackMachine_To_v1alpha6_OpenStackMachine(in *v1beta1.OpenStackMachine, out *OpenStackMachine, s conversion.Scope) error { out.ObjectMeta = in.ObjectMeta if err := Convert_v1beta1_OpenStackMachineSpec_To_v1alpha6_OpenStackMachineSpec(&in.Spec, &out.Spec, s); err != nil { @@ -1082,11 +1077,6 @@ func autoConvert_v1beta1_OpenStackMachine_To_v1alpha6_OpenStackMachine(in *v1bet return nil } -// Convert_v1beta1_OpenStackMachine_To_v1alpha6_OpenStackMachine is an autogenerated conversion function. -func Convert_v1beta1_OpenStackMachine_To_v1alpha6_OpenStackMachine(in *v1beta1.OpenStackMachine, out *OpenStackMachine, s conversion.Scope) error { - return autoConvert_v1beta1_OpenStackMachine_To_v1alpha6_OpenStackMachine(in, out, s) -} - func autoConvert_v1alpha6_OpenStackMachineList_To_v1beta1_OpenStackMachineList(in *OpenStackMachineList, out *v1beta1.OpenStackMachineList, s conversion.Scope) error { out.ListMeta = in.ListMeta if in.Items != nil { @@ -1131,7 +1121,7 @@ func Convert_v1beta1_OpenStackMachineList_To_v1alpha6_OpenStackMachineList(in *v func autoConvert_v1alpha6_OpenStackMachineSpec_To_v1beta1_OpenStackMachineSpec(in *OpenStackMachineSpec, out *v1beta1.OpenStackMachineSpec, s conversion.Scope) error { out.ProviderID = (*string)(unsafe.Pointer(in.ProviderID)) - out.InstanceID = (*string)(unsafe.Pointer(in.InstanceID)) + // WARNING: in.InstanceID requires manual conversion: does not exist in peer-type // WARNING: in.CloudName requires manual conversion: does not exist in peer-type out.Flavor = in.Flavor // WARNING: in.Image requires manual conversion: inconvertible types (string vs sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1.ImageFilter) @@ -1182,7 +1172,6 @@ func autoConvert_v1alpha6_OpenStackMachineSpec_To_v1beta1_OpenStackMachineSpec(i func autoConvert_v1beta1_OpenStackMachineSpec_To_v1alpha6_OpenStackMachineSpec(in *v1beta1.OpenStackMachineSpec, out *OpenStackMachineSpec, s conversion.Scope) error { out.ProviderID = (*string)(unsafe.Pointer(in.ProviderID)) - out.InstanceID = (*string)(unsafe.Pointer(in.InstanceID)) out.Flavor = in.Flavor // WARNING: in.Image requires manual conversion: inconvertible types (sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1.ImageFilter vs string) out.SSHKeyName = in.SSHKeyName @@ -1231,27 +1220,22 @@ func autoConvert_v1beta1_OpenStackMachineSpec_To_v1alpha6_OpenStackMachineSpec(i func autoConvert_v1alpha6_OpenStackMachineStatus_To_v1beta1_OpenStackMachineStatus(in *OpenStackMachineStatus, out *v1beta1.OpenStackMachineStatus, s conversion.Scope) error { out.Ready = in.Ready out.Addresses = *(*[]corev1.NodeAddress)(unsafe.Pointer(&in.Addresses)) - out.InstanceState = (*v1beta1.InstanceState)(unsafe.Pointer(in.InstanceState)) + // WARNING: in.InstanceState requires manual conversion: does not exist in peer-type out.FailureReason = (*errors.MachineStatusError)(unsafe.Pointer(in.FailureReason)) out.FailureMessage = (*string)(unsafe.Pointer(in.FailureMessage)) out.Conditions = *(*apiv1beta1.Conditions)(unsafe.Pointer(&in.Conditions)) return nil } -// Convert_v1alpha6_OpenStackMachineStatus_To_v1beta1_OpenStackMachineStatus is an autogenerated conversion function. -func Convert_v1alpha6_OpenStackMachineStatus_To_v1beta1_OpenStackMachineStatus(in *OpenStackMachineStatus, out *v1beta1.OpenStackMachineStatus, s conversion.Scope) error { - return autoConvert_v1alpha6_OpenStackMachineStatus_To_v1beta1_OpenStackMachineStatus(in, out, s) -} - func autoConvert_v1beta1_OpenStackMachineStatus_To_v1alpha6_OpenStackMachineStatus(in *v1beta1.OpenStackMachineStatus, out *OpenStackMachineStatus, s conversion.Scope) error { out.Ready = in.Ready out.Addresses = *(*[]corev1.NodeAddress)(unsafe.Pointer(&in.Addresses)) - out.InstanceState = (*InstanceState)(unsafe.Pointer(in.InstanceState)) // WARNING: in.Resolved requires manual conversion: does not exist in peer-type // WARNING: in.Resources requires manual conversion: does not exist in peer-type out.FailureReason = (*errors.MachineStatusError)(unsafe.Pointer(in.FailureReason)) out.FailureMessage = (*string)(unsafe.Pointer(in.FailureMessage)) out.Conditions = *(*apiv1beta1.Conditions)(unsafe.Pointer(&in.Conditions)) + // WARNING: in.Server requires manual conversion: does not exist in peer-type return nil } diff --git a/api/v1alpha7/conversion_test.go b/api/v1alpha7/conversion_test.go index a2c770984f..f4eba0364c 100644 --- a/api/v1alpha7/conversion_test.go +++ b/api/v1alpha7/conversion_test.go @@ -312,7 +312,10 @@ func TestMachineConversionControllerSpecFields(t *testing.T) { { name: "Set InstanceID", modifyUp: func(up *infrav1.OpenStackMachine) { - up.Spec.InstanceID = pointer.String("new-instance-id") + up.Status.Server = &infrav1.ServerStatus{ + ID: "new-instance-id", + State: "ACTIVE", + } }, testAfter: func(after *OpenStackMachine) { g.Expect(after.Spec.InstanceID).To(gomega.Equal(pointer.String("new-instance-id"))) diff --git a/api/v1alpha7/openstackcluster_conversion.go b/api/v1alpha7/openstackcluster_conversion.go index 3defae462a..f9862d0fac 100644 --- a/api/v1alpha7/openstackcluster_conversion.go +++ b/api/v1alpha7/openstackcluster_conversion.go @@ -342,9 +342,15 @@ func Convert_v1beta1_OpenStackClusterSpec_To_v1alpha7_OpenStackClusterSpec(in *i /* OpenStackClusterStatus */ func restorev1alpha7ClusterStatus(previous *OpenStackClusterStatus, dst *OpenStackClusterStatus) { + if previous == nil || dst == nil { + return + } + restorev1alpha7SecurityGroup(previous.ControlPlaneSecurityGroup, dst.ControlPlaneSecurityGroup) restorev1alpha7SecurityGroup(previous.WorkerSecurityGroup, dst.WorkerSecurityGroup) restorev1alpha7SecurityGroup(previous.BastionSecurityGroup, dst.BastionSecurityGroup) + + restorev1alpha7BastionStatus(previous.Bastion, dst.Bastion) } func restorev1beta1ClusterStatus(previous *infrav1.OpenStackClusterStatus, dst *infrav1.OpenStackClusterStatus) { @@ -362,20 +368,21 @@ func Convert_v1beta1_OpenStackClusterStatus_To_v1alpha7_OpenStackClusterStatus(i /* Bastion */ func restorev1alpha7Bastion(previous **Bastion, dst **Bastion) { - if *previous != nil && *dst != nil { - restorev1alpha7MachineSpec(&(*previous).Instance, &(*dst).Instance) + if *previous == nil || *dst == nil { + return } + restorev1alpha7MachineSpec(&(*previous).Instance, &(*dst).Instance) + (*dst).Instance.InstanceID = (*previous).Instance.InstanceID } func restorev1beta1Bastion(previous **infrav1.Bastion, dst **infrav1.Bastion) { - if *previous != nil { - if *dst != nil && (*previous).Spec != nil && (*dst).Spec != nil { - restorev1beta1MachineSpec((*previous).Spec, (*dst).Spec) - } - - optional.RestoreString(&(*previous).FloatingIP, &(*dst).FloatingIP) - optional.RestoreString(&(*previous).AvailabilityZone, &(*dst).AvailabilityZone) + if previous == nil || dst == nil || *previous == nil || *dst == nil { + return } + restorev1beta1MachineSpec((*previous).Spec, (*dst).Spec) + + optional.RestoreString(&(*previous).FloatingIP, &(*dst).FloatingIP) + optional.RestoreString(&(*previous).AvailabilityZone, &(*dst).AvailabilityZone) } func Convert_v1alpha7_Bastion_To_v1beta1_Bastion(in *Bastion, out *infrav1.Bastion, s apiconversion.Scope) error { @@ -441,9 +448,25 @@ func restorev1beta1BastionStatus(previous *infrav1.BastionStatus, dst *infrav1.B // Resolved and resources have no equivalents dst.Resolved = previous.Resolved dst.Resources = previous.Resources + dst.Server = previous.Server +} + +/* Bastion status */ + +func restorev1alpha7BastionStatus(previous *BastionStatus, dst *BastionStatus) { + if previous == nil || dst == nil { + return + } + + dst.ID = previous.ID + dst.SSHKeyName = previous.SSHKeyName + dst.State = previous.State +} + +func Convert_v1alpha7_BastionStatus_To_v1beta1_BastionStatus(in *BastionStatus, out *infrav1.BastionStatus, s apiconversion.Scope) error { + return autoConvert_v1alpha7_BastionStatus_To_v1beta1_BastionStatus(in, out, s) } func Convert_v1beta1_BastionStatus_To_v1alpha7_BastionStatus(in *infrav1.BastionStatus, out *BastionStatus, s apiconversion.Scope) error { - // ReferencedResources have no equivalent in v1alpha7 return autoConvert_v1beta1_BastionStatus_To_v1alpha7_BastionStatus(in, out, s) } diff --git a/api/v1alpha7/openstackmachine_conversion.go b/api/v1alpha7/openstackmachine_conversion.go index fa0655288c..edef2c2215 100644 --- a/api/v1alpha7/openstackmachine_conversion.go +++ b/api/v1alpha7/openstackmachine_conversion.go @@ -67,6 +67,12 @@ var v1alpha7OpenStackMachineRestorer = conversion.RestorerFor[*OpenStackMachine] }, restorev1alpha7MachineSpec, ), + "status": conversion.HashedFieldRestorer( + func(c *OpenStackMachine) *OpenStackMachineStatus { + return &c.Status + }, + restorev1alpha7MachineStatus, + ), } var v1beta1OpenStackMachineRestorer = conversion.RestorerFor[*infrav1.OpenStackMachine]{ @@ -89,6 +95,39 @@ var v1beta1OpenStackMachineRestorer = conversion.RestorerFor[*infrav1.OpenStackM ), } +/* OpenStackMachine */ + +func Convert_v1alpha7_OpenStackMachine_To_v1beta1_OpenStackMachine(in *OpenStackMachine, out *infrav1.OpenStackMachine, s apiconversion.Scope) error { + if err := autoConvert_v1alpha7_OpenStackMachine_To_v1beta1_OpenStackMachine(in, out, s); err != nil { + return err + } + + if in.Spec.InstanceID != nil { + serverStatus := &infrav1.ServerStatus{ + ID: *in.Spec.InstanceID, + } + if in.Status.InstanceState != nil { + serverStatus.State = (infrav1.InstanceState)(*in.Status.InstanceState) + } + out.Status.Server = serverStatus + } + return nil +} + +func Convert_v1beta1_OpenStackMachine_To_v1alpha7_OpenStackMachine(in *infrav1.OpenStackMachine, out *OpenStackMachine, s apiconversion.Scope) error { + if err := autoConvert_v1beta1_OpenStackMachine_To_v1alpha7_OpenStackMachine(in, out, s); err != nil { + return err + } + + if in.Status.Server != nil { + out.Spec.InstanceID = &in.Status.Server.ID + state := InstanceState(in.Status.Server.State) + out.Status.InstanceState = &state + } + + return nil +} + /* OpenStackMachineSpec */ func restorev1alpha7MachineSpec(previous *OpenStackMachineSpec, dst *OpenStackMachineSpec) { @@ -137,6 +176,10 @@ func restorev1alpha7MachineSpec(previous *OpenStackMachineSpec, dst *OpenStackMa } func restorev1beta1MachineSpec(previous *infrav1.OpenStackMachineSpec, dst *infrav1.OpenStackMachineSpec) { + if previous == nil || dst == nil { + return + } + dst.ServerGroup = previous.ServerGroup dst.Image = previous.Image @@ -232,7 +275,16 @@ func Convert_v1beta1_OpenStackMachineSpec_To_v1alpha7_OpenStackMachineSpec(in *i /* OpenStackMachineStatus */ +func restorev1alpha7MachineStatus(previous *OpenStackMachineStatus, dst *OpenStackMachineStatus) { + if dst.InstanceState == nil || *dst.InstanceState == "" { + dst.InstanceState = previous.InstanceState + } +} + +func Convert_v1alpha7_OpenStackMachineStatus_To_v1beta1_OpenStackMachineStatus(in *OpenStackMachineStatus, out *infrav1.OpenStackMachineStatus, s apiconversion.Scope) error { + return autoConvert_v1alpha7_OpenStackMachineStatus_To_v1beta1_OpenStackMachineStatus(in, out, s) +} + func Convert_v1beta1_OpenStackMachineStatus_To_v1alpha7_OpenStackMachineStatus(in *infrav1.OpenStackMachineStatus, out *OpenStackMachineStatus, s apiconversion.Scope) error { - // ReferencedResources have no equivalent in v1alpha7 return autoConvert_v1beta1_OpenStackMachineStatus_To_v1alpha7_OpenStackMachineStatus(in, out, s) } diff --git a/api/v1alpha7/openstackmachinetemplate_conversion.go b/api/v1alpha7/openstackmachinetemplate_conversion.go index f110066467..0e68f8ff43 100644 --- a/api/v1alpha7/openstackmachinetemplate_conversion.go +++ b/api/v1alpha7/openstackmachinetemplate_conversion.go @@ -79,4 +79,6 @@ var v1beta1OpenStackMachineTemplateRestorer = conversion.RestorerFor[*infrav1.Op func restorev1alpha7MachineTemplateSpec(previous *OpenStackMachineTemplateSpec, dst *OpenStackMachineTemplateSpec) { restorev1alpha7MachineSpec(&previous.Template.Spec, &dst.Template.Spec) + + dst.Template.Spec.InstanceID = previous.Template.Spec.InstanceID } diff --git a/api/v1alpha7/zz_generated.conversion.go b/api/v1alpha7/zz_generated.conversion.go index 5646dbe6f8..71f64eed75 100644 --- a/api/v1alpha7/zz_generated.conversion.go +++ b/api/v1alpha7/zz_generated.conversion.go @@ -71,11 +71,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*BastionStatus)(nil), (*v1beta1.BastionStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha7_BastionStatus_To_v1beta1_BastionStatus(a.(*BastionStatus), b.(*v1beta1.BastionStatus), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*BindingProfile)(nil), (*v1beta1.BindingProfile)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha7_BindingProfile_To_v1beta1_BindingProfile(a.(*BindingProfile), b.(*v1beta1.BindingProfile), scope) }); err != nil { @@ -221,16 +216,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*OpenStackMachine)(nil), (*v1beta1.OpenStackMachine)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha7_OpenStackMachine_To_v1beta1_OpenStackMachine(a.(*OpenStackMachine), b.(*v1beta1.OpenStackMachine), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*v1beta1.OpenStackMachine)(nil), (*OpenStackMachine)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1beta1_OpenStackMachine_To_v1alpha7_OpenStackMachine(a.(*v1beta1.OpenStackMachine), b.(*OpenStackMachine), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*OpenStackMachineList)(nil), (*v1beta1.OpenStackMachineList)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha7_OpenStackMachineList_To_v1beta1_OpenStackMachineList(a.(*OpenStackMachineList), b.(*v1beta1.OpenStackMachineList), scope) }); err != nil { @@ -241,11 +226,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*OpenStackMachineStatus)(nil), (*v1beta1.OpenStackMachineStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha7_OpenStackMachineStatus_To_v1beta1_OpenStackMachineStatus(a.(*OpenStackMachineStatus), b.(*v1beta1.OpenStackMachineStatus), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*OpenStackMachineTemplate)(nil), (*v1beta1.OpenStackMachineTemplate)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha7_OpenStackMachineTemplate_To_v1beta1_OpenStackMachineTemplate(a.(*OpenStackMachineTemplate), b.(*v1beta1.OpenStackMachineTemplate), scope) }); err != nil { @@ -326,6 +306,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*BastionStatus)(nil), (*v1beta1.BastionStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha7_BastionStatus_To_v1beta1_BastionStatus(a.(*BastionStatus), b.(*v1beta1.BastionStatus), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*Bastion)(nil), (*v1beta1.Bastion)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha7_Bastion_To_v1beta1_Bastion(a.(*Bastion), b.(*v1beta1.Bastion), scope) }); err != nil { @@ -351,6 +336,16 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*OpenStackMachineStatus)(nil), (*v1beta1.OpenStackMachineStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha7_OpenStackMachineStatus_To_v1beta1_OpenStackMachineStatus(a.(*OpenStackMachineStatus), b.(*v1beta1.OpenStackMachineStatus), scope) + }); err != nil { + return err + } + if err := s.AddConversionFunc((*OpenStackMachine)(nil), (*v1beta1.OpenStackMachine)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha7_OpenStackMachine_To_v1beta1_OpenStackMachine(a.(*OpenStackMachine), b.(*v1beta1.OpenStackMachine), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*PortOpts)(nil), (*v1beta1.PortOpts)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha7_PortOpts_To_v1beta1_PortOpts(a.(*PortOpts), b.(*v1beta1.PortOpts), scope) }); err != nil { @@ -416,6 +411,11 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddConversionFunc((*v1beta1.OpenStackMachine)(nil), (*OpenStackMachine)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_OpenStackMachine_To_v1alpha7_OpenStackMachine(a.(*v1beta1.OpenStackMachine), b.(*OpenStackMachine), scope) + }); err != nil { + return err + } if err := s.AddConversionFunc((*v1beta1.PortOpts)(nil), (*PortOpts)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1beta1_PortOpts_To_v1alpha7_PortOpts(a.(*v1beta1.PortOpts), b.(*PortOpts), scope) }); err != nil { @@ -552,29 +552,22 @@ func autoConvert_v1beta1_Bastion_To_v1alpha7_Bastion(in *v1beta1.Bastion, out *B } func autoConvert_v1alpha7_BastionStatus_To_v1beta1_BastionStatus(in *BastionStatus, out *v1beta1.BastionStatus, s conversion.Scope) error { - out.ID = in.ID + // WARNING: in.ID requires manual conversion: does not exist in peer-type out.Name = in.Name - out.SSHKeyName = in.SSHKeyName - out.State = v1beta1.InstanceState(in.State) + // WARNING: in.SSHKeyName requires manual conversion: does not exist in peer-type + // WARNING: in.State requires manual conversion: does not exist in peer-type out.IP = in.IP out.FloatingIP = in.FloatingIP return nil } -// Convert_v1alpha7_BastionStatus_To_v1beta1_BastionStatus is an autogenerated conversion function. -func Convert_v1alpha7_BastionStatus_To_v1beta1_BastionStatus(in *BastionStatus, out *v1beta1.BastionStatus, s conversion.Scope) error { - return autoConvert_v1alpha7_BastionStatus_To_v1beta1_BastionStatus(in, out, s) -} - func autoConvert_v1beta1_BastionStatus_To_v1alpha7_BastionStatus(in *v1beta1.BastionStatus, out *BastionStatus, s conversion.Scope) error { - out.ID = in.ID out.Name = in.Name - out.SSHKeyName = in.SSHKeyName - out.State = InstanceState(in.State) out.IP = in.IP out.FloatingIP = in.FloatingIP // WARNING: in.Resolved requires manual conversion: does not exist in peer-type // WARNING: in.Resources requires manual conversion: does not exist in peer-type + // WARNING: in.Server requires manual conversion: does not exist in peer-type return nil } @@ -1267,11 +1260,6 @@ func autoConvert_v1alpha7_OpenStackMachine_To_v1beta1_OpenStackMachine(in *OpenS return nil } -// Convert_v1alpha7_OpenStackMachine_To_v1beta1_OpenStackMachine is an autogenerated conversion function. -func Convert_v1alpha7_OpenStackMachine_To_v1beta1_OpenStackMachine(in *OpenStackMachine, out *v1beta1.OpenStackMachine, s conversion.Scope) error { - return autoConvert_v1alpha7_OpenStackMachine_To_v1beta1_OpenStackMachine(in, out, s) -} - func autoConvert_v1beta1_OpenStackMachine_To_v1alpha7_OpenStackMachine(in *v1beta1.OpenStackMachine, out *OpenStackMachine, s conversion.Scope) error { out.ObjectMeta = in.ObjectMeta if err := Convert_v1beta1_OpenStackMachineSpec_To_v1alpha7_OpenStackMachineSpec(&in.Spec, &out.Spec, s); err != nil { @@ -1283,11 +1271,6 @@ func autoConvert_v1beta1_OpenStackMachine_To_v1alpha7_OpenStackMachine(in *v1bet return nil } -// Convert_v1beta1_OpenStackMachine_To_v1alpha7_OpenStackMachine is an autogenerated conversion function. -func Convert_v1beta1_OpenStackMachine_To_v1alpha7_OpenStackMachine(in *v1beta1.OpenStackMachine, out *OpenStackMachine, s conversion.Scope) error { - return autoConvert_v1beta1_OpenStackMachine_To_v1alpha7_OpenStackMachine(in, out, s) -} - func autoConvert_v1alpha7_OpenStackMachineList_To_v1beta1_OpenStackMachineList(in *OpenStackMachineList, out *v1beta1.OpenStackMachineList, s conversion.Scope) error { out.ListMeta = in.ListMeta if in.Items != nil { @@ -1332,7 +1315,7 @@ func Convert_v1beta1_OpenStackMachineList_To_v1alpha7_OpenStackMachineList(in *v func autoConvert_v1alpha7_OpenStackMachineSpec_To_v1beta1_OpenStackMachineSpec(in *OpenStackMachineSpec, out *v1beta1.OpenStackMachineSpec, s conversion.Scope) error { out.ProviderID = (*string)(unsafe.Pointer(in.ProviderID)) - out.InstanceID = (*string)(unsafe.Pointer(in.InstanceID)) + // WARNING: in.InstanceID requires manual conversion: does not exist in peer-type // WARNING: in.CloudName requires manual conversion: does not exist in peer-type out.Flavor = in.Flavor // WARNING: in.Image requires manual conversion: inconvertible types (string vs sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1.ImageFilter) @@ -1382,7 +1365,6 @@ func autoConvert_v1alpha7_OpenStackMachineSpec_To_v1beta1_OpenStackMachineSpec(i func autoConvert_v1beta1_OpenStackMachineSpec_To_v1alpha7_OpenStackMachineSpec(in *v1beta1.OpenStackMachineSpec, out *OpenStackMachineSpec, s conversion.Scope) error { out.ProviderID = (*string)(unsafe.Pointer(in.ProviderID)) - out.InstanceID = (*string)(unsafe.Pointer(in.InstanceID)) out.Flavor = in.Flavor // WARNING: in.Image requires manual conversion: inconvertible types (sigs.k8s.io/cluster-api-provider-openstack/api/v1beta1.ImageFilter vs string) out.SSHKeyName = in.SSHKeyName @@ -1431,27 +1413,22 @@ func autoConvert_v1beta1_OpenStackMachineSpec_To_v1alpha7_OpenStackMachineSpec(i func autoConvert_v1alpha7_OpenStackMachineStatus_To_v1beta1_OpenStackMachineStatus(in *OpenStackMachineStatus, out *v1beta1.OpenStackMachineStatus, s conversion.Scope) error { out.Ready = in.Ready out.Addresses = *(*[]corev1.NodeAddress)(unsafe.Pointer(&in.Addresses)) - out.InstanceState = (*v1beta1.InstanceState)(unsafe.Pointer(in.InstanceState)) + // WARNING: in.InstanceState requires manual conversion: does not exist in peer-type out.FailureReason = (*errors.MachineStatusError)(unsafe.Pointer(in.FailureReason)) out.FailureMessage = (*string)(unsafe.Pointer(in.FailureMessage)) out.Conditions = *(*apiv1beta1.Conditions)(unsafe.Pointer(&in.Conditions)) return nil } -// Convert_v1alpha7_OpenStackMachineStatus_To_v1beta1_OpenStackMachineStatus is an autogenerated conversion function. -func Convert_v1alpha7_OpenStackMachineStatus_To_v1beta1_OpenStackMachineStatus(in *OpenStackMachineStatus, out *v1beta1.OpenStackMachineStatus, s conversion.Scope) error { - return autoConvert_v1alpha7_OpenStackMachineStatus_To_v1beta1_OpenStackMachineStatus(in, out, s) -} - func autoConvert_v1beta1_OpenStackMachineStatus_To_v1alpha7_OpenStackMachineStatus(in *v1beta1.OpenStackMachineStatus, out *OpenStackMachineStatus, s conversion.Scope) error { out.Ready = in.Ready out.Addresses = *(*[]corev1.NodeAddress)(unsafe.Pointer(&in.Addresses)) - out.InstanceState = (*InstanceState)(unsafe.Pointer(in.InstanceState)) // WARNING: in.Resolved requires manual conversion: does not exist in peer-type // WARNING: in.Resources requires manual conversion: does not exist in peer-type out.FailureReason = (*errors.MachineStatusError)(unsafe.Pointer(in.FailureReason)) out.FailureMessage = (*string)(unsafe.Pointer(in.FailureMessage)) out.Conditions = *(*apiv1beta1.Conditions)(unsafe.Pointer(&in.Conditions)) + // WARNING: in.Server requires manual conversion: does not exist in peer-type return nil } diff --git a/api/v1beta1/openstackmachine_types.go b/api/v1beta1/openstackmachine_types.go index f222f71761..0522205482 100644 --- a/api/v1beta1/openstackmachine_types.go +++ b/api/v1beta1/openstackmachine_types.go @@ -33,12 +33,11 @@ const ( // OpenStackMachineSpec defines the desired state of OpenStackMachine. type OpenStackMachineSpec struct { - // ProviderID is the unique identifier as specified by the cloud provider. + // ProviderID is a unique identifier for this machine of the form `openstack://`. + // Note that it is set by the OpenStackMachine controller, and should not be set by the user. + // +optional ProviderID *string `json:"providerID,omitempty"` - // InstanceID is the OpenStack instance ID for this machine. - InstanceID *string `json:"instanceID,omitempty"` - // The flavor reference for the flavor for your server instance. Flavor string `json:"flavor"` @@ -122,10 +121,6 @@ type OpenStackMachineStatus struct { // Addresses contains the OpenStack instance associated addresses. Addresses []corev1.NodeAddress `json:"addresses,omitempty"` - // InstanceState is the state of the OpenStack instance for this machine. - // +optional - InstanceState *InstanceState `json:"instanceState,omitempty"` - // Resolved contains parts of the machine spec with all external // references fully resolved. // +optional @@ -157,6 +152,10 @@ type OpenStackMachineStatus struct { FailureMessage *string `json:"failureMessage,omitempty"` Conditions clusterv1.Conditions `json:"conditions,omitempty"` + + // Server describes the OpenStack server created for the machine + // +optional + Server *ServerStatus `json:"server,omitempty"` } // +genclient @@ -166,9 +165,9 @@ type OpenStackMachineStatus struct { // +kubebuilder:resource:path=openstackmachines,scope=Namespaced,categories=cluster-api,shortName=osm // +kubebuilder:subresource:status // +kubebuilder:printcolumn:name="Cluster",type="string",JSONPath=".metadata.labels.cluster\\.x-k8s\\.io/cluster-name",description="Cluster to which this OpenStackMachine belongs" -// +kubebuilder:printcolumn:name="InstanceState",type="string",JSONPath=".status.instanceState",description="OpenStack instance state" +// +kubebuilder:printcolumn:name="ServerID",type="string",JSONPath=".status.resources.server.id",description="OpenStack instance ID" +// +kubebuilder:printcolumn:name="InstanceState",type="string",JSONPath=".status.resources.server.state",description="OpenStack instance state" // +kubebuilder:printcolumn:name="Ready",type="string",JSONPath=".status.ready",description="Machine ready status" -// +kubebuilder:printcolumn:name="ProviderID",type="string",JSONPath=".spec.providerID",description="OpenStack instance ID" // +kubebuilder:printcolumn:name="Machine",type="string",JSONPath=".metadata.ownerReferences[?(@.kind==\"Machine\")].name",description="Machine object which owns with this OpenStackMachine" // +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp",description="Time duration since creation of OpenStackMachine" diff --git a/api/v1beta1/types.go b/api/v1beta1/types.go index d2d90d8f6e..78758392f3 100644 --- a/api/v1beta1/types.go +++ b/api/v1beta1/types.go @@ -358,12 +358,9 @@ type AddressPair struct { } type BastionStatus struct { - ID string `json:"id,omitempty"` - Name string `json:"name,omitempty"` - SSHKeyName string `json:"sshKeyName,omitempty"` - State InstanceState `json:"state,omitempty"` - IP string `json:"ip,omitempty"` - FloatingIP string `json:"floatingIP,omitempty"` + Name string `json:"name,omitempty"` + IP string `json:"ip,omitempty"` + FloatingIP string `json:"floatingIP,omitempty"` // Resolved contains parts of the bastion's machine spec with all // external references fully resolved. @@ -373,6 +370,10 @@ type BastionStatus struct { // Resources contains references to OpenStack resources created for the bastion. // +optional Resources *MachineResources `json:"resources,omitempty"` + + // Server describes the OpenStack server created for the bastion + // +optional + Server *ServerStatus `json:"server,omitempty"` } type RootVolume struct { @@ -686,6 +687,31 @@ type MachineResources struct { Ports []PortStatus `json:"ports,omitempty"` } +func (r *OpenStackMachineStatus) GetServerID() *string { + if r == nil || r.Server == nil { + return nil + } + return &r.Server.ID +} + +func (r *BastionStatus) GetServerID() *string { + if r == nil || r.Server == nil { + return nil + } + return &r.Server.ID +} + +type ServerStatus struct { + // ID is the uuid of the server + // +kubebuilder:validation:Required + ID string `json:"id"` + + // State is a previously observed state of the server + // Do not rely on this field to be up to date + // +kubebuilder:validation:Required + State InstanceState `json:"state"` +} + // ValueSpec represents a single value_spec key-value pair. type ValueSpec struct { // Name is the name of the key-value pair. diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index b5d80bafff..420f402bfb 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -156,6 +156,11 @@ func (in *BastionStatus) DeepCopyInto(out *BastionStatus) { *out = new(MachineResources) (*in).DeepCopyInto(*out) } + if in.Server != nil { + in, out := &in.Server, &out.Server + *out = new(ServerStatus) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BastionStatus. @@ -885,11 +890,6 @@ func (in *OpenStackMachineSpec) DeepCopyInto(out *OpenStackMachineSpec) { *out = new(string) **out = **in } - if in.InstanceID != nil { - in, out := &in.InstanceID, &out.InstanceID - *out = new(string) - **out = **in - } in.Image.DeepCopyInto(&out.Image) if in.Ports != nil { in, out := &in.Ports, &out.Ports @@ -967,11 +967,6 @@ func (in *OpenStackMachineStatus) DeepCopyInto(out *OpenStackMachineStatus) { *out = make([]v1.NodeAddress, len(*in)) copy(*out, *in) } - if in.InstanceState != nil { - in, out := &in.InstanceState, &out.InstanceState - *out = new(InstanceState) - **out = **in - } if in.Resolved != nil { in, out := &in.Resolved, &out.Resolved *out = new(ResolvedMachineSpec) @@ -999,6 +994,11 @@ func (in *OpenStackMachineStatus) DeepCopyInto(out *OpenStackMachineStatus) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.Server != nil { + in, out := &in.Server, &out.Server + *out = new(ServerStatus) + **out = **in + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OpenStackMachineStatus. @@ -1490,6 +1490,21 @@ func (in *ServerMetadata) DeepCopy() *ServerMetadata { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ServerStatus) DeepCopyInto(out *ServerStatus) { + *out = *in +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServerStatus. +func (in *ServerStatus) DeepCopy() *ServerStatus { + if in == nil { + return nil + } + out := new(ServerStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Subnet) DeepCopyInto(out *Subnet) { *out = *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 4aa7ca14b0..6065d4450f 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclusters.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclusters.yaml @@ -5075,10 +5075,6 @@ spec: - message: when ID is set you cannot set other options rule: (has(self.id) && !has(self.name) && !has(self.tags)) || !has(self.id) - instanceID: - description: InstanceID is the OpenStack instance ID for this - machine. - type: string ports: description: |- Ports to be attached to the server instance. They are created if a port with the given name does not already exist. @@ -5448,8 +5444,9 @@ spec: type: object type: array providerID: - description: ProviderID is the unique identifier as specified - by the cloud provider. + description: |- + ProviderID is a unique identifier for this machine of the form `openstack://`. + Note that it is set by the OpenStackMachine controller, and should not be set by the user. type: string rootVolume: description: The volume metadata to boot from @@ -6244,8 +6241,6 @@ spec: properties: floatingIP: type: string - id: - type: string ip: type: string name: @@ -6452,12 +6447,22 @@ spec: type: object type: array type: object - sshKeyName: - type: string - state: - description: InstanceState describes the state of an OpenStack - instance. - type: string + server: + description: Server describes the OpenStack server created for + the bastion + properties: + id: + description: ID is the uuid of the server + type: string + state: + description: |- + State is a previously observed state of the server + Do not rely on this field to be up to date + type: string + required: + - id + - state + type: object type: object bastionSecurityGroup: description: |- 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 66b4e12174..800b09fc94 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclustertemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackclustertemplates.yaml @@ -2504,10 +2504,6 @@ spec: - message: when ID is set you cannot set other options rule: (has(self.id) && !has(self.name) && !has(self.tags)) || !has(self.id) - instanceID: - description: InstanceID is the OpenStack instance - ID for this machine. - type: string ports: description: |- Ports to be attached to the server instance. They are created if a port with the given name does not already exist. @@ -2881,8 +2877,9 @@ spec: type: object type: array providerID: - description: ProviderID is the unique identifier as - specified by the cloud provider. + description: |- + ProviderID is a unique identifier for this machine of the form `openstack://`. + Note that it is set by the OpenStackMachine controller, and should not be set by the user. type: string rootVolume: description: The volume metadata to boot from 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 3d866edc37..c36f1cc909 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachines.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachines.yaml @@ -1672,18 +1672,18 @@ spec: jsonPath: .metadata.labels.cluster\.x-k8s\.io/cluster-name name: Cluster type: string + - description: OpenStack instance ID + jsonPath: .status.resources.server.id + name: ServerID + type: string - description: OpenStack instance state - jsonPath: .status.instanceState + jsonPath: .status.resources.server.state name: InstanceState type: string - description: Machine ready status jsonPath: .status.ready name: Ready type: string - - description: OpenStack instance ID - jsonPath: .spec.providerID - name: ProviderID - type: string - description: Machine object which owns with this OpenStackMachine jsonPath: .metadata.ownerReferences[?(@.kind=="Machine")].name name: Machine @@ -1854,9 +1854,6 @@ spec: x-kubernetes-validations: - message: when ID is set you cannot set other options rule: (has(self.id) && !has(self.name) && !has(self.tags)) || !has(self.id) - instanceID: - description: InstanceID is the OpenStack instance ID for this machine. - type: string ports: description: |- Ports to be attached to the server instance. They are created if a port with the given name does not already exist. @@ -2224,8 +2221,9 @@ spec: type: object type: array providerID: - description: ProviderID is the unique identifier as specified by the - cloud provider. + description: |- + ProviderID is a unique identifier for this machine of the form `openstack://`. + Note that it is set by the OpenStackMachine controller, and should not be set by the user. type: string rootVolume: description: The volume metadata to boot from @@ -2446,10 +2444,6 @@ spec: description: MachineStatusError defines errors states for Machine objects. type: string - instanceState: - description: InstanceState is the state of the OpenStack instance - for this machine. - type: string ready: description: Ready is true when the provider resource is ready. type: boolean @@ -2653,6 +2647,22 @@ spec: type: object type: array type: object + server: + description: Server describes the OpenStack server created for the + machine + properties: + id: + description: ID is the uuid of the server + type: string + state: + description: |- + State is a previously observed state of the server + Do not rely on this field to be up to date + type: string + required: + - id + - state + type: object type: object type: object served: true 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 12d3b1ea40..eec4cff865 100644 --- a/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachinetemplates.yaml +++ b/config/crd/bases/infrastructure.cluster.x-k8s.io_openstackmachinetemplates.yaml @@ -1529,10 +1529,6 @@ spec: - message: when ID is set you cannot set other options rule: (has(self.id) && !has(self.name) && !has(self.tags)) || !has(self.id) - instanceID: - description: InstanceID is the OpenStack instance ID for this - machine. - type: string ports: description: |- Ports to be attached to the server instance. They are created if a port with the given name does not already exist. @@ -1902,8 +1898,9 @@ spec: type: object type: array providerID: - description: ProviderID is the unique identifier as specified - by the cloud provider. + description: |- + ProviderID is a unique identifier for this machine of the form `openstack://`. + Note that it is set by the OpenStackMachine controller, and should not be set by the user. type: string rootVolume: description: The volume metadata to boot from diff --git a/controllers/openstackcluster_controller.go b/controllers/openstackcluster_controller.go index 1af03280f6..6ce2c97acb 100644 --- a/controllers/openstackcluster_controller.go +++ b/controllers/openstackcluster_controller.go @@ -269,18 +269,18 @@ func deleteBastion(scope *scope.WithLogger, cluster *clusterv1.Cluster, openStac return err } - if openStackCluster.Status.Bastion != nil && openStackCluster.Status.Bastion.FloatingIP != "" { + bastionStatus := openStackCluster.Status.Bastion + if bastionStatus != nil && bastionStatus.FloatingIP != "" { if err = networkingService.DeleteFloatingIP(openStackCluster, openStackCluster.Status.Bastion.FloatingIP); err != nil { handleUpdateOSCError(openStackCluster, fmt.Errorf("failed to delete floating IP: %w", err)) return fmt.Errorf("failed to delete floating IP: %w", err) } } - bastionStatus := openStackCluster.Status.Bastion - var instanceStatus *compute.InstanceStatus - if bastionStatus != nil && bastionStatus.ID != "" { - instanceStatus, err = computeService.GetInstanceStatus(openStackCluster.Status.Bastion.ID) + serverID := bastionStatus.GetServerID() + if bastionStatus != nil && serverID != nil { + instanceStatus, err = computeService.GetInstanceStatus(*serverID) if err != nil { return err } @@ -318,7 +318,7 @@ func deleteBastion(scope *scope.WithLogger, cluster *clusterv1.Cluster, openStac } } - if bastionStatus != nil && bastionStatus.Resources != nil { + if bastionStatus != nil && bastionStatus.Resources != nil && len(bastionStatus.Resources.Ports) > 1 { trunkSupported, err := networkingService.IsTrunkExtSupported() if err != nil { return err @@ -458,9 +458,12 @@ func reconcileBastion(scope *scope.WithLogger, cluster *clusterv1.Cluster, openS bastionPortIDs := GetPortIDs(openStackCluster.Status.Bastion.Resources.Ports) var instanceStatus *compute.InstanceStatus - if openStackCluster.Status.Bastion != nil && openStackCluster.Status.Bastion.ID != "" { - if instanceStatus, err = computeService.GetInstanceStatus(openStackCluster.Status.Bastion.ID); err != nil { - return nil, err + bastionStatus := openStackCluster.Status.Bastion + if bastionStatus != nil { + if serverID := bastionStatus.GetServerID(); serverID != nil { + if instanceStatus, err = computeService.GetInstanceStatus(*serverID); err != nil { + return nil, err + } } } if instanceStatus == nil { @@ -477,6 +480,10 @@ func reconcileBastion(scope *scope.WithLogger, cluster *clusterv1.Cluster, openS } // Save hash & status as soon as we know we have an instance + openStackCluster.Status.Bastion.Server = &infrav1.ServerStatus{ + ID: instanceStatus.ID(), + State: instanceStatus.State(), + } instanceStatus.UpdateBastionStatus(openStackCluster) // Make sure that bastion instance has a valid state diff --git a/controllers/openstackcluster_controller_test.go b/controllers/openstackcluster_controller_test.go index 29cfd40a21..0b09d254e7 100644 --- a/controllers/openstackcluster_controller_test.go +++ b/controllers/openstackcluster_controller_test.go @@ -206,7 +206,10 @@ var _ = Describe("OpenStackCluster controller", func() { Expect(err).To(BeNil()) testCluster.Status = infrav1.OpenStackClusterStatus{ Bastion: &infrav1.BastionStatus{ - ID: "bastion-uuid", + Server: &infrav1.ServerStatus{ + ID: "bastion-uuid", + State: "ACTIVE", + }, }, } err = k8sClient.Status().Update(ctx, testCluster) @@ -284,8 +287,6 @@ var _ = Describe("OpenStackCluster controller", func() { res, err := reconcileBastion(scope, capiCluster, testCluster) expectedStatus := &infrav1.BastionStatus{ - ID: "adopted-bastion-uuid", - State: "ACTIVE", Resolved: &infrav1.ResolvedMachineSpec{ ImageID: "imageID", Ports: []infrav1.ResolvedPortSpec{ @@ -301,6 +302,10 @@ var _ = Describe("OpenStackCluster controller", func() { }, }, }, + Server: &infrav1.ServerStatus{ + ID: "adopted-bastion-uuid", + State: "ACTIVE", + }, } Expect(testCluster.Status.Bastion).To(Equal(expectedStatus), cmp.Diff(testCluster.Status.Bastion, expectedStatus)) Expect(err).To(BeNil()) @@ -326,7 +331,6 @@ var _ = Describe("OpenStackCluster controller", func() { }, }, Bastion: &infrav1.BastionStatus{ - ID: "adopted-fip-bastion-uuid", Resolved: &infrav1.ResolvedMachineSpec{ ImageID: "imageID", Ports: []infrav1.ResolvedPortSpec{ @@ -342,6 +346,9 @@ var _ = Describe("OpenStackCluster controller", func() { }, }, }, + Server: &infrav1.ServerStatus{ + ID: "adopted-fip-bastion-uuid", + }, }, } err = k8sClient.Status().Update(ctx, testCluster) @@ -366,9 +373,7 @@ var _ = Describe("OpenStackCluster controller", func() { res, err := reconcileBastion(scope, capiCluster, testCluster) Expect(testCluster.Status.Bastion).To(Equal(&infrav1.BastionStatus{ - ID: "adopted-fip-bastion-uuid", FloatingIP: "1.2.3.4", - State: "ACTIVE", Resolved: &infrav1.ResolvedMachineSpec{ ImageID: "imageID", Ports: []infrav1.ResolvedPortSpec{ @@ -384,6 +389,10 @@ var _ = Describe("OpenStackCluster controller", func() { }, }, }, + Server: &infrav1.ServerStatus{ + ID: "adopted-fip-bastion-uuid", + State: "ACTIVE", + }, })) Expect(err).To(BeNil()) Expect(res).To(BeNil()) @@ -408,7 +417,6 @@ var _ = Describe("OpenStackCluster controller", func() { }, }, Bastion: &infrav1.BastionStatus{ - ID: "requeue-bastion-uuid", Resolved: &infrav1.ResolvedMachineSpec{ ImageID: "imageID", Ports: []infrav1.ResolvedPortSpec{ @@ -424,6 +432,9 @@ var _ = Describe("OpenStackCluster controller", func() { }, }, }, + Server: &infrav1.ServerStatus{ + ID: "requeue-bastion-uuid", + }, }, } err = k8sClient.Status().Update(ctx, testCluster) @@ -443,8 +454,6 @@ var _ = Describe("OpenStackCluster controller", func() { res, err := reconcileBastion(scope, capiCluster, testCluster) Expect(testCluster.Status.Bastion).To(Equal(&infrav1.BastionStatus{ - ID: "requeue-bastion-uuid", - State: "BUILD", Resolved: &infrav1.ResolvedMachineSpec{ ImageID: "imageID", Ports: []infrav1.ResolvedPortSpec{ @@ -460,6 +469,10 @@ var _ = Describe("OpenStackCluster controller", func() { }, }, }, + Server: &infrav1.ServerStatus{ + ID: "requeue-bastion-uuid", + State: "BUILD", + }, })) Expect(err).To(BeNil()) Expect(res).To(Equal(&reconcile.Result{RequeueAfter: waitForBuildingInstanceToReconcile})) diff --git a/controllers/openstackmachine_controller.go b/controllers/openstackmachine_controller.go index 969ec5b61a..aba76744e9 100644 --- a/controllers/openstackmachine_controller.go +++ b/controllers/openstackmachine_controller.go @@ -277,8 +277,8 @@ func (r *OpenStackMachineReconciler) reconcileDelete(scope *scope.WithLogger, cl } var instanceStatus *compute.InstanceStatus - if openStackMachine.Spec.InstanceID != nil { - instanceStatus, err = computeService.GetInstanceStatus(*openStackMachine.Spec.InstanceID) + if openStackMachine.Status.Server != nil { + instanceStatus, err = computeService.GetInstanceStatus(openStackMachine.Status.Server.ID) if err != nil { return ctrl.Result{}, err } @@ -548,10 +548,10 @@ func (r *OpenStackMachineReconciler) reconcileNormal(ctx context.Context, scope // TODO(sbueringer) From CAPA: TODO(ncdc): move this validation logic into a validating webhook (for us: create validation logic in webhook) openStackMachine.Spec.ProviderID = pointer.String(fmt.Sprintf("openstack:///%s", instanceStatus.ID())) - openStackMachine.Spec.InstanceID = pointer.String(instanceStatus.ID()) - - state := instanceStatus.State() - openStackMachine.Status.InstanceState = &state + openStackMachine.Status.Server = &infrav1.ServerStatus{ + ID: instanceStatus.ID(), + State: instanceStatus.State(), + } instanceNS, err := instanceStatus.NetworkStatus() if err != nil { @@ -700,10 +700,11 @@ func getOrCreateMachinePorts(openStackMachine *infrav1.OpenStackMachine, network func (r *OpenStackMachineReconciler) getOrCreateInstance(logger logr.Logger, openStackCluster *infrav1.OpenStackCluster, machine *clusterv1.Machine, openStackMachine *infrav1.OpenStackMachine, computeService *compute.Service, userData string, portIDs []string) (*compute.InstanceStatus, error) { var instanceStatus *compute.InstanceStatus var err error - if openStackMachine.Spec.InstanceID != nil { - instanceStatus, err = computeService.GetInstanceStatus(*openStackMachine.Spec.InstanceID) + if openStackMachine.Status.Server != nil { + serverID := openStackMachine.Status.Server.ID + instanceStatus, err = computeService.GetInstanceStatus(serverID) if err != nil { - logger.Info("Unable to get OpenStack instance", "name", openStackMachine.Name) + logger.Info("Unable to get OpenStack instance", "name", openStackMachine.Name, "id", serverID) conditions.MarkFalse(openStackMachine, infrav1.InstanceReadyCondition, infrav1.OpenStackErrorReason, clusterv1.ConditionSeverityError, err.Error()) return nil, err } @@ -714,7 +715,7 @@ func (r *OpenStackMachineReconciler) getOrCreateInstance(logger logr.Logger, ope if instanceStatus != nil { return instanceStatus, nil } - if openStackMachine.Spec.InstanceID != nil { + if openStackMachine.Status.Server != nil { logger.Info("Not reconciling machine in failed state. The previously existing OpenStack instance is no longer available") conditions.MarkFalse(openStackMachine, infrav1.InstanceReadyCondition, infrav1.InstanceNotFoundReason, clusterv1.ConditionSeverityError, "virtual machine no longer exists") openStackMachine.SetFailure(capierrors.UpdateMachineError, errors.New("virtual machine no longer exists")) diff --git a/controllers/suite_test.go b/controllers/suite_test.go index 0a49b42403..2c058c20e2 100644 --- a/controllers/suite_test.go +++ b/controllers/suite_test.go @@ -31,7 +31,6 @@ import ( "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/rest" - "k8s.io/utils/pointer" clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1" "sigs.k8s.io/cluster-api/test/framework" "sigs.k8s.io/controller-runtime/pkg/client" @@ -149,8 +148,11 @@ var _ = Describe("When calling getOrCreate", func() { openStackCluster := &infrav1.OpenStackCluster{} machine := &clusterv1.Machine{} openStackMachine := &infrav1.OpenStackMachine{ - Spec: infrav1.OpenStackMachineSpec{ - InstanceID: pointer.String("machine-uuid"), + Status: infrav1.OpenStackMachineStatus{ + Server: &infrav1.ServerStatus{ + ID: "machine-uuid", + State: "ACTIVE", + }, }, } diff --git a/docs/book/src/api/v1beta1/api.md b/docs/book/src/api/v1beta1/api.md index c60863aaf2..30b0b2e04f 100644 --- a/docs/book/src/api/v1beta1/api.md +++ b/docs/book/src/api/v1beta1/api.md @@ -558,18 +558,9 @@ string -

ProviderID is the unique identifier as specified by the cloud provider.

- - - - -instanceID
- -string - - - -

InstanceID is the OpenStack instance ID for this machine.

+(Optional) +

ProviderID is a unique identifier for this machine of the form openstack://<server_id>. +Note that it is set by the OpenStackMachine controller, and should not be set by the user.

@@ -1150,16 +1141,6 @@ exist, CAPO will try to create it, but by default only OpenStack administrators -id
- -string - - - - - - - name
string @@ -1170,28 +1151,6 @@ string -sshKeyName
- -string - - - - - - - -state
- - -InstanceState - - - - - - - - ip
string @@ -1239,6 +1198,20 @@ MachineResources

Resources contains references to OpenStack resources created for the bastion.

+ + +server
+ + +ServerStatus + + + + +(Optional) +

Server describes the OpenStack server created for the bastion

+ +

BindingProfile @@ -1635,8 +1608,7 @@ string (string alias)

(Appears on: -BastionStatus, -OpenStackMachineStatus) +ServerStatus)

InstanceState describes the state of an OpenStack instance.

@@ -3036,18 +3008,9 @@ string
-

ProviderID is the unique identifier as specified by the cloud provider.

- - - - -instanceID
- -string - - - -

InstanceID is the OpenStack instance ID for this machine.

+(Optional) +

ProviderID is a unique identifier for this machine of the form openstack://<server_id>. +Note that it is set by the OpenStackMachine controller, and should not be set by the user.

@@ -3277,20 +3240,6 @@ bool -instanceState
- - -InstanceState - - - - -(Optional) -

InstanceState is the state of the OpenStack instance for this machine.

- - - - resolved
@@ -3367,6 +3316,20 @@ sigs.k8s.io/cluster-api/api/v1beta1.Conditions + + +server
+ +
+ServerStatus + + + + +(Optional) +

Server describes the OpenStack server created for the machine

+ +

OpenStackMachineTemplateResource @@ -3408,18 +3371,9 @@ string -

ProviderID is the unique identifier as specified by the cloud provider.

- - - - -instanceID
- -string - - - -

InstanceID is the OpenStack instance ID for this machine.

+(Optional) +

ProviderID is a unique identifier for this machine of the form openstack://<server_id>. +Note that it is set by the OpenStackMachine controller, and should not be set by the user.

@@ -4704,6 +4658,50 @@ string +

ServerStatus +

+

+(Appears on: +BastionStatus, +OpenStackMachineStatus) +

+

+

+ + + + + + + + + + + + + + + + + +
FieldDescription
+id
+ +string + +
+

ID is the uuid of the server

+
+state
+ + +InstanceState + + +
+

State is a previously observed state of the server +Do not rely on this field to be up to date

+

Subnet

diff --git a/docs/book/src/development/development.md b/docs/book/src/development/development.md index 661ac84ec6..fd44c9cf8c 100644 --- a/docs/book/src/development/development.md +++ b/docs/book/src/development/development.md @@ -28,7 +28,7 @@ - [Host configuration](#host-configuration) - [Running podman system service to emulate docker daemon](#running-podman-system-service-to-emulate-docker-daemon) - [API concepts](#api-concepts) - - [`referencedResources`](#referencedresources) + - [`resolved`](#resolved) @@ -498,8 +498,11 @@ $ sudo ln -s /run/user/$(id -u)/podman/podman.sock /var/run/docker.sock This sections goal is to gather various insights into the API design that can serve as a reference to explain various choices made without need to analyze discussions in individual PRs. -### `referencedResources` +### `resolved` -Starting from v1beta1 both `OpenStackMachineStatus` and `BastionsStatus` feature a field named `referencedResources` which aims to include fields that list individual IDs of the resources associated with the machine or bastion. These IDs are calculated on machine or bastion creation and are not intended to be changed during the object lifecycle. +Starting from v1beta1 both `OpenStackMachineStatus` and `BastionsStatus` feature a field named `resolved` which aims to include fields that list fully 'resolved' versions of portions of the machine spec which require further processing before they can be used. Currently this is +- serverGroupID: the result of executing the server group filter +- imageID: the result of executing the image filter +- ports: the result of executing ConstructPorts, which amongst other things resolves network, subnet, and security group queries to resource IDs, and adds any default options. -Having all the IDs of related resources saved in the statuses allows CAPO to make easy decisions about deleting the related resources when deleting the VM corresponding to the machine or bastion. +`resolved` is guaranteed to be executed before any resources are created. It allows CAPO to make easy decisions about which resources need to be created or deleted. \ No newline at end of file diff --git a/docs/book/src/topics/crd-changes/v1alpha7-to-v1beta1.md b/docs/book/src/topics/crd-changes/v1alpha7-to-v1beta1.md index 36d68a5b19..12999781db 100644 --- a/docs/book/src/topics/crd-changes/v1alpha7-to-v1beta1.md +++ b/docs/book/src/topics/crd-changes/v1alpha7-to-v1beta1.md @@ -14,7 +14,8 @@ - [Change to image](#change-to-image) - [Removal of imageUUID](#removal-of-imageuuid) - [Changes to ports](#changes-to-ports) - - [Additon of floatingIPPoolRef](#additon-of-floatingippoolref) + - [Addition of floatingIPPoolRef](#addition-of-floatingippoolref) + - [Removal of instanceID from spec](#removal-of-instanceid-from-spec) - [`OpenStackCluster`](#openstackcluster) - [Removal of cloudName](#removal-of-cloudname-1) - [identityRef is now required](#identityref-is-now-required) @@ -28,7 +29,8 @@ - [Change to network](#change-to-network) - [Change to networkMtu](#change-to-networkmtu) - [Changes to apiServerLoadBalancer](#changes-to-apiserverloadbalancer) - - [Changes to bastion](#changes-to-bastion) + - [Changes to bastion in spec](#changes-to-bastion-in-spec) + - [Changes to bastion in status](#changes-to-bastion-in-status) - [Changes to filters](#changes-to-filters) - [Changes to filter tags](#changes-to-filter-tags) - [Field capitalization consistency](#field-capitalization-consistency) @@ -87,8 +89,8 @@ serverGroup: name: "workers" ``` -If a server group is provided and found, it'll be added to `OpenStackMachine.Status.ReferencedResources.ServerGroupID`. If the server group can't be found or filter matches multiple server groups, an error will be returned. -If empty object or null is provided, Machine will not be added to any server group and `OpenStackMachine.Status.ReferencedResources.ServerGroupID` will be empty. +If a server group is provided and found, it'll be added to `OpenStackMachine.Status.Resources.ServerGroupID`. If the server group can't be found or filter matches multiple server groups, an error will be returned. +If empty object or null is provided, Machine will not be added to any server group and `OpenStackMachine.Status.Resources.ServerGroupID` will be empty. #### Change to image @@ -106,7 +108,7 @@ image: name: "test-image" ``` -The image ID will be added to `OpenStackMachine.Status.ReferencedResources.ImageID`. If the image can't be found or filter matches multiple images, an error will be returned. +The image ID will be added to `OpenStackMachine.Status.Resources.ImageID`. If the image can't be found or filter matches multiple images, an error will be returned. #### Removal of imageUUID @@ -157,6 +159,10 @@ spec: name: "MyOpenStackFloatingIPPool" ``` +#### Removal of instanceID from spec + +The OpenStackMachine controller previously set `instanceID` in the machine spec, in addition to `providerID`. `providerID` remains unchanged as it is required by Cluster API, but `instanceID` is no longer set. If still required, it is now available in the status in `.status.server`. + ### `OpenStackCluster` #### Removal of cloudName @@ -365,7 +371,7 @@ spec: apiServerLoadBalancer: {} ``` -#### Changes to bastion +#### Changes to bastion in spec In v1beta1, `OpenStackCluster.spec.bastion.instance` becomes `OpenStackCluster.spec.bastion.spec`. @@ -389,6 +395,10 @@ spec: name: foobar ``` +#### Changes to bastion in status + +`id`, `sshKeyName`, and `state` are removed from the bastion status. `id` and `state` are now available in `bastion.server` if required. `sshKeyName` has no replacement in status, but remains available in the spec. + ### Changes to filters #### Changes to filter tags diff --git a/pkg/cloud/services/compute/instance_types.go b/pkg/cloud/services/compute/instance_types.go index c9940db7f1..c0ad085425 100644 --- a/pkg/cloud/services/compute/instance_types.go +++ b/pkg/cloud/services/compute/instance_types.go @@ -86,24 +86,13 @@ func (is *InstanceStatus) State() infrav1.InstanceState { return infrav1.InstanceState(is.server.Status) } -func (is *InstanceStatus) SSHKeyName() string { - return is.server.KeyName -} - -func (is *InstanceStatus) AvailabilityZone() string { - return is.server.AvailabilityZone -} - // BastionStatus updates BastionStatus in openStackCluster. func (is *InstanceStatus) UpdateBastionStatus(openStackCluster *infrav1.OpenStackCluster) { if openStackCluster.Status.Bastion == nil { openStackCluster.Status.Bastion = &infrav1.BastionStatus{} } - openStackCluster.Status.Bastion.ID = is.ID() openStackCluster.Status.Bastion.Name = is.Name() - openStackCluster.Status.Bastion.SSHKeyName = is.SSHKeyName() - openStackCluster.Status.Bastion.State = is.State() ns, err := is.NetworkStatus() if err != nil {