Skip to content

Commit

Permalink
feature: add controlPlane.distro.k8s.version chart value to ease CAPI…
Browse files Browse the repository at this point in the history
… intergration
  • Loading branch information
hidalgopl committed Aug 6, 2024
1 parent c523d8b commit b51e00a
Show file tree
Hide file tree
Showing 5 changed files with 259 additions and 25 deletions.
37 changes: 34 additions & 3 deletions chart/templates/_init-containers.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,37 @@
{{- 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}}
{{- else -}}
{{ .Values.controlPlane.distro.k8s.controllerManager.image.tag }}
{{- 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 -}}
{{ .Values.controlPlane.distro.k8s.apiServer.image.tag }}
{{- end -}}
{{- end -}}


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

{{- define "vcluster.k8s.initContainers" -}}
{{- include "vcluster.oldPlugins.initContainers" . }}
{{- include "vcluster.plugins.initContainers" . }}
Expand All @@ -32,7 +63,7 @@
{{ toYaml .Values.controlPlane.distro.k8s.resources | indent 4 }}
{{- if .Values.controlPlane.distro.k8s.controllerManager.enabled }}
- name: kube-controller-manager
image: "{{ include "vcluster.image" (dict "defaultImageRegistry" .Values.controlPlane.advanced.defaultImageRegistry "registry" .Values.controlPlane.distro.k8s.controllerManager.image.registry "repository" .Values.controlPlane.distro.k8s.controllerManager.image.repository "tag" .Values.controlPlane.distro.k8s.controllerManager.image.tag) }}"
image: "{{ include "vcluster.image" (dict "defaultImageRegistry" .Values.controlPlane.advanced.defaultImageRegistry "registry" .Values.controlPlane.distro.k8s.controllerManager.image.registry "repository" .Values.controlPlane.distro.k8s.controllerManager.image.repository "tag" (include "vcluster.k8s.controllerManager.image.tag" .)) }}"
volumeMounts:
- mountPath: /binaries
name: binaries
Expand All @@ -52,7 +83,7 @@
{{- end }}
{{- if .Values.controlPlane.advanced.virtualScheduler.enabled }}
- name: kube-scheduler-manager
image: "{{ include "vcluster.image" (dict "defaultImageRegistry" .Values.controlPlane.advanced.defaultImageRegistry "registry" .Values.controlPlane.distro.k8s.scheduler.image.registry "repository" .Values.controlPlane.distro.k8s.scheduler.image.repository "tag" .Values.controlPlane.distro.k8s.scheduler.image.tag) }}"
image: "{{ include "vcluster.image" (dict "defaultImageRegistry" .Values.controlPlane.advanced.defaultImageRegistry "registry" .Values.controlPlane.distro.k8s.scheduler.image.registry "repository" .Values.controlPlane.distro.k8s.scheduler.image.repository "tag" (include "vcluster.k8s.scheduler.image.tag" .)) }}"
volumeMounts:
- mountPath: /binaries
name: binaries
Expand All @@ -72,7 +103,7 @@
{{- end }}
{{- if .Values.controlPlane.distro.k8s.apiServer.enabled }}
- name: kube-apiserver
image: "{{ include "vcluster.image" (dict "defaultImageRegistry" .Values.controlPlane.advanced.defaultImageRegistry "registry" .Values.controlPlane.distro.k8s.apiServer.image.registry "repository" .Values.controlPlane.distro.k8s.apiServer.image.repository "tag" .Values.controlPlane.distro.k8s.apiServer.image.tag) }}"
image: "{{ include "vcluster.image" (dict "defaultImageRegistry" .Values.controlPlane.advanced.defaultImageRegistry "registry" .Values.controlPlane.distro.k8s.apiServer.image.registry "repository" .Values.controlPlane.distro.k8s.apiServer.image.repository "tag" (include "vcluster.k8s.apiServer.image.tag" .)) }}"
volumeMounts:
- mountPath: /binaries
name: binaries
Expand Down
175 changes: 175 additions & 0 deletions chart/tests/statefulset_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -576,3 +576,178 @@ tests:
name: data
persistentVolumeClaim:
claimName: my-custom-pvc

- it: k8s version not set, default tag images used for apiServer and controllerManager
set:
controlPlane:
distro:
k8s:
enabled: true
asserts:
- equal:
path: spec.template.spec.initContainers[1].image
value: registry.k8s.io/kube-controller-manager:v1.30.2
- equal:
path: spec.template.spec.initContainers[2].image
value: registry.k8s.io/kube-apiserver:v1.30.2

- it: k8s version sets image tag for apiServer and controllerManager
set:
controlPlane:
distro:
k8s:
enabled: true
version: v1.35.999
asserts:
- equal:
path: spec.template.spec.initContainers[1].image
value: registry.k8s.io/kube-controller-manager:v1.35.999
- equal:
path: spec.template.spec.initContainers[2].image
value: registry.k8s.io/kube-apiserver:v1.35.999

