Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions api/v1alpha5/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,23 +448,17 @@ 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
return nil
}

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
Expand Down Expand Up @@ -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)
}

Expand Down
22 changes: 8 additions & 14 deletions api/v1alpha5/zz_generated.conversion.go

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

5 changes: 4 additions & 1 deletion api/v1alpha6/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
Expand Down
26 changes: 20 additions & 6 deletions api/v1alpha6/openstackcluster_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -481,25 +500,20 @@ 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
}

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
Expand Down
57 changes: 56 additions & 1 deletion api/v1alpha6/openstackmachine_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]{
Expand All @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the other restore functions skip the setting of previous into dst when the resource is empty/nil. Should we follow the same pattern here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been adding that incrementally. As this is a new function I should have added it here.

}
}

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)
}
8 changes: 7 additions & 1 deletion api/v1alpha6/openstackmachinetemplate_conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ var v1alpha6OpenStackMachineTemplateRestorer = conversion.RestorerFor[*OpenStack
func(c *OpenStackMachineTemplate) *OpenStackMachineSpec {
return &c.Spec.Template.Spec
},
restorev1alpha6MachineSpec,
restorev1alpha6MachineSpecFromTemplate,
),
}

Expand All @@ -76,3 +76,9 @@ var v1beta1OpenStackMachineTemplateRestorer = conversion.RestorerFor[*infrav1.Op
restorev1beta1MachineSpec,
),
}

func restorev1alpha6MachineSpecFromTemplate(previous *OpenStackMachineSpec, dst *OpenStackMachineSpec) {
restorev1alpha6MachineSpec(previous, dst)

dst.InstanceID = previous.InstanceID
}
Loading