@@ -21,10 +21,17 @@ import (
2121 "fmt"
2222
2323 apiconversion "k8s.io/apimachinery/pkg/conversion"
24+ "k8s.io/apimachinery/pkg/runtime/schema"
2425 "sigs.k8s.io/cluster-api/api/v1alpha3"
26+ bootstrapv1 "sigs.k8s.io/cluster-api/bootstrap/kubeadm/api/v1alpha3"
2527 "sigs.k8s.io/controller-runtime/pkg/conversion"
2628)
2729
30+ const (
31+ kubeadmConfigKind = "KubeadmConfig"
32+ kubeadmConfigTemplateKind = "KubeadmConfigTemplate"
33+ )
34+
2835func (src * Cluster ) ConvertTo (dstRaw conversion.Hub ) error {
2936 dst := dstRaw .(* v1alpha3.Cluster )
3037
@@ -155,8 +162,12 @@ func (dst *MachineDeploymentList) ConvertFrom(srcRaw conversion.Hub) error {
155162}
156163
157164func Convert_v1alpha2_MachineSpec_To_v1alpha3_MachineSpec (in * MachineSpec , out * v1alpha3.MachineSpec , s apiconversion.Scope ) error {
158- if out .Bootstrap .ConfigRef .Kind == "KubeadmConfig" || out .Bootstrap .ConfigRef .Kind == "KubeadmConfigTemplate" {
159- out .Bootstrap .ConfigRef .APIVersion = in .Bootstrap .ConfigRef .GroupVersionKind ().Group + "/" + "v1alpha3"
165+ inGV , err := schema .ParseGroupVersion (in .Bootstrap .ConfigRef .APIVersion )
166+ if err != nil {
167+ return err
168+ }
169+ if inGV .Group == bootstrapv1 .GroupVersion .Group && (out .Bootstrap .ConfigRef .Kind == kubeadmConfigKind || out .Bootstrap .ConfigRef .Kind == kubeadmConfigTemplateKind ) {
170+ out .Bootstrap .ConfigRef .APIVersion = bootstrapv1 .GroupVersion .String ()
160171 }
161172
162173 if err := autoConvert_v1alpha2_MachineSpec_To_v1alpha3_MachineSpec (in , out , s ); err != nil {
@@ -169,15 +180,23 @@ func Convert_v1alpha2_MachineSpec_To_v1alpha3_MachineSpec(in *MachineSpec, out *
169180}
170181
171182func Convert_v1alpha2_MachineSetSpec_To_v1alpha3_MachineSetSpec (in * MachineSetSpec , out * v1alpha3.MachineSetSpec , s apiconversion.Scope ) error {
172- if out .Template .Spec .Bootstrap .ConfigRef .Kind == "KubeadmConfig" || out .Template .Spec .Bootstrap .ConfigRef .Kind == "KubeadmConfigTemplate" {
183+ inGV , err := schema .ParseGroupVersion (in .Template .Spec .Bootstrap .ConfigRef .APIVersion )
184+ if err != nil {
185+ return err
186+ }
187+ if inGV .Group == bootstrapv1 .GroupVersion .Group && (out .Template .Spec .Bootstrap .ConfigRef .Kind == kubeadmConfigKind || out .Template .Spec .Bootstrap .ConfigRef .Kind == kubeadmConfigTemplateKind ) {
173188 out .Template .Spec .Bootstrap .ConfigRef .APIVersion = in .Template .Spec .Bootstrap .ConfigRef .GroupVersionKind ().Group + "/" + "v1alpha3"
174189 }
175190
176191 return autoConvert_v1alpha2_MachineSetSpec_To_v1alpha3_MachineSetSpec (in , out , s )
177192}
178193
179194func Convert_v1alpha2_MachineDeploymentSpec_To_v1alpha3_MachineDeploymentSpec (in * MachineDeploymentSpec , out * v1alpha3.MachineDeploymentSpec , s apiconversion.Scope ) error {
180- if out .Template .Spec .Bootstrap .ConfigRef .Kind == "KubeadmConfig" || out .Template .Spec .Bootstrap .ConfigRef .Kind == "KubeadmConfigTemplate" {
195+ inGV , err := schema .ParseGroupVersion (in .Template .Spec .Bootstrap .ConfigRef .APIVersion )
196+ if err != nil {
197+ return err
198+ }
199+ if inGV .Group == bootstrapv1 .GroupVersion .Group && (out .Template .Spec .Bootstrap .ConfigRef .Kind == kubeadmConfigKind || out .Template .Spec .Bootstrap .ConfigRef .Kind == kubeadmConfigTemplateKind ) {
181200 out .Template .Spec .Bootstrap .ConfigRef .APIVersion = in .Template .Spec .Bootstrap .ConfigRef .GroupVersionKind ().Group + "/" + "v1alpha3"
182201 }
183202
0 commit comments