From b4f9db4af86dc0baa566151ffa51e6667b26a09e Mon Sep 17 00:00:00 2001 From: Oleg Tsymbal Date: Wed, 30 Apr 2025 11:43:25 +0300 Subject: [PATCH] Fix(Helm): make tolerations, nodeSelector, affinity more generic (#6771) * Fix(Helm): make tolerations, nodeSelector, affinity more generic Signed-off-by: Oleg Tsymbal * Fix(Helm): make conditionals if and with consistent Signed-off-by: Oleg Tsymbal * Fix(Helm): trigger the build to see if it is a problem with timeout Signed-off-by: Oleg Tsymbal --------- Signed-off-by: Oleg Tsymbal --- .../job-patch/job-createSecret.yaml | 25 +++++++++++------ .../job-patch/job-patchWebhook.yaml | 27 ++++++++++++++----- .../cluster-gateway/cluster-gateway.yaml | 2 +- .../templates/cluster-gateway/job-patch.yaml | 26 +++++++++++++++++- .../templates/test/test-application.yaml | 12 +++++++++ 5 files changed, 75 insertions(+), 17 deletions(-) diff --git a/charts/vela-core/templates/admission-webhooks/job-patch/job-createSecret.yaml b/charts/vela-core/templates/admission-webhooks/job-patch/job-createSecret.yaml index f3eeef972..dd02a14ac 100644 --- a/charts/vela-core/templates/admission-webhooks/job-patch/job-createSecret.yaml +++ b/charts/vela-core/templates/admission-webhooks/job-patch/job-createSecret.yaml @@ -2,7 +2,7 @@ apiVersion: batch/v1 kind: Job metadata: - name: {{ template "kubevela.fullname" . }}-admission-create + name: {{ template "kubevela.fullname" . }}-admission-create namespace: {{ .Release.Namespace }} annotations: "helm.sh/hook": pre-install,pre-upgrade @@ -17,7 +17,7 @@ spec: {{- end }} template: metadata: - name: {{ template "kubevela.fullname" . }}-admission-create + name: {{ template "kubevela.fullname" . }}-admission-create labels: app: {{ template "kubevela.name" . }}-admission-create {{- include "kubevela.labels" . | nindent 8 }} @@ -39,17 +39,26 @@ spec: - --cert-name=tls.crt restartPolicy: OnFailure serviceAccountName: {{ template "kubevela.fullname" . }}-admission - {{- with .Values.admissionWebhooks.patch.nodeSelector }} + {{- if .Values.admissionWebhooks.patch.nodeSelector }} nodeSelector: - {{- toYaml . | nindent 8 }} + {{- toYaml .Values.admissionWebhooks.patch.nodeSelector | nindent 8 }} + {{- else if .Values.nodeSelector }} + nodeSelector: + {{- toYaml .Values.nodeSelector | nindent 8 }} {{- end }} - {{- with .Values.admissionWebhooks.patch.affinity }} + {{- if .Values.admissionWebhooks.patch.affinity }} affinity: -{{ toYaml . | indent 8 }} + {{- toYaml .Values.admissionWebhooks.patch.affinity | nindent 8 }} + {{- else if .Values.affinity }} + affinity: + {{- toYaml .Values.affinity | nindent 8 }} {{- end }} - {{- with .Values.admissionWebhooks.patch.tolerations }} + {{- if .Values.admissionWebhooks.patch.tolerations }} tolerations: -{{ toYaml . | indent 8 }} + {{- toYaml .Values.admissionWebhooks.patch.tolerations | nindent 8 }} + {{- else if .Values.tolerations }} + tolerations: + {{- toYaml .Values.tolerations | nindent 8 }} {{- end }} securityContext: runAsGroup: 2000 diff --git a/charts/vela-core/templates/admission-webhooks/job-patch/job-patchWebhook.yaml b/charts/vela-core/templates/admission-webhooks/job-patch/job-patchWebhook.yaml index 7b8b60aa6..eb2e9847d 100644 --- a/charts/vela-core/templates/admission-webhooks/job-patch/job-patchWebhook.yaml +++ b/charts/vela-core/templates/admission-webhooks/job-patch/job-patchWebhook.yaml @@ -2,7 +2,7 @@ apiVersion: batch/v1 kind: Job metadata: - name: {{ template "kubevela.fullname" . }}-admission-patch + name: {{ template "kubevela.fullname" . }}-admission-patch namespace: {{ .Release.Namespace }} annotations: "helm.sh/hook": post-install,post-upgrade @@ -17,7 +17,7 @@ spec: {{- end }} template: metadata: - name: {{ template "kubevela.fullname" . }}-admission-patch + name: {{ template "kubevela.fullname" . }}-admission-patch labels: app: {{ template "kubevela.name" . }}-admission-patch {{- include "kubevela.labels" . | nindent 8 }} @@ -41,13 +41,26 @@ spec: {{- end }} restartPolicy: OnFailure serviceAccountName: {{ template "kubevela.fullname" . }}-admission - {{- with .Values.admissionWebhooks.patch.affinity }} - affinity: -{{ toYaml . | indent 8 }} + {{- if .Values.admissionWebhooks.patch.nodeSelector }} + nodeSelector: + {{- toYaml .Values.admissionWebhooks.patch.nodeSelector | nindent 8 }} + {{- else if .Values.nodeSelector }} + nodeSelector: + {{- toYaml .Values.nodeSelector | nindent 8 }} {{- end }} - {{- with .Values.admissionWebhooks.patch.tolerations }} + {{- if .Values.admissionWebhooks.patch.affinity }} + affinity: + {{- toYaml .Values.admissionWebhooks.patch.affinity | nindent 8 }} + {{- else if .Values.affinity }} + affinity: + {{- toYaml .Values.affinity | nindent 8 }} + {{- end }} + {{- if .Values.admissionWebhooks.patch.tolerations }} tolerations: -{{ toYaml . | indent 8 }} + {{- toYaml .Values.admissionWebhooks.patch.tolerations | nindent 8 }} + {{- else if .Values.tolerations }} + tolerations: + {{- toYaml .Values.tolerations | nindent 8 }} {{- end }} securityContext: runAsGroup: 2000 diff --git a/charts/vela-core/templates/cluster-gateway/cluster-gateway.yaml b/charts/vela-core/templates/cluster-gateway/cluster-gateway.yaml index c02d85ec0..99d2cc328 100644 --- a/charts/vela-core/templates/cluster-gateway/cluster-gateway.yaml +++ b/charts/vela-core/templates/cluster-gateway/cluster-gateway.yaml @@ -190,4 +190,4 @@ subjects: - kind: ServiceAccount name: {{ include "kubevela.serviceAccountName" . }} namespace: {{ .Release.Namespace }} -{{ end }} \ No newline at end of file +{{ end }} diff --git a/charts/vela-core/templates/cluster-gateway/job-patch.yaml b/charts/vela-core/templates/cluster-gateway/job-patch.yaml index 239564652..f2190a6a8 100644 --- a/charts/vela-core/templates/cluster-gateway/job-patch.yaml +++ b/charts/vela-core/templates/cluster-gateway/job-patch.yaml @@ -95,6 +95,18 @@ spec: runAsGroup: 2000 runAsNonRoot: true runAsUser: 2000 + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} --- apiVersion: batch/v1 kind: Job @@ -138,4 +150,16 @@ spec: runAsGroup: 2000 runAsNonRoot: true runAsUser: 2000 -{{ end }} \ No newline at end of file + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 8 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 8 }} + {{- end }} +{{ end }} diff --git a/charts/vela-core/templates/test/test-application.yaml b/charts/vela-core/templates/test/test-application.yaml index 5b3e80270..4cebf5aeb 100644 --- a/charts/vela-core/templates/test/test-application.yaml +++ b/charts/vela-core/templates/test/test-application.yaml @@ -48,3 +48,15 @@ spec: echo "Application and its components are created" restartPolicy: Never + {{- with .Values.nodeSelector }} + nodeSelector: + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with .Values.affinity }} + affinity: + {{- toYaml . | nindent 4 }} + {{- end }} + {{- with .Values.tolerations }} + tolerations: + {{- toYaml . | nindent 4 }} + {{- end }}