File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed
pkg/provisioner/templates Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -272,14 +272,16 @@ type KubeadmConfig struct {
272272}
273273
274274func 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
You can’t perform that action at this time.
0 commit comments