- it: k8s version set but overridden by image tag for apiServer and controllerManager
set:
controlPlane:
distro:
k8s:
enabled: true
version: v1.30.999
apiServer:
image:
tag: v99912
controllerManager:
image:
tag: v23123

asserts:
- equal:
path: spec.template.spec.initContainers[1].image
value: registry.k8s.io/kube-controller-manager:v23123
- equal:
path: spec.template.spec.initContainers[2].image
value: registry.k8s.io/kube-apiserver:v99912

- it: k8s not version set but image tags for apiServer and controllerManager set
set:
controlPlane:
distro:
k8s:
enabled: true
apiServer:
image:
tag: v99914
controllerManager:
image:
tag: v23127

asserts:
- equal:
path: spec.template.spec.initContainers[1].image
value: registry.k8s.io/kube-controller-manager:v23127
- equal:
path: spec.template.spec.initContainers[2].image
value: registry.k8s.io/kube-apiserver:v99914

- it: k8s version not set, default tag images used for apiServer and controllerManager (virtual scheduler enabled)
set:
controlPlane:
distro:
k8s:
enabled: true
advanced:
virtualScheduler:
enabled: true
asserts:
- equal:
path: spec.template.spec.initContainers[1].image
value: registry.k8s.io/kube-controller-manager:v1.30.2
- equal:
path: spec.template.spec.initContainers[2].image
value: registry.k8s.io/kube-scheduler:v1.30.2
- equal:
path: spec.template.spec.initContainers[3].image
value: registry.k8s.io/kube-apiserver:v1.30.2

- it: k8s version sets image tag for apiServer and controllerManager (virtual scheduler enabled)
set:
controlPlane:
distro:
k8s:
enabled: true
version: v1.35.999
advanced:
virtualScheduler:
enabled: true
asserts:
- equal:
path: spec.template.spec.initContainers[1].image
value: registry.k8s.io/kube-controller-manager:v1.35.999
- equal:
path: spec.template.spec.initContainers[2].image
value: registry.k8s.io/kube-scheduler:v1.35.999
- equal:
path: spec.template.spec.initContainers[3].image
value: registry.k8s.io/kube-apiserver:v1.35.999

- it: k8s version set but overridden by image tag for apiServer and controllerManager (virtual scheduler enabled)
set:
controlPlane:
distro:
k8s:
enabled: true
version: v1.30.999
apiServer:
image:
tag: v99912
controllerManager:
image:
tag: v23123
scheduler:
image:
tag: v123654
advanced:
virtualScheduler:
enabled: true

asserts:
- equal:
path: spec.template.spec.initContainers[1].image
value: registry.k8s.io/kube-controller-manager:v23123
- equal:
path: spec.template.spec.initContainers[2].image
value: registry.k8s.io/kube-scheduler:v123654
- equal:
path: spec.template.spec.initContainers[3].image
value: registry.k8s.io/kube-apiserver:v99912

- it: k8s not version set but image tags for apiServer and controllerManager set (virtual scheduler enabled)
set:
controlPlane:
distro:
k8s:
enabled: true
apiServer:
image:
tag: v99914
controllerManager:
image:
tag: v23127
scheduler:
image:
tag: v123656

advanced:
virtualScheduler:
enabled: true

asserts:
- equal:
path: spec.template.spec.initContainers[1].image
value: registry.k8s.io/kube-controller-manager:v23127
- equal:
path: spec.template.spec.initContainers[2].image
value: registry.k8s.io/kube-scheduler:v123656
- equal:
path: spec.template.spec.initContainers[3].image
value: registry.k8s.io/kube-apiserver:v99914
4 changes: 4 additions & 0 deletions chart/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,10 @@
"type": "boolean",
"description": "Enabled specifies if the K8s distro should be enabled. Only one distro can be enabled at the same time."
},
"version": {
"type": "string",
"description": "Version specifies k8s components (scheduler, kube-controller-manager \u0026 apiserver) version.\nIt is a shortcut for controlPlane.distro.k8s.apiServer.image.tag,\ncontrolPlane.distro.k8s.controllerManager.image.tag and\ncontrolPlane.distro.k8s.scheduler.image.tag\nIf e.g. controlPlane.distro.k8s.version is set to v1.30.1 and\ncontrolPlane.distro.k8s.scheduler.image.tag\n(or controlPlane.distro.k8s.controllerManager.image.tag or controlPlane.distro.k8s.apiServer.image.tag)\nis set to v1.31.0,\nvalue from controlPlane.distro.k8s.\u003ccontrolPlane-component\u003e.image.tag will be used\n(where \u003ccontrolPlane-component is apiServer, controllerManager and scheduler)."
},
"apiServer": {
"$ref": "#/$defs/DistroContainerEnabled",
"description": "APIServer holds configuration specific to starting the api server."
Expand Down
Loading

0 comments on commit b51e00a

Please sign in to comment.