Skip to content

Commit d32d7c2

Browse files
committed
Declared constants to satisfy lint tool
1 parent 227a520 commit d32d7c2

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

api/v1alpha2/conversion.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
2835
func (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

157164
func 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

171182
func 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

179194
func 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

Comments
 (0)