From f0d4b3135f806286701e8c6a09f9ebfb45099b08 Mon Sep 17 00:00:00 2001 From: Chris Werner Rau Date: Mon, 11 Sep 2023 15:12:04 +0200 Subject: [PATCH] feat(t8s-cluster/management-cluster): simplify k8s version check (#548) --- .../management-cluster/check-k8s-version.yaml | 47 ++----------------- 1 file changed, 3 insertions(+), 44 deletions(-) diff --git a/charts/t8s-cluster/templates/management-cluster/check-k8s-version.yaml b/charts/t8s-cluster/templates/management-cluster/check-k8s-version.yaml index b43952eff..862aec8d7 100644 --- a/charts/t8s-cluster/templates/management-cluster/check-k8s-version.yaml +++ b/charts/t8s-cluster/templates/management-cluster/check-k8s-version.yaml @@ -2,48 +2,7 @@ {{- $existingCluster := lookup $cluster.apiVersion $cluster.kind $cluster.metadata.namespace $cluster.metadata.name }} {{/* Should always pass, just doesn't work for local diffs 😥 */}} {{- if $existingCluster }} -apiVersion: batch/v1 -kind: Job -metadata: - name: check-k8s-version - namespace: {{ .Release.Namespace }} - labels: {{- include "common.labels.standard" . | nindent 4 }} - annotations: - helm.sh/hook: pre-upgrade - helm.sh/hook-delete-policy: before-hook-creation,hook-succeeded -spec: - backoffLimit: 0 - template: - spec: - restartPolicy: Never - automountServiceAccountToken: false - securityContext: - runAsNonRoot: true - runAsGroup: 1000 - runAsUser: 1000 - fsGroup: 1000 - containers: - - name: check-k8s-version - image: {{ include "common.images.image" (dict "imageRoot" .Values.global.semver.image "global" .Values.global) }} - {{- if .Values.global.semver.image.digest }} - imagePullPolicy: IfNotPresent - {{- else }} - imagePullPolicy: Always - {{- end }} - securityContext: - readOnlyRootFilesystem: true - privileged: false - capabilities: - drop: - - ALL - allowPrivilegeEscalation: false - seccompProfile: - type: RuntimeDefault - command: - - semver - - --range - - '>={{ $existingCluster.spec.version }}' - {{- with .Values.version }} - - {{ printf "v%d.%d.%d" (.major | int) (.minor | int) (.patch | int) }} - {{- end }} + {{- if semverCompare (printf "<%s" ($existingCluster.spec.version | trimPrefix "v")) (printf "%d.%d.%d" (.Values.version.major | int) (.Values.version.minor | int) (.Values.version.patch | int)) -}} + {{- fail "Cannot downgrade cluster version" -}} + {{- end }} {{- end }}