Skip to content

Commit ed3ed33

Browse files
committed
Fix v1alpha4 conversion
Signed-off-by: Tobias Giese <[email protected]>
1 parent ecba024 commit ed3ed33

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

api/v1alpha4/conversion.go

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,32 @@ var _ ctrlconversion.Convertible = &OpenStackClusterTemplate{}
8080
func (r *OpenStackClusterTemplate) ConvertTo(dstRaw ctrlconversion.Hub) error {
8181
dst := dstRaw.(*infrav1.OpenStackClusterTemplate)
8282

83-
return Convert_v1alpha4_OpenStackClusterTemplate_To_v1alpha6_OpenStackClusterTemplate(r, dst, nil)
83+
if err := Convert_v1alpha4_OpenStackClusterTemplate_To_v1alpha6_OpenStackClusterTemplate(r, dst, nil); err != nil {
84+
return err
85+
}
86+
87+
// Manually restore data.
88+
restored := &infrav1.OpenStackClusterTemplate{}
89+
if ok, err := utilconversion.UnmarshalData(r, restored); err != nil || !ok {
90+
return err
91+
}
92+
93+
return nil
8494
}
8595

8696
func (r *OpenStackClusterTemplate) ConvertFrom(srcRaw ctrlconversion.Hub) error {
8797
src := srcRaw.(*infrav1.OpenStackClusterTemplate)
8898

89-
return Convert_v1alpha6_OpenStackClusterTemplate_To_v1alpha4_OpenStackClusterTemplate(src, r, nil)
99+
if err := Convert_v1alpha6_OpenStackClusterTemplate_To_v1alpha4_OpenStackClusterTemplate(src, r, nil); err != nil {
100+
return err
101+
}
102+
103+
// Preserve Hub data on down-conversion except for metadata
104+
if err := utilconversion.MarshalData(src, r); err != nil {
105+
return err
106+
}
107+
108+
return nil
90109
}
91110

92111
var _ ctrlconversion.Convertible = &OpenStackClusterTemplateList{}
@@ -108,7 +127,17 @@ var _ ctrlconversion.Convertible = &OpenStackMachine{}
108127
func (r *OpenStackMachine) ConvertTo(dstRaw ctrlconversion.Hub) error {
109128
dst := dstRaw.(*infrav1.OpenStackMachine)
110129

111-
return Convert_v1alpha4_OpenStackMachine_To_v1alpha6_OpenStackMachine(r, dst, nil)
130+
if err := Convert_v1alpha4_OpenStackMachine_To_v1alpha6_OpenStackMachine(r, dst, nil); err != nil {
131+
return err
132+
}
133+
134+
// Manually restore data.
135+
restored := &infrav1.OpenStackMachine{}
136+
if ok, err := utilconversion.UnmarshalData(r, restored); err != nil || !ok {
137+
return err
138+
}
139+
140+
return nil
112141
}
113142

114143
func (r *OpenStackMachine) ConvertFrom(srcRaw ctrlconversion.Hub) error {
@@ -145,7 +174,17 @@ var _ ctrlconversion.Convertible = &OpenStackMachineTemplate{}
145174
func (r *OpenStackMachineTemplate) ConvertTo(dstRaw ctrlconversion.Hub) error {
146175
dst := dstRaw.(*infrav1.OpenStackMachineTemplate)
147176

148-
return Convert_v1alpha4_OpenStackMachineTemplate_To_v1alpha6_OpenStackMachineTemplate(r, dst, nil)
177+
if err := Convert_v1alpha4_OpenStackMachineTemplate_To_v1alpha6_OpenStackMachineTemplate(r, dst, nil); err != nil {
178+
return err
179+
}
180+
181+
// Manually restore data.
182+
restored := &infrav1.OpenStackMachineTemplate{}
183+
if ok, err := utilconversion.UnmarshalData(r, restored); err != nil || !ok {
184+
return err
185+
}
186+
187+
return nil
149188
}
150189

151190
func (r *OpenStackMachineTemplate) ConvertFrom(srcRaw ctrlconversion.Hub) error {

api/v1alpha4/conversion_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,11 @@ func TestConvertFrom(t *testing.T) {
186186
},
187187
want: &OpenStackClusterTemplate{
188188
Spec: OpenStackClusterTemplateSpec{},
189+
ObjectMeta: metav1.ObjectMeta{
190+
Annotations: map[string]string{
191+
"cluster.x-k8s.io/conversion-data": "{\"spec\":{\"template\":{\"spec\":{\"allowAllInClusterTraffic\":false,\"apiServerLoadBalancer\":{},\"cloudName\":\"\",\"controlPlaneEndpoint\":{\"host\":\"\",\"port\":0},\"disableAPIServerFloatingIP\":false,\"managedSecurityGroups\":false,\"network\":{},\"subnet\":{}}}}}",
192+
},
193+
},
189194
},
190195
},
191196
}

0 commit comments

Comments
 (0)