Skip to content

Commit 13fa2be

Browse files
Move microK8s version normalization to it's template
Signed-off-by: Carlos Eduardo Arango Gutierrez <[email protected]>
1 parent 4190ef6 commit 13fa2be

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

cmd/cli/.main.go.swp

12 KB
Binary file not shown.

pkg/provisioner/templates/kubernetes.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,14 @@ echo "ssh -i <your-private-key> ubuntu@${INSTANCE_ENDPOINT_HOST}"
171171

172172
const microk8sTemplate = `
173173
: ${INSTANCE_ENDPOINT_HOST:={{.K8sEndpointHost}}}
174+
: ${K8S_VERSION:={{.Version}}}
175+
176+
# Remove leading 'v' from version if present for microk8s snap channel
177+
MICROK8S_VERSION="${K8S_VERSION#v}"
174178
175179
# Install microk8s
176180
sudo apt-get update
177-
178-
sudo snap install microk8s --classic --channel={{.Version}}
181+
sudo snap install microk8s --classic --channel=${MICROK8S_VERSION}
179182
sudo microk8s enable gpu dashboard dns registry
180183
sudo usermod -a -G microk8s ubuntu
181184
mkdir -p ~/.kube
@@ -184,7 +187,7 @@ sudo microk8s config > ~/.kube/config
184187
sudo chown -f -R ubuntu ~/.kube
185188
sudo snap alias microk8s.kubectl kubectl
186189
187-
echo "Microk8s {{.Version}} installed successfully"
190+
echo "Microk8s ${MICROK8S_VERSION} installed successfully"
188191
echo "you can now access the cluster with:"
189192
echo "ssh -i <your-private-key> ubuntu@${INSTANCE_ENDPOINT_HOST}"
190193
`
@@ -274,11 +277,11 @@ type KubeadmConfig struct {
274277
func NewKubernetes(env v1alpha1.Environment) (*Kubernetes, error) {
275278
kubernetes := &Kubernetes{}
276279

277-
// Normalize Kubernetes version using a switch statement
280+
// Normalize Kubernetes version: always ensure it starts with 'v'
278281
switch {
279282
case env.Spec.Kubernetes.KubernetesVersion == "":
280283
kubernetes.Version = defaultKubernetesVersion
281-
case !strings.HasPrefix(env.Spec.Kubernetes.KubernetesVersion, "v") && env.Spec.Kubernetes.KubernetesInstaller != "microk8s":
284+
case !strings.HasPrefix(env.Spec.Kubernetes.KubernetesVersion, "v"):
282285
kubernetes.Version = "v" + env.Spec.Kubernetes.KubernetesVersion
283286
default:
284287
kubernetes.Version = env.Spec.Kubernetes.KubernetesVersion

0 commit comments

Comments
 (0)