From 5649c2863ca7ccf0f84a61c928bc7b44391400ff Mon Sep 17 00:00:00 2001 From: Lukasz Raczylo Date: Mon, 13 Jan 2025 13:59:18 +0000 Subject: [PATCH] Improve helm chart allowing for lock of the worker image --- chart/Chart.yaml | 4 ++-- chart/templates/_helpers.tpl | 10 +++----- chart/templates/clusterimageexport-crd.yaml | 12 ++++++++++ chart/templates/deployment.yaml | 16 ++++++------- chart/values.yaml | 26 ++++++++++++--------- internal/shared/definitions.go | 10 +++++++- 6 files changed, 49 insertions(+), 29 deletions(-) diff --git a/chart/Chart.yaml b/chart/Chart.yaml index ba66fea..122449b 100644 --- a/chart/Chart.yaml +++ b/chart/Chart.yaml @@ -10,9 +10,9 @@ description: | type: application -version: 0.2.44 +version: 0.5.47 -appVersion: "0.2.44" +appVersion: "0.5.47" home: https://github.com/lukaszraczylo/kubernetes-images-sync-operator diff --git a/chart/templates/_helpers.tpl b/chart/templates/_helpers.tpl index 7ba5edc..076856b 100644 --- a/chart/templates/_helpers.tpl +++ b/chart/templates/_helpers.tpl @@ -51,12 +51,8 @@ app.kubernetes.io/instance: {{ .Release.Name }} {{- end }} {{/* -Create the name of the service account to use +Get the worker image */}} -{{- define "chart.serviceAccountName" -}} -{{- if .Values.serviceAccount.create }} -{{- default (include "chart.fullname" .) .Values.serviceAccount.name }} -{{- else }} -{{- default "default" .Values.serviceAccount.name }} -{{- end }} +{{- define "chart.workerImage" -}} +{{- printf "%s:%s" .Values.images.worker.repository .Values.images.worker.tag }} {{- end }} diff --git a/chart/templates/clusterimageexport-crd.yaml b/chart/templates/clusterimageexport-crd.yaml index 4b98bd9..562a97d 100644 --- a/chart/templates/clusterimageexport-crd.yaml +++ b/chart/templates/clusterimageexport-crd.yaml @@ -25,6 +25,12 @@ spec: - jsonPath: .status.progress name: Progress type: string + - jsonPath: .status.completedImages + name: Images + type: string + - jsonPath: .status.totalImages + name: Total + type: string - jsonPath: .metadata.creationTimestamp name: Age type: date @@ -159,8 +165,14 @@ spec: status: description: ClusterImageExportStatus defines the observed state of ClusterImageExport properties: + completedImages: + description: Number of images that have completed export + type: integer progress: type: string + totalImages: + description: Total number of images to be exported + type: integer type: object type: object served: true diff --git a/chart/templates/deployment.yaml b/chart/templates/deployment.yaml index 633ee6e..820c2bd 100644 --- a/chart/templates/deployment.yaml +++ b/chart/templates/deployment.yaml @@ -4,18 +4,18 @@ metadata: name: {{ include "chart.fullname" . }}-sa labels: control-plane: sa - {{- include "chart.labels" . | nindent 4 }} + {{- include "chart.labels" . | nindent 4 }} spec: replicas: {{ .Values.sa.replicas }} selector: matchLabels: control-plane: sa - {{- include "chart.selectorLabels" . | nindent 6 }} + {{- include "chart.selectorLabels" . | nindent 6 }} template: metadata: labels: control-plane: sa - {{- include "chart.selectorLabels" . | nindent 8 }} + {{- include "chart.selectorLabels" . | nindent 8 }} annotations: kubectl.kubernetes.io/default-container: manager spec: @@ -30,8 +30,9 @@ spec: fieldPath: spec.serviceAccountName - name: KUBERNETES_CLUSTER_DOMAIN value: {{ quote .Values.kubernetesClusterDomain }} - image: {{ .Values.sa.manager.image.repository }}:{{ .Values.sa.manager.image.tag - | default .Chart.AppVersion }} + - name: WORKER_IMAGE + value: {{ include "chart.workerImage" . }} + image: {{ .Values.images.operator.repository }}:{{ .Values.images.operator.tag | default .Chart.AppVersion }} livenessProbe: httpGet: path: /healthz @@ -46,8 +47,7 @@ spec: initialDelaySeconds: 5 periodSeconds: 10 resources: {{- toYaml .Values.sa.manager.resources | nindent 10 }} - securityContext: {{- toYaml .Values.sa.manager.containerSecurityContext | nindent - 10 }} + securityContext: {{- toYaml .Values.sa.manager.containerSecurityContext | nindent 10 }} securityContext: {{- toYaml .Values.sa.podSecurityContext | nindent 8 }} serviceAccountName: {{ include "chart.fullname" . }}-sa - terminationGracePeriodSeconds: 10 \ No newline at end of file + terminationGracePeriodSeconds: 10 diff --git a/chart/values.yaml b/chart/values.yaml index 8142d7b..b5b24b4 100644 --- a/chart/values.yaml +++ b/chart/values.yaml @@ -1,18 +1,22 @@ kubernetesClusterDomain: cluster.local +images: + operator: + repository: ghcr.io/lukaszraczylo/kubernetes-images-sync-operator + tag: 0.5.47 + worker: + repository: ghcr.io/lukaszraczylo/kubernetes-images-sync-worker + tag: 0.5.47 sa: manager: args: - - --metrics-bind-address=:8443 - - --leader-elect - - --health-probe-bind-address=:8081 + - --metrics-bind-address=:8443 + - --leader-elect + - --health-probe-bind-address=:8081 containerSecurityContext: allowPrivilegeEscalation: false capabilities: drop: - - ALL - image: - repository: ghcr.io/lukaszraczylo/kubernetes-images-sync-operator - tag: 0.2.44 + - ALL resources: limits: cpu: 500m @@ -27,8 +31,8 @@ sa: annotations: {} saMetricsService: ports: - - name: https - port: 8443 - protocol: TCP - targetPort: 8443 + - name: https + port: 8443 + protocol: TCP + targetPort: 8443 type: ClusterIP diff --git a/internal/shared/definitions.go b/internal/shared/definitions.go index 1d1dcdd..f2c0870 100644 --- a/internal/shared/definitions.go +++ b/internal/shared/definitions.go @@ -1,11 +1,19 @@ package shared import ( + "os" "regexp" "strings" ) -var BACKUP_JOB_IMAGE = "ghcr.io/lukaszraczylo/kubernetes-images-sync-worker:1.0.2" +var BACKUP_JOB_IMAGE = getWorkerImage() + +func getWorkerImage() string { + if img := os.Getenv("WORKER_IMAGE"); img != "" { + return img + } + return "ghcr.io/lukaszraczylo/kubernetes-images-sync-worker:1.0.2" // fallback +} const ( // AVAILABLE STATUSES