Skip to content

Commit 4190ef6

Browse files
fix kubernetes version setting on kubernetes template
Signed-off-by: Carlos Eduardo Arango Gutierrez <[email protected]>
1 parent f9103a7 commit 4190ef6

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

pkg/provisioner/templates/kubernetes.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,16 @@ type KubeadmConfig struct {
272272
}
273273

274274
func NewKubernetes(env v1alpha1.Environment) (*Kubernetes, error) {
275-
kubernetes := &Kubernetes{
276-
Version: env.Spec.Kubernetes.KubernetesVersion,
277-
}
278-
// check if env.Spec.Kubernetes.KubernetesVersion is in the format of vX.Y.Z
279-
// if not, set the default version
280-
if !strings.HasPrefix(env.Spec.Kubernetes.KubernetesVersion, "v") && env.Spec.Kubernetes.KubernetesInstaller != "microk8s" {
281-
fmt.Printf("Kubernetes version %s is not in the format of vX.Y.Z, setting default version v1.32.1\n", env.Spec.Kubernetes.KubernetesVersion)
275+
kubernetes := &Kubernetes{}
276+
277+
// Normalize Kubernetes version using a switch statement
278+
switch {
279+
case env.Spec.Kubernetes.KubernetesVersion == "":
282280
kubernetes.Version = defaultKubernetesVersion
281+
case !strings.HasPrefix(env.Spec.Kubernetes.KubernetesVersion, "v") && env.Spec.Kubernetes.KubernetesInstaller != "microk8s":
282+
kubernetes.Version = "v" + env.Spec.Kubernetes.KubernetesVersion
283+
default:
284+
kubernetes.Version = env.Spec.Kubernetes.KubernetesVersion
283285
}
284286
if env.Spec.Kubernetes.KubeletReleaseVersion != "" {
285287
kubernetes.KubeletReleaseVersion = env.Spec.Kubernetes.KubeletReleaseVersion

0 commit comments

Comments
 (0)