From c9fecf436311c46b2a69fee6f31f45d4f34f57f1 Mon Sep 17 00:00:00 2001 From: David Levanon Date: Sun, 1 Dec 2024 14:09:53 +0200 Subject: [PATCH 1/2] secrets are optional --- charts/k8s-read/templates/_helpers.tpl | 13 ++++++++++++- charts/k8s-read/templates/deployment.yaml | 2 +- charts/k8s-read/templates/oltp-secret.yaml | 9 +++------ charts/static-sbom/templates/_helpers.tpl | 13 ++++++++++++- charts/static-sbom/templates/deployment.yaml | 2 +- charts/static-sbom/templates/oltp-secret.yaml | 9 +++------ 6 files changed, 32 insertions(+), 16 deletions(-) diff --git a/charts/k8s-read/templates/_helpers.tpl b/charts/k8s-read/templates/_helpers.tpl index 0a4910c6..85d1551d 100644 --- a/charts/k8s-read/templates/_helpers.tpl +++ b/charts/k8s-read/templates/_helpers.tpl @@ -65,13 +65,15 @@ Create the name of the service account to use {{- $emptyImagePullSecrets := list (dict "name" "") }} {{- $global := .Values.global | default dict }} {{- $globalImagePullSecrets := dig "imagePullSecrets" $emptyImagePullSecrets $global }} +{{- $globalImageCredentialsUsername := dig "imageCredentials" "username" "" $global }} +{{- $username := coalesce .Values.imageCredentials.username $globalImageCredentialsUsername }} {{- if (not (empty (index .Values.imagePullSecrets 0).name)) }} imagePullSecrets: {{- toYaml .Values.imagePullSecrets | nindent 2 }} {{- else if (not (empty (index $globalImagePullSecrets 0).name)) }} imagePullSecrets: {{- toYaml .Values.global.imagePullSecrets | nindent 2 }} -{{- else }} +{{- else if (not (empty $username)) }} imagePullSecrets: - name: k8s-read-miggo-regcred {{- end }} @@ -80,3 +82,12 @@ imagePullSecrets: {{- define "k8s-read.configMapCacheName" -}} {{- default (printf "%s-cache" (include "k8s-read.fullname" .)) .Values.config.cache.configMap.name }} {{- end }} + +{{- define "common.otlp.authHeader" -}} +{{- $global := .Values.global | default dict }} +{{- $globalOtlpHttpAuthHeader := dig "output" "otlp" "httpAuthHeader" "" $global }} +{{- $authHeader := coalesce .Values.output.otlp.httpAuthHeader $globalOtlpHttpAuthHeader "" }} +{{- if $authHeader }} +{{- $authHeader -}} +{{- end }} +{{- end }} diff --git a/charts/k8s-read/templates/deployment.yaml b/charts/k8s-read/templates/deployment.yaml index f51a9a8c..ebdb1930 100644 --- a/charts/k8s-read/templates/deployment.yaml +++ b/charts/k8s-read/templates/deployment.yaml @@ -68,7 +68,7 @@ spec: {{- if .Values.output.otlp.existingSecret }} - secretRef: name: {{ .Values.output.otlp.existingSecret }} - {{- else }} + {{- else if (not (empty (include "common.otlp.authHeader" .))) }} - secretRef: name: k8s-read-otlp-secret {{- end }} diff --git a/charts/k8s-read/templates/oltp-secret.yaml b/charts/k8s-read/templates/oltp-secret.yaml index d6988b47..a48bdfdb 100644 --- a/charts/k8s-read/templates/oltp-secret.yaml +++ b/charts/k8s-read/templates/oltp-secret.yaml @@ -1,14 +1,11 @@ -{{- $global := .Values.global | default dict }} -{{- $globalOtlpHttpAuthHeader := dig "output" "otlp" "httpAuthHeader" "" $global }} -{{- $authHeader := coalesce .Values.output.otlp.httpAuthHeader $globalOtlpHttpAuthHeader }} -{{- if and (empty .Values.output.otlp.existingSecret) (not (empty $authHeader)) }} +{{- if and (empty .Values.output.otlp.existingSecret) (not (empty (include "common.otlp.authHeader" .))) }} apiVersion: v1 kind: Secret metadata: name: k8s-read-otlp-secret type: Opaque data: - K8S_READ_OTLP_AUTH_HEADER: {{ $authHeader | b64enc | quote }} - K8S_READ_METRIC_OTLP_AUTH_HEADER: {{ $authHeader | b64enc | quote }} + K8S_READ_OTLP_AUTH_HEADER: {{ (include "common.otlp.authHeader" .) | b64enc | quote }} + K8S_READ_METRIC_OTLP_AUTH_HEADER: {{ (include "common.otlp.authHeader" .) | b64enc | quote }} {{- end }} --- \ No newline at end of file diff --git a/charts/static-sbom/templates/_helpers.tpl b/charts/static-sbom/templates/_helpers.tpl index 0224da15..8f48d890 100644 --- a/charts/static-sbom/templates/_helpers.tpl +++ b/charts/static-sbom/templates/_helpers.tpl @@ -65,13 +65,15 @@ Create the name of the service account to use {{- $emptyImagePullSecrets := list (dict "name" "") }} {{- $global := .Values.global | default dict }} {{- $globalImagePullSecrets := dig "imagePullSecrets" $emptyImagePullSecrets $global }} +{{- $globalImageCredentialsUsername := dig "imageCredentials" "username" "" $global }} +{{- $username := coalesce .Values.imageCredentials.username $globalImageCredentialsUsername }} {{- if (not (empty (index .Values.imagePullSecrets 0).name)) }} imagePullSecrets: {{- toYaml .Values.imagePullSecrets | nindent 2 }} {{- else if (not (empty (index $globalImagePullSecrets 0).name)) }} imagePullSecrets: {{- toYaml .Values.global.imagePullSecrets | nindent 2 }} -{{- else }} +{{- else if (not (empty $username)) }} imagePullSecrets: - name: static-sbom-miggo-regcred {{- end }} @@ -80,3 +82,12 @@ imagePullSecrets: {{- define "static-sbom.configMapCacheName" -}} {{- default (printf "%s-cache" (include "static-sbom.fullname" .)) .Values.config.cache.configMap.name }} {{- end }} + +{{- define "common.otlp.authHeader" -}} +{{- $global := .Values.global | default dict }} +{{- $globalOtlpHttpAuthHeader := dig "output" "otlp" "httpAuthHeader" "" $global }} +{{- $authHeader := coalesce .Values.output.otlp.httpAuthHeader $globalOtlpHttpAuthHeader "" }} +{{- if $authHeader }} +{{- $authHeader -}} +{{- end }} +{{- end }} diff --git a/charts/static-sbom/templates/deployment.yaml b/charts/static-sbom/templates/deployment.yaml index db327426..58a67559 100644 --- a/charts/static-sbom/templates/deployment.yaml +++ b/charts/static-sbom/templates/deployment.yaml @@ -74,7 +74,7 @@ spec: {{- if .Values.output.otlp.existingSecret }} - secretRef: name: {{ .Values.output.otlp.existingSecret }} - {{- else }} + {{- else if (not (empty (include "common.otlp.authHeader" .))) }} - secretRef: name: static-sbom-otlp-secret {{- end }} diff --git a/charts/static-sbom/templates/oltp-secret.yaml b/charts/static-sbom/templates/oltp-secret.yaml index 040ead0a..5e1482fb 100644 --- a/charts/static-sbom/templates/oltp-secret.yaml +++ b/charts/static-sbom/templates/oltp-secret.yaml @@ -1,14 +1,11 @@ -{{- $global := .Values.global | default dict }} -{{- $globalOtlpHttpAuthHeader := dig "output" "otlp" "httpAuthHeader" "" $global }} -{{- $authHeader := coalesce .Values.output.otlp.httpAuthHeader $globalOtlpHttpAuthHeader }} -{{- if and (empty .Values.output.otlp.existingSecret) (not (empty $authHeader)) }} +{{- if and (empty .Values.output.otlp.existingSecret) (not (empty (include "common.otlp.authHeader" .))) }} apiVersion: v1 kind: Secret metadata: name: static-sbom-otlp-secret type: Opaque data: - STATIC_SBOM_OTLP_AUTH_HEADER: {{ $authHeader | b64enc | quote }} - STATIC_SBOM_METRIC_OTLP_AUTH_HEADER: {{ $authHeader | b64enc | quote }} + STATIC_SBOM_OTLP_AUTH_HEADER: {{ (include "common.otlp.authHeader" .) | b64enc | quote }} + STATIC_SBOM_METRIC_OTLP_AUTH_HEADER: {{ (include "common.otlp.authHeader" .) | b64enc | quote }} {{- end }} --- From 1302458945465caf0a661f3974a71cf7e8628e6f Mon Sep 17 00:00:00 2001 From: dvdlevanon-miggo Date: Sun, 1 Dec 2024 12:15:21 +0000 Subject: [PATCH 2/2] [AUTO GITHUB] Bump chart versions --- charts/k8s-integration/Chart.yaml | 2 +- charts/k8s-read/Chart.yaml | 2 +- charts/static-sbom/Chart.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/charts/k8s-integration/Chart.yaml b/charts/k8s-integration/Chart.yaml index 37a7a15f..f308e893 100644 --- a/charts/k8s-integration/Chart.yaml +++ b/charts/k8s-integration/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 name: k8s-integration description: A Helm chart for miggo's k8s-integration type: application -version: 0.0.8 +version: 0.0.9 appVersion: "0.0.1" dependencies: - name: k8s-read diff --git a/charts/k8s-read/Chart.yaml b/charts/k8s-read/Chart.yaml index a275fd9e..ddf79158 100644 --- a/charts/k8s-read/Chart.yaml +++ b/charts/k8s-read/Chart.yaml @@ -2,5 +2,5 @@ apiVersion: v2 name: k8s-read description: A Helm chart for miggo's k8s-read type: application -version: 0.0.8 +version: 0.0.9 appVersion: "0.0.1" diff --git a/charts/static-sbom/Chart.yaml b/charts/static-sbom/Chart.yaml index 3ee63c81..2e484e84 100644 --- a/charts/static-sbom/Chart.yaml +++ b/charts/static-sbom/Chart.yaml @@ -2,5 +2,5 @@ apiVersion: v2 name: static-sbom description: A Helm chart for miggo's static-sbom type: application -version: 0.0.11 +version: 0.0.12 appVersion: "0.0.1"