From 89033a6f5ec850658cf4c929296f54528e6ed309 Mon Sep 17 00:00:00 2001 From: Ved Ratan <82467006+VedRatan@users.noreply.github.com> Date: Thu, 27 Feb 2025 18:02:42 +0530 Subject: [PATCH] Ndev 21757 NDEV 21756 : feat - added imagePullSecret for cluster-registrator and also included configuration to add cluster labels while registering clusters (#527) * fix: added imagePullSecret in registrator and cluster labels while registering cluster Signed-off-by: VedRatan * chore: added image pull secret for hooks Signed-off-by: VedRatan * chore: bump chart version Signed-off-by: VedRatan * chore: bump chart version Signed-off-by: VedRatan * chore: revert nirmataURL Signed-off-by: VedRatan --------- Signed-off-by: VedRatan --- charts/cluster-registrator/Chart.yaml | 2 +- charts/cluster-registrator/templates/_helpers.tpl | 4 ++++ .../templates/imagepullsecret.yaml | 11 +++++++++++ charts/cluster-registrator/templates/job.yaml | 8 ++++++++ .../templates/pre-delete-hook.yaml | 4 ++++ charts/cluster-registrator/values.yaml | 8 ++++++++ 6 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 charts/cluster-registrator/templates/imagepullsecret.yaml diff --git a/charts/cluster-registrator/Chart.yaml b/charts/cluster-registrator/Chart.yaml index 30f0e992..dd833ad5 100644 --- a/charts/cluster-registrator/Chart.yaml +++ b/charts/cluster-registrator/Chart.yaml @@ -15,7 +15,7 @@ type: application # This is the chart version. This version number should be incremented each time you make changes # to the chart and its templates, including the app version. # Versions are expected to follow Semantic Versioning (https://semver.org/) -version: 0.1.17-rc4 +version: 0.1.17-rc5 # This is the version number of the application being deployed. This version number should be # incremented each time you make changes to the application. Versions are not expected to diff --git a/charts/cluster-registrator/templates/_helpers.tpl b/charts/cluster-registrator/templates/_helpers.tpl index 0521d634..542b9b39 100644 --- a/charts/cluster-registrator/templates/_helpers.tpl +++ b/charts/cluster-registrator/templates/_helpers.tpl @@ -60,3 +60,7 @@ Create the name of the service account to use {{- default "default" .Values.serviceAccount.name }} {{- end }} {{- end }} + +{{- define "registrator.imagePullSecret" }} +{{- printf "{\"auths\":{\"%s\":{\"auth\":\"%s\"}}}" .registryName (printf "%s:%s" .userName .password | b64enc) | b64enc }} +{{- end }} diff --git a/charts/cluster-registrator/templates/imagepullsecret.yaml b/charts/cluster-registrator/templates/imagepullsecret.yaml new file mode 100644 index 00000000..82a75953 --- /dev/null +++ b/charts/cluster-registrator/templates/imagepullsecret.yaml @@ -0,0 +1,11 @@ +{{ if and .Values.imagePullSecret.registryName .Values.imagePullSecret.userName .Values.imagePullSecret.password }} +--- +apiVersion: v1 +kind: Secret +metadata: + name: cluster-registrator-imagepullsecret + namespace: {{ .Values.namespace }} +type: kubernetes.io/dockerconfigjson +data: + .dockerconfigjson: {{ template "registrator.imagePullSecret" .Values.imagePullSecret }} +{{ end }} \ No newline at end of file diff --git a/charts/cluster-registrator/templates/job.yaml b/charts/cluster-registrator/templates/job.yaml index a08d887e..8d45f0cf 100644 --- a/charts/cluster-registrator/templates/job.yaml +++ b/charts/cluster-registrator/templates/job.yaml @@ -413,6 +413,10 @@ metadata: spec: template: spec: + {{ if and .Values.imagePullSecret.registryName .Values.imagePullSecret.userName .Values.imagePullSecret.password }} + imagePullSecrets: + - name: cluster-registrator-imagepullsecret + {{ end }} containers: - name: cluster-registrator image: {{ .Values.registrator.image.registry | default "ghcr.io" }}/{{ .Values.registrator.image.repository | default "nirmata" }}/cluster-registrator:{{ .Chart.AppVersion }} @@ -423,6 +427,10 @@ spec: - "--token-secret" - "{{ .Values.apiTokenSecret }}" {{- end }} + {{ range $key, $value := .Values.clusterLabels }} + - "--labels" + - "{{$key}}:{{$value}}" + {{ end }} env: - name: CLUSTER_NAME value: "{{ .Values.cluster.name }}" diff --git a/charts/cluster-registrator/templates/pre-delete-hook.yaml b/charts/cluster-registrator/templates/pre-delete-hook.yaml index a30fd054..bf1b0cc4 100644 --- a/charts/cluster-registrator/templates/pre-delete-hook.yaml +++ b/charts/cluster-registrator/templates/pre-delete-hook.yaml @@ -13,6 +13,10 @@ spec: spec: restartPolicy: Never serviceAccountName: nirmata-cluster-registrator + {{ if and .Values.imagePullSecret.registryName .Values.imagePullSecret.userName .Values.imagePullSecret.password }} + imagePullSecrets: + - name: cluster-registrator-imagepullsecret + {{ end }} containers: - name: delete-items image: {{ .Values.hooks.image.registry | default "ghcr.io" }}/{{ .Values.hooks.image.repository | default "nirmata" }}/kubectl:{{ .Values.hooks.image.tag }} diff --git a/charts/cluster-registrator/values.yaml b/charts/cluster-registrator/values.yaml index 74fabd00..5e94f7be 100644 --- a/charts/cluster-registrator/values.yaml +++ b/charts/cluster-registrator/values.yaml @@ -17,6 +17,14 @@ proxy: httpsProxy: "" noProxy: "" +imagePullSecret: + registryName: "" + userName: "" + password: "" + +clusterLabels: + # key: value + registrator: image: registry: ""