Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: figure out k8s version in helm chart #2186

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion chart/templates/_init-containers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,46 @@
{{- end -}}
{{- end -}}

{{- define "vcluster.k8s.capabilities.version" -}}
{{/* We need to workaround here for unit tests because Capabilities.KubeVersion.Version is not supported, so we use .Chart.Version */}}
{{- if hasPrefix "test-" .Chart.Version -}}
{{- regexFind "^v[0-9]+\\.[0-9]+\\.[0-9]+" (trimPrefix "test-" .Chart.Version) -}}
{{- else -}}
{{- regexFind "^v[0-9]+\\.[0-9]+\\.[0-9]+" .Capabilities.KubeVersion.Version -}}
{{- end -}}
{{- end -}}

{{/* Bump $defaultTag value whenever k8s version is bumped */}}
{{- define "vcluster.k8s.controllerManager.image.tag" -}}
{{- $defaultTag := "v1.30.2" -}}
{{- if and (not (empty .Values.controlPlane.distro.k8s.version)) (eq .Values.controlPlane.distro.k8s.controllerManager.image.tag $defaultTag) -}}
{{ .Values.controlPlane.distro.k8s.version}}
{{ .Values.controlPlane.distro.k8s.version }}
{{- else -}}
{{- if not (eq .Values.controlPlane.distro.k8s.controllerManager.image.tag $defaultTag) -}}
{{ .Values.controlPlane.distro.k8s.controllerManager.image.tag }}
{{- else if not (empty (include "vcluster.k8s.capabilities.version" .)) -}}
{{ include "vcluster.k8s.capabilities.version" . }}
{{- else -}}
{{ .Values.controlPlane.distro.k8s.controllerManager.image.tag }}
{{- end -}}
{{- end -}}
{{- end -}}

{{/* Bump $defaultTag value whenever k8s version is bumped */}}
{{- define "vcluster.k8s.apiServer.image.tag" -}}
{{- $defaultTag := "v1.30.2" -}}
{{- if and (not (empty .Values.controlPlane.distro.k8s.version)) (eq .Values.controlPlane.distro.k8s.apiServer.image.tag $defaultTag) -}}
{{ .Values.controlPlane.distro.k8s.version}}
{{- else -}}
{{- if not (eq .Values.controlPlane.distro.k8s.apiServer.image.tag $defaultTag) -}}
{{ .Values.controlPlane.distro.k8s.apiServer.image.tag }}
{{- else if not (empty (include "vcluster.k8s.capabilities.version" .)) -}}
{{ include "vcluster.k8s.capabilities.version" . }}
{{- else -}}
{{ .Values.controlPlane.distro.k8s.apiServer.image.tag }}
{{- end -}}
{{- end -}}
{{- end -}}


{{/* Bump $defaultTag value whenever k8s version is bumped */}}
Expand All @@ -35,7 +56,13 @@
{{- if and (not (empty .Values.controlPlane.distro.k8s.version)) (eq .Values.controlPlane.distro.k8s.scheduler.image.tag $defaultTag) -}}
{{ .Values.controlPlane.distro.k8s.version}}
{{- else -}}
{{- if not (eq .Values.controlPlane.distro.k8s.scheduler.image.tag $defaultTag) -}}
{{ .Values.controlPlane.distro.k8s.scheduler.image.tag }}
{{- else if not (empty (include "vcluster.k8s.capabilities.version" .)) -}}
{{ include "vcluster.k8s.capabilities.version" . }}
{{- else -}}
{{ .Values.controlPlane.distro.k8s.scheduler.image.tag }}
{{- end -}}
{{- end -}}
{{- end -}}

Expand Down
58 changes: 58 additions & 0 deletions chart/tests/statefulset_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,8 @@ tests:
claimName: my-custom-pvc

- it: k8s version not set, default tag images used for apiServer and controllerManager
chart:
version: "test-"
set:
controlPlane:
distro:
Expand All @@ -591,6 +593,60 @@ tests:
path: spec.template.spec.initContainers[2].image
value: registry.k8s.io/kube-apiserver:v1.30.2

- it: k8s capabilities set
chart:
version: "test-v1.29.3"
asserts:
- equal:
path: spec.template.spec.initContainers[1].image
value: registry.k8s.io/kube-controller-manager:v1.29.3
- equal:
path: spec.template.spec.initContainers[2].image
value: registry.k8s.io/kube-apiserver:v1.29.3

- it: k8s capabilities orbstack
chart:
version: "test-v1.29.3+orb1"
asserts:
- equal:
path: spec.template.spec.initContainers[1].image
value: registry.k8s.io/kube-controller-manager:v1.29.3
- equal:
path: spec.template.spec.initContainers[2].image
value: registry.k8s.io/kube-apiserver:v1.29.3

- it: k8s capabilities invalid
chart:
version: "test-invalid"
asserts:
- equal:
path: spec.template.spec.initContainers[1].image
value: registry.k8s.io/kube-controller-manager:v1.30.2

- it: k8s capabilities incomplete
chart:
version: "test-v1.22"
asserts:
- equal:
path: spec.template.spec.initContainers[1].image
value: registry.k8s.io/kube-controller-manager:v1.30.2

- it: k8s capabilities incomplete 2
chart:
version: "test-1.22.11"
asserts:
- equal:
path: spec.template.spec.initContainers[1].image
value: registry.k8s.io/kube-controller-manager:v1.30.2

- it: k8s capabilities incomplete 2
chart:
version: "test-v1.22.33"
asserts:
- equal:
path: spec.template.spec.initContainers[1].image
value: registry.k8s.io/kube-controller-manager:v1.22.33

- it: k8s version sets image tag for apiServer and controllerManager
set:
controlPlane:
Expand Down Expand Up @@ -650,6 +706,8 @@ tests:
value: registry.k8s.io/kube-apiserver:v99914

- it: k8s version not set, default tag images used for apiServer and controllerManager (virtual scheduler enabled)
chart:
version: "test-"
set:
controlPlane:
distro:
Expand Down
Loading
Loading