Skip to content

Commit 4c162b6

Browse files
authored
Merge pull request #1988 from shiftstack/instanceidstatus2
⚠️ Move InstanceID from Spec to Status
2 parents a6732bc + 5c1ad44 commit 4c162b6

20 files changed

+138
-119
lines changed

api/v1alpha5/zz_generated.conversion.go

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

api/v1alpha6/conversion_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ func TestMachineConversionControllerSpecFields(t *testing.T) {
607607
{
608608
name: "Set InstanceID",
609609
modifyUp: func(up *infrav1.OpenStackMachine) {
610-
up.Spec.InstanceID = pointer.String("new-instance-id")
610+
up.Status.InstanceID = pointer.String("new-instance-id")
611611
},
612612
testAfter: func(after *OpenStackMachine) {
613613
g.Expect(after.Spec.InstanceID).To(gomega.Equal(pointer.String("new-instance-id")))

api/v1alpha6/openstackcluster_conversion.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ var v1beta1OpenStackClusterRestorer = conversion.RestorerFor[*infrav1.OpenStackC
116116
/* OpenStackClusterSpec */
117117

118118
func restorev1alpha6ClusterSpec(previous *OpenStackClusterSpec, dst *OpenStackClusterSpec) {
119+
if previous == nil || dst == nil {
120+
return
121+
}
122+
119123
for i := range previous.ExternalRouterIPs {
120124
dstIP := &dst.ExternalRouterIPs[i]
121125
previousIP := &previous.ExternalRouterIPs[i]
@@ -139,6 +143,7 @@ func restorev1alpha6ClusterSpec(previous *OpenStackClusterSpec, dst *OpenStackCl
139143
dstBastion := dst.Bastion
140144
if prevBastion != nil && dstBastion != nil {
141145
restorev1alpha6MachineSpec(&prevBastion.Instance, &dstBastion.Instance)
146+
dstBastion.Instance.InstanceID = prevBastion.Instance.InstanceID
142147
}
143148

144149
// To avoid lossy conversion, we need to restore AllowAllInClusterTraffic

api/v1alpha6/openstackmachine_conversion.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,26 @@ var v1beta1OpenStackMachineRestorer = conversion.RestorerFor[*infrav1.OpenStackM
102102
),
103103
}
104104

105+
/* OpenStackMachine */
106+
107+
func Convert_v1alpha6_OpenStackMachine_To_v1beta1_OpenStackMachine(in *OpenStackMachine, out *infrav1.OpenStackMachine, s apiconversion.Scope) error {
108+
err := autoConvert_v1alpha6_OpenStackMachine_To_v1beta1_OpenStackMachine(in, out, s)
109+
if err != nil {
110+
return err
111+
}
112+
out.Status.InstanceID = in.Spec.InstanceID
113+
return nil
114+
}
115+
116+
func Convert_v1beta1_OpenStackMachine_To_v1alpha6_OpenStackMachine(in *infrav1.OpenStackMachine, out *OpenStackMachine, s apiconversion.Scope) error {
117+
err := autoConvert_v1beta1_OpenStackMachine_To_v1alpha6_OpenStackMachine(in, out, s)
118+
if err != nil {
119+
return err
120+
}
121+
out.Spec.InstanceID = in.Status.InstanceID
122+
return nil
123+
}
124+
105125
/* OpenStackMachineSpec */
106126

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

api/v1alpha6/openstackmachinetemplate_conversion.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ var v1alpha6OpenStackMachineTemplateRestorer = conversion.RestorerFor[*OpenStack
6464
func(c *OpenStackMachineTemplate) *OpenStackMachineSpec {
6565
return &c.Spec.Template.Spec
6666
},
67-
restorev1alpha6MachineSpec,
67+
restorev1alpha6MachineTemplateMachineSpec,
6868
),
6969
}
7070

@@ -76,3 +76,13 @@ var v1beta1OpenStackMachineTemplateRestorer = conversion.RestorerFor[*infrav1.Op
7676
restorev1beta1MachineSpec,
7777
),
7878
}
79+
80+
// Restore a MachineSpec in the context of a MachineTemplate. Restores
81+
// InstanceID, which will not otherwise be restored for a MachineTemplate.
82+
func restorev1alpha6MachineTemplateMachineSpec(previous *OpenStackMachineSpec, dst *OpenStackMachineSpec) {
83+
if previous == nil || dst == nil {
84+
return
85+
}
86+
restorev1alpha6MachineSpec(previous, dst)
87+
dst.InstanceID = previous.InstanceID
88+
}

api/v1alpha6/zz_generated.conversion.go

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

api/v1alpha7/conversion_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ func TestMachineConversionControllerSpecFields(t *testing.T) {
211211
{
212212
name: "Set InstanceID",
213213
modifyUp: func(up *infrav1.OpenStackMachine) {
214-
up.Spec.InstanceID = pointer.String("new-instance-id")
214+
up.Status.InstanceID = pointer.String("new-instance-id")
215215
},
216216
testAfter: func(g gomega.Gomega, after *OpenStackMachine) {
217217
g.Expect(after.Spec.InstanceID).To(gomega.Equal(pointer.String("new-instance-id")))

api/v1alpha7/openstackcluster_conversion.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,14 @@ func Convert_v1beta1_OpenStackClusterStatus_To_v1alpha7_OpenStackClusterStatus(i
371371
/* Bastion */
372372

373373
func restorev1alpha7Bastion(previous **Bastion, dst **Bastion) {
374-
if *previous != nil && *dst != nil {
375-
restorev1alpha7MachineSpec(&(*previous).Instance, &(*dst).Instance)
374+
if *previous == nil || *dst == nil {
375+
return
376376
}
377+
378+
prevMachineSpec := &(*previous).Instance
379+
dstMachineSpec := &(*dst).Instance
380+
restorev1alpha7MachineSpec(prevMachineSpec, dstMachineSpec)
381+
dstMachineSpec.InstanceID = prevMachineSpec.InstanceID
377382
}
378383

379384
func restorev1beta1Bastion(previous **infrav1.Bastion, dst **infrav1.Bastion) {

api/v1alpha7/openstackmachine_conversion.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,28 @@ var v1beta1OpenStackMachineRestorer = conversion.RestorerFor[*infrav1.OpenStackM
102102
),
103103
}
104104

105+
/* OpenStackMachine */
106+
107+
func Convert_v1alpha7_OpenStackMachine_To_v1beta1_OpenStackMachine(in *OpenStackMachine, out *infrav1.OpenStackMachine, s apiconversion.Scope) error {
108+
err := autoConvert_v1alpha7_OpenStackMachine_To_v1beta1_OpenStackMachine(in, out, s)
109+
if err != nil {
110+
return err
111+
}
112+
113+
out.Status.InstanceID = in.Spec.InstanceID
114+
return nil
115+
}
116+
117+
func Convert_v1beta1_OpenStackMachine_To_v1alpha7_OpenStackMachine(in *infrav1.OpenStackMachine, out *OpenStackMachine, s apiconversion.Scope) error {
118+
err := autoConvert_v1beta1_OpenStackMachine_To_v1alpha7_OpenStackMachine(in, out, s)
119+
if err != nil {
120+
return err
121+
}
122+
123+
out.Spec.InstanceID = in.Status.InstanceID
124+
return nil
125+
}
126+
105127
/* OpenStackMachineSpec */
106128

107129
func restorev1alpha7MachineSpec(previous *OpenStackMachineSpec, dst *OpenStackMachineSpec) {

api/v1alpha7/openstackmachinetemplate_conversion.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,12 @@ var v1beta1OpenStackMachineTemplateRestorer = conversion.RestorerFor[*infrav1.Op
7878
}
7979

8080
func restorev1alpha7MachineTemplateSpec(previous *OpenStackMachineTemplateSpec, dst *OpenStackMachineTemplateSpec) {
81-
restorev1alpha7MachineSpec(&previous.Template.Spec, &dst.Template.Spec)
81+
if previous == nil || dst == nil {
82+
return
83+
}
84+
85+
prevMachineSpec := &previous.Template.Spec
86+
dstMachineSpec := &dst.Template.Spec
87+
restorev1alpha7MachineSpec(prevMachineSpec, dstMachineSpec)
88+
dstMachineSpec.InstanceID = prevMachineSpec.InstanceID
8289
}

api/v1alpha7/zz_generated.conversion.go

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

api/v1beta1/openstackmachine_types.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
"k8s.io/utils/pointer"
2323
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
2424
"sigs.k8s.io/cluster-api/errors"
25+
26+
"sigs.k8s.io/cluster-api-provider-openstack/pkg/utils/optional"
2527
)
2628

2729
const (
@@ -36,9 +38,6 @@ type OpenStackMachineSpec struct {
3638
// ProviderID is the unique identifier as specified by the cloud provider.
3739
ProviderID *string `json:"providerID,omitempty"`
3840

39-
// InstanceID is the OpenStack instance ID for this machine.
40-
InstanceID *string `json:"instanceID,omitempty"`
41-
4241
// The flavor reference for the flavor for your server instance.
4342
Flavor string `json:"flavor"`
4443

@@ -119,6 +118,10 @@ type OpenStackMachineStatus struct {
119118
// +optional
120119
Ready bool `json:"ready"`
121120

121+
// InstanceID is the OpenStack instance ID for this machine.
122+
// +optional
123+
InstanceID optional.String `json:"instanceID,omitempty"`
124+
122125
// Addresses contains the OpenStack instance associated addresses.
123126
Addresses []corev1.NodeAddress `json:"addresses,omitempty"`
124127

0 commit comments

Comments
 (0)