From 4db355d016e517d27ef0aafe29f6b4dd33ccf8f5 Mon Sep 17 00:00:00 2001 From: Yann Soubeyrand Date: Wed, 6 Mar 2024 18:47:30 +0100 Subject: [PATCH] [kube-state-metrics] make possible to globally override a specific image registry This feature is necessary in cases where repositories coming from different registries are stored in different namespaces in your registry. For example, this is the case with AWS ECR pull through cache feature, which uses the repository prefix to know where to fetch the image from. Signed-off-by: Yann Soubeyrand --- charts/kube-state-metrics/Chart.yaml | 2 +- .../kube-state-metrics/templates/_helpers.tpl | 26 +++++-------------- charts/kube-state-metrics/values.yaml | 4 +++ 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/charts/kube-state-metrics/Chart.yaml b/charts/kube-state-metrics/Chart.yaml index f6596eea8f2f..936c11e45653 100644 --- a/charts/kube-state-metrics/Chart.yaml +++ b/charts/kube-state-metrics/Chart.yaml @@ -7,7 +7,7 @@ keywords: - prometheus - kubernetes type: application -version: 5.16.4 +version: 5.17.0 appVersion: 2.10.1 home: https://github.com/kubernetes/kube-state-metrics/ sources: diff --git a/charts/kube-state-metrics/templates/_helpers.tpl b/charts/kube-state-metrics/templates/_helpers.tpl index a4358c87a106..17b4b27ffbf2 100644 --- a/charts/kube-state-metrics/templates/_helpers.tpl +++ b/charts/kube-state-metrics/templates/_helpers.tpl @@ -121,18 +121,11 @@ Formats imagePullSecrets. Input is (dict "Values" .Values "imagePullSecrets" .{s The image to use for kube-state-metrics */}} {{- define "kube-state-metrics.image" -}} +{{- $registry := index .Values.global.imageRegistries .Values.image.registry | default .Values.global.imageRegistry | default .Values.image.registry -}} {{- if .Values.image.sha }} -{{- if .Values.global.imageRegistry }} -{{- printf "%s/%s:%s@%s" .Values.global.imageRegistry .Values.image.repository (default (printf "v%s" .Chart.AppVersion) .Values.image.tag) .Values.image.sha }} +{{- printf "%s/%s:%s@%s" $registry .Values.image.repository (default (printf "v%s" .Chart.AppVersion) .Values.image.tag) .Values.image.sha }} {{- else }} -{{- printf "%s/%s:%s@%s" .Values.image.registry .Values.image.repository (default (printf "v%s" .Chart.AppVersion) .Values.image.tag) .Values.image.sha }} -{{- end }} -{{- else }} -{{- if .Values.global.imageRegistry }} -{{- printf "%s/%s:%s" .Values.global.imageRegistry .Values.image.repository (default (printf "v%s" .Chart.AppVersion) .Values.image.tag) }} -{{- else }} -{{- printf "%s/%s:%s" .Values.image.registry .Values.image.repository (default (printf "v%s" .Chart.AppVersion) .Values.image.tag) }} -{{- end }} +{{- printf "%s/%s:%s" $registry .Values.image.repository (default (printf "v%s" .Chart.AppVersion) .Values.image.tag) }} {{- end }} {{- end }} @@ -140,17 +133,10 @@ The image to use for kube-state-metrics The image to use for kubeRBACProxy */}} {{- define "kubeRBACProxy.image" -}} +{{- $registry := index .Values.global.imageRegistries .Values.kubeRBACProxy.image.registry | default .Values.global.imageRegistry | default .Values.kubeRBACProxy.image.registry -}} {{- if .Values.kubeRBACProxy.image.sha }} -{{- if .Values.global.imageRegistry }} -{{- printf "%s/%s:%s@%s" .Values.global.imageRegistry .Values.kubeRBACProxy.image.repository (default (printf "v%s" .Chart.AppVersion) .Values.kubeRBACProxy.image.tag) .Values.kubeRBACProxy.image.sha }} +{{- printf "%s/%s:%s@%s" $registry .Values.kubeRBACProxy.image.repository (default (printf "v%s" .Chart.AppVersion) .Values.kubeRBACProxy.image.tag) .Values.kubeRBACProxy.image.sha }} {{- else }} -{{- printf "%s/%s:%s@%s" .Values.kubeRBACProxy.image.registry .Values.kubeRBACProxy.image.repository (default (printf "v%s" .Chart.AppVersion) .Values.kubeRBACProxy.image.tag) .Values.kubeRBACProxy.image.sha }} -{{- end }} -{{- else }} -{{- if .Values.global.imageRegistry }} -{{- printf "%s/%s:%s" .Values.global.imageRegistry .Values.kubeRBACProxy.image.repository (default (printf "v%s" .Chart.AppVersion) .Values.kubeRBACProxy.image.tag) }} -{{- else }} -{{- printf "%s/%s:%s" .Values.kubeRBACProxy.image.registry .Values.kubeRBACProxy.image.repository (default (printf "v%s" .Chart.AppVersion) .Values.kubeRBACProxy.image.tag) }} -{{- end }} +{{- printf "%s/%s:%s" $registry .Values.kubeRBACProxy.image.repository (default (printf "v%s" .Chart.AppVersion) .Values.kubeRBACProxy.image.tag) }} {{- end }} {{- end }} diff --git a/charts/kube-state-metrics/values.yaml b/charts/kube-state-metrics/values.yaml index 75aa2f7e9184..e2762c492cfa 100644 --- a/charts/kube-state-metrics/values.yaml +++ b/charts/kube-state-metrics/values.yaml @@ -27,6 +27,10 @@ global: # # Allow parent charts to override registry hostname imageRegistry: "" + # Allow parent charts to override registries hostname + imageRegistries: {} + # registry.k8s.io: "registry.example.com/k8s" + # quay.io: "registry.example.com/quay" # If set to true, this will deploy kube-state-metrics as a StatefulSet and the data # will be automatically sharded across <.Values.replicas> pods using the built-in