Skip to content

Commit 3b8bc57

Browse files
Deprecate SSHKeys in favor of SSHKeysRef variable (#920)
Signed-off-by: Prajyot-Parab <[email protected]> Signed-off-by: Prajyot-Parab <[email protected]>
1 parent bd2090a commit 3b8bc57

13 files changed

+546
-61
lines changed

api/v1alpha3/conversion.go

Lines changed: 69 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323

2424
capiv1alpha3 "sigs.k8s.io/cluster-api/api/v1alpha3"
2525
capiv1beta1 "sigs.k8s.io/cluster-api/api/v1beta1"
26+
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
2627

2728
infrav1beta1 "sigs.k8s.io/cluster-api-provider-ibmcloud/api/v1beta1"
2829
)
@@ -62,13 +63,41 @@ func (dst *IBMVPCClusterList) ConvertFrom(srcRaw conversion.Hub) error {
6263
func (src *IBMVPCMachine) ConvertTo(dstRaw conversion.Hub) error {
6364
dst := dstRaw.(*infrav1beta1.IBMVPCMachine)
6465

65-
return Convert_v1alpha3_IBMVPCMachine_To_v1beta1_IBMVPCMachine(src, dst, nil)
66+
if err := Convert_v1alpha3_IBMVPCMachine_To_v1beta1_IBMVPCMachine(src, dst, nil); err != nil {
67+
return err
68+
}
69+
70+
for _, sshKey := range src.Spec.SSHKeys {
71+
dst.Spec.SSHKeysRef = append(dst.Spec.SSHKeysRef, &infrav1beta1.IBMVPCResourceReference{
72+
ID: sshKey,
73+
})
74+
}
75+
76+
return nil
6677
}
6778

6879
func (dst *IBMVPCMachine) ConvertFrom(srcRaw conversion.Hub) error {
6980
src := srcRaw.(*infrav1beta1.IBMVPCMachine)
7081

71-
return Convert_v1beta1_IBMVPCMachine_To_v1alpha3_IBMVPCMachine(src, dst, nil)
82+
if err := Convert_v1beta1_IBMVPCMachine_To_v1alpha3_IBMVPCMachine(src, dst, nil); err != nil {
83+
return err
84+
}
85+
86+
// Preserve Hub data on down-conversion except for metadata
87+
if err := utilconversion.MarshalData(src, dst); err != nil {
88+
return err
89+
}
90+
91+
if src.Spec.SSHKeysRef != nil {
92+
for _, sshKey := range src.Spec.SSHKeysRef {
93+
if sshKey.ID != nil {
94+
// Only source keys with ID will be converted
95+
dst.Spec.SSHKeys = append(dst.Spec.SSHKeys, sshKey.ID)
96+
}
97+
}
98+
}
99+
100+
return nil
72101
}
73102

74103
func (src *IBMVPCMachineList) ConvertTo(dstRaw conversion.Hub) error {
@@ -86,13 +115,41 @@ func (dst *IBMVPCMachineList) ConvertFrom(srcRaw conversion.Hub) error {
86115
func (src *IBMVPCMachineTemplate) ConvertTo(dstRaw conversion.Hub) error {
87116
dst := dstRaw.(*infrav1beta1.IBMVPCMachineTemplate)
88117

89-
return Convert_v1alpha3_IBMVPCMachineTemplate_To_v1beta1_IBMVPCMachineTemplate(src, dst, nil)
118+
if err := Convert_v1alpha3_IBMVPCMachineTemplate_To_v1beta1_IBMVPCMachineTemplate(src, dst, nil); err != nil {
119+
return err
120+
}
121+
122+
for _, sshKey := range src.Spec.Template.Spec.SSHKeys {
123+
dst.Spec.Template.Spec.SSHKeysRef = append(dst.Spec.Template.Spec.SSHKeysRef, &infrav1beta1.IBMVPCResourceReference{
124+
ID: sshKey,
125+
})
126+
}
127+
128+
return nil
90129
}
91130

92131
func (dst *IBMVPCMachineTemplate) ConvertFrom(srcRaw conversion.Hub) error {
93132
src := srcRaw.(*infrav1beta1.IBMVPCMachineTemplate)
94133

95-
return Convert_v1beta1_IBMVPCMachineTemplate_To_v1alpha3_IBMVPCMachineTemplate(src, dst, nil)
134+
if err := Convert_v1beta1_IBMVPCMachineTemplate_To_v1alpha3_IBMVPCMachineTemplate(src, dst, nil); err != nil {
135+
return err
136+
}
137+
138+
// Preserve Hub data on down-conversion except for metadata
139+
if err := utilconversion.MarshalData(src, dst); err != nil {
140+
return err
141+
}
142+
143+
if src.Spec.Template.Spec.SSHKeysRef != nil {
144+
for _, sshKey := range src.Spec.Template.Spec.SSHKeysRef {
145+
if sshKey.ID != nil {
146+
// Only source keys with ID will be converted
147+
dst.Spec.Template.Spec.SSHKeys = append(dst.Spec.Template.Spec.SSHKeys, sshKey.ID)
148+
}
149+
}
150+
}
151+
152+
return nil
96153
}
97154

98155
func (src *IBMVPCMachineTemplateList) ConvertTo(dstRaw conversion.Hub) error {
@@ -124,3 +181,11 @@ func Convert_v1beta1_IBMVPCClusterStatus_To_v1alpha3_IBMVPCClusterStatus(in *inf
124181
func Convert_v1beta1_VPCEndpoint_To_v1alpha3_VPCEndpoint(in *infrav1beta1.VPCEndpoint, out *VPCEndpoint, s apiconversion.Scope) error {
125182
return autoConvert_v1beta1_VPCEndpoint_To_v1alpha3_VPCEndpoint(in, out, s)
126183
}
184+
185+
func Convert_v1beta1_IBMVPCMachineSpec_To_v1alpha3_IBMVPCMachineSpec(in *infrav1beta1.IBMVPCMachineSpec, out *IBMVPCMachineSpec, s apiconversion.Scope) error {
186+
return autoConvert_v1beta1_IBMVPCMachineSpec_To_v1alpha3_IBMVPCMachineSpec(in, out, s)
187+
}
188+
189+
func Convert_v1alpha3_IBMVPCMachineSpec_To_v1beta1_IBMVPCMachineSpec(in *IBMVPCMachineSpec, out *infrav1beta1.IBMVPCMachineSpec, s apiconversion.Scope) error {
190+
return autoConvert_v1alpha3_IBMVPCMachineSpec_To_v1beta1_IBMVPCMachineSpec(in, out, s)
191+
}

api/v1alpha3/zz_generated.conversion.go

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

api/v1alpha4/ibmvpc_conversion.go

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ import (
2121

2222
"sigs.k8s.io/controller-runtime/pkg/conversion"
2323

24+
utilconversion "sigs.k8s.io/cluster-api/util/conversion"
25+
2426
infrav1beta1 "sigs.k8s.io/cluster-api-provider-ibmcloud/api/v1beta1"
2527
)
2628

@@ -51,13 +53,41 @@ func (dst *IBMVPCClusterList) ConvertFrom(srcRaw conversion.Hub) error {
5153
func (src *IBMVPCMachine) ConvertTo(dstRaw conversion.Hub) error {
5254
dst := dstRaw.(*infrav1beta1.IBMVPCMachine)
5355

54-
return Convert_v1alpha4_IBMVPCMachine_To_v1beta1_IBMVPCMachine(src, dst, nil)
56+
if err := Convert_v1alpha4_IBMVPCMachine_To_v1beta1_IBMVPCMachine(src, dst, nil); err != nil {
57+
return err
58+
}
59+
60+
for _, sshKey := range src.Spec.SSHKeys {
61+
dst.Spec.SSHKeysRef = append(dst.Spec.SSHKeysRef, &infrav1beta1.IBMVPCResourceReference{
62+
ID: sshKey,
63+
})
64+
}
65+
66+
return nil
5567
}
5668

5769
func (dst *IBMVPCMachine) ConvertFrom(srcRaw conversion.Hub) error {
5870
src := srcRaw.(*infrav1beta1.IBMVPCMachine)
5971

60-
return Convert_v1beta1_IBMVPCMachine_To_v1alpha4_IBMVPCMachine(src, dst, nil)
72+
if err := Convert_v1beta1_IBMVPCMachine_To_v1alpha4_IBMVPCMachine(src, dst, nil); err != nil {
73+
return err
74+
}
75+
76+
// Preserve Hub data on down-conversion except for metadata
77+
if err := utilconversion.MarshalData(src, dst); err != nil {
78+
return err
79+
}
80+
81+
if src.Spec.SSHKeysRef != nil {
82+
for _, sshKey := range src.Spec.SSHKeysRef {
83+
if sshKey.ID != nil {
84+
// Only source keys with ID will be converted
85+
dst.Spec.SSHKeys = append(dst.Spec.SSHKeys, sshKey.ID)
86+
}
87+
}
88+
}
89+
90+
return nil
6191
}
6292

6393
func (src *IBMVPCMachineList) ConvertTo(dstRaw conversion.Hub) error {
@@ -75,13 +105,41 @@ func (dst *IBMVPCMachineList) ConvertFrom(srcRaw conversion.Hub) error {
75105
func (src *IBMVPCMachineTemplate) ConvertTo(dstRaw conversion.Hub) error {
76106
dst := dstRaw.(*infrav1beta1.IBMVPCMachineTemplate)
77107

78-
return Convert_v1alpha4_IBMVPCMachineTemplate_To_v1beta1_IBMVPCMachineTemplate(src, dst, nil)
108+
if err := Convert_v1alpha4_IBMVPCMachineTemplate_To_v1beta1_IBMVPCMachineTemplate(src, dst, nil); err != nil {
109+
return err
110+
}
111+
112+
for _, sshKey := range src.Spec.Template.Spec.SSHKeys {
113+
dst.Spec.Template.Spec.SSHKeysRef = append(dst.Spec.Template.Spec.SSHKeysRef, &infrav1beta1.IBMVPCResourceReference{
114+
ID: sshKey,
115+
})
116+
}
117+
118+
return nil
79119
}
80120

81121
func (dst *IBMVPCMachineTemplate) ConvertFrom(srcRaw conversion.Hub) error {
82122
src := srcRaw.(*infrav1beta1.IBMVPCMachineTemplate)
83123

84-
return Convert_v1beta1_IBMVPCMachineTemplate_To_v1alpha4_IBMVPCMachineTemplate(src, dst, nil)
124+
if err := Convert_v1beta1_IBMVPCMachineTemplate_To_v1alpha4_IBMVPCMachineTemplate(src, dst, nil); err != nil {
125+
return err
126+
}
127+
128+
// Preserve Hub data on down-conversion except for metadata
129+
if err := utilconversion.MarshalData(src, dst); err != nil {
130+
return err
131+
}
132+
133+
if src.Spec.Template.Spec.SSHKeysRef != nil {
134+
for _, sshKey := range src.Spec.Template.Spec.SSHKeysRef {
135+
if sshKey.ID != nil {
136+
// Only source keys with ID will be converted
137+
dst.Spec.Template.Spec.SSHKeys = append(dst.Spec.Template.Spec.SSHKeys, sshKey.ID)
138+
}
139+
}
140+
}
141+
142+
return nil
85143
}
86144

87145
func (src *IBMVPCMachineTemplateList) ConvertTo(dstRaw conversion.Hub) error {
@@ -113,3 +171,11 @@ func Convert_v1beta1_IBMVPCClusterStatus_To_v1alpha4_IBMVPCClusterStatus(in *inf
113171
func Convert_v1beta1_VPCEndpoint_To_v1alpha4_VPCEndpoint(in *infrav1beta1.VPCEndpoint, out *VPCEndpoint, s apiconversion.Scope) error {
114172
return autoConvert_v1beta1_VPCEndpoint_To_v1alpha4_VPCEndpoint(in, out, s)
115173
}
174+
175+
func Convert_v1beta1_IBMVPCMachineSpec_To_v1alpha4_IBMVPCMachineSpec(in *infrav1beta1.IBMVPCMachineSpec, out *IBMVPCMachineSpec, s apiconversion.Scope) error {
176+
return autoConvert_v1beta1_IBMVPCMachineSpec_To_v1alpha4_IBMVPCMachineSpec(in, out, s)
177+
}
178+
179+
func Convert_v1alpha4_IBMVPCMachineSpec_To_v1beta1_IBMVPCMachineSpec(in *IBMVPCMachineSpec, out *infrav1beta1.IBMVPCMachineSpec, s apiconversion.Scope) error {
180+
return autoConvert_v1alpha4_IBMVPCMachineSpec_To_v1beta1_IBMVPCMachineSpec(in, out, s)
181+
}

0 commit comments

Comments
 (0)