From d8d77c85404bd5d9133fc3534d8756ef6443d03f Mon Sep 17 00:00:00 2001 From: Hung Nguyen Date: Mon, 20 May 2024 14:01:24 -0400 Subject: [PATCH 1/3] update feedsUpgradeJob to use annotations and labels Signed-off-by: Hung Nguyen --- stable/feeds/templates/_common.tpl | 14 +++++++++++++- .../templates/hooks/post-upgrade/upgrade_job.yaml | 8 ++++---- .../templates/hooks/pre-upgrade/upgrade_job.yaml | 8 ++++---- .../templates/hooks/pre-upgrade/upgrade_rbac.yaml | 14 +++++++------- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/stable/feeds/templates/_common.tpl b/stable/feeds/templates/_common.tpl index b41d2ce9..7b6b40cd 100644 --- a/stable/feeds/templates/_common.tpl +++ b/stable/feeds/templates/_common.tpl @@ -2,12 +2,18 @@ Common annotations */}} {{- define "feeds.common.annotations" -}} -{{- if and (not .nil) (not .Values.annotations) }} +{{- $component := .component -}} +{{- if and (not .nil) (not .Values.annotations) (not (index .Values (print $component)).annotations) }} {{- print "{}" }} {{- else }} {{- with .Values.annotations }} {{- toYaml . }} {{- end }} + {{- if $component }} + {{- with (index .Values (print $component)).annotations }} +{{ toYaml . }} + {{- end }} + {{- end }} {{- end }} {{- end -}} @@ -76,6 +82,7 @@ Common environment variables Common labels */}} {{- define "feeds.common.labels" -}} +{{- $component := .component -}} app.kubernetes.io/name: {{ template "feeds.fullname" . }} app.kubernetes.io/component: feeds app.kubernetes.io/instance: {{ .Release.Name }} @@ -86,6 +93,11 @@ helm.sh/chart: {{ printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | {{- with .Values.labels }} {{ toYaml . }} {{- end }} +{{- if $component }} + {{- with (index .Values (print $component)).labels }} +{{ toYaml . }} + {{- end }} +{{- end }} {{- end -}} {{/* diff --git a/stable/feeds/templates/hooks/post-upgrade/upgrade_job.yaml b/stable/feeds/templates/hooks/post-upgrade/upgrade_job.yaml index 44bdfaa4..276414f5 100644 --- a/stable/feeds/templates/hooks/post-upgrade/upgrade_job.yaml +++ b/stable/feeds/templates/hooks/post-upgrade/upgrade_job.yaml @@ -1,12 +1,12 @@ {{- if and .Values.feedsUpgradeJob.enabled .Values.feedsUpgradeJob.usePostUpgradeHook -}} - +{{- $component := "feedsUpgradeJob" -}} apiVersion: batch/v1 kind: Job metadata: name: {{ template "feeds.upgradeJob.fullname" . }} namespace: {{ .Release.Namespace }} - labels: {{- include "feeds.common.labels" . | nindent 4 }} - annotations: {{- include "feeds.common.annotations" (merge (dict "nil" true) .) | nindent 4 }} + labels: {{- include "feeds.common.labels" (merge (dict "component" $component) .) | nindent 4 }} + annotations: {{- include "feeds.common.annotations" (merge (dict "component" $component "nil" true) .) | nindent 4 }} {{- if not .Values.feedsUpgradeJob.force }} "helm.sh/hook": post-upgrade "helm.sh/hook-weight": "0" @@ -15,7 +15,7 @@ spec: template: metadata: name: {{ template "feeds.upgradeJob.fullname" . }} - labels: {{- include "feeds.common.labels" . | nindent 8 }} + labels: {{- include "feeds.common.labels" (merge (dict "component" $component) .) | nindent 8 }} annotations: {{- include "feeds.common.annotations" . | nindent 8 }} spec: {{- with .Values.securityContext }} diff --git a/stable/feeds/templates/hooks/pre-upgrade/upgrade_job.yaml b/stable/feeds/templates/hooks/pre-upgrade/upgrade_job.yaml index c7181f6b..9f3daf06 100644 --- a/stable/feeds/templates/hooks/pre-upgrade/upgrade_job.yaml +++ b/stable/feeds/templates/hooks/pre-upgrade/upgrade_job.yaml @@ -1,12 +1,12 @@ {{- if and .Values.feedsUpgradeJob.enabled (not .Values.feedsUpgradeJob.usePostUpgradeHook) -}} - +{{- $component := "feedsUpgradeJob" -}} apiVersion: batch/v1 kind: Job metadata: name: {{ template "feeds.upgradeJob.fullname" . }} namespace: {{ .Release.Namespace }} - labels: {{- include "feeds.common.labels" . | nindent 4 }} - annotations: {{- include "feeds.common.annotations" (merge (dict "nil" true) .) | nindent 4 }} + labels: {{- include "feeds.common.labels" (merge (dict "component" $component) .) | nindent 4 }} + annotations: {{- include "feeds.common.annotations" (merge (dict "component" $component "nil" true) .) | nindent 4 }} {{- if not .Values.feedsUpgradeJob.force }} "helm.sh/hook": pre-upgrade "helm.sh/hook-weight": "3" @@ -19,7 +19,7 @@ spec: template: metadata: name: {{ template "feeds.upgradeJob.fullname" . }} - labels: {{- include "feeds.common.labels" . | nindent 8 }} + labels: {{- include "feeds.common.labels" (merge (dict "component" $component) .) | nindent 8 }} annotations: {{- include "feeds.common.annotations" . | nindent 8 }} spec: {{- with .Values.securityContext }} diff --git a/stable/feeds/templates/hooks/pre-upgrade/upgrade_rbac.yaml b/stable/feeds/templates/hooks/pre-upgrade/upgrade_rbac.yaml index f7f55279..eb71ccea 100644 --- a/stable/feeds/templates/hooks/pre-upgrade/upgrade_rbac.yaml +++ b/stable/feeds/templates/hooks/pre-upgrade/upgrade_rbac.yaml @@ -1,13 +1,13 @@ {{- if and .Values.feedsUpgradeJob.enabled .Values.feedsUpgradeJob.rbacCreate (not .Values.feedsUpgradeJob.usePostUpgradeHook) -}} - +{{- $component := "feedsUpgradeJob" -}} --- apiVersion: v1 kind: ServiceAccount metadata: name: {{ template "feeds.fullname" . }}-upgrade-sa namespace: {{ .Release.Namespace }} - labels: {{- include "feeds.common.labels" . | nindent 4 }} - annotations: {{- include "feeds.common.annotations" (merge (dict "nil" true) .) | nindent 4 }} + labels: {{- include "feeds.common.labels" (merge (dict "component" $component) .) | nindent 4 }} + annotations: {{- include "feeds.common.annotations" (merge (dict "component" $component "nil" true) .) | nindent 4 }} {{- if not .Values.feedsUpgradeJob.force }} "helm.sh/hook": pre-upgrade "helm.sh/hook-weight": "1" @@ -19,8 +19,8 @@ kind: RoleBinding metadata: name: {{ template "feeds.fullname" . }}-upgrade-role-binding namespace: {{ .Release.Namespace }} - labels: {{- include "feeds.common.labels" . | nindent 4 }} - annotations: {{- include "feeds.common.annotations" (merge (dict "nil" true) .) | nindent 4 }} + labels: {{- include "feeds.common.labels" (merge (dict "component" $component) .) | nindent 4 }} + annotations: {{- include "feeds.common.annotations" (merge (dict "component" $component "nil" true) .) | nindent 4 }} {{- if not .Values.feedsUpgradeJob.force }} "helm.sh/hook": pre-upgrade "helm.sh/hook-weight": "1" @@ -40,8 +40,8 @@ kind: Role metadata: name: {{ template "feeds.fullname" . }}-upgrade-role namespace: {{ .Release.Namespace }} - labels: {{- include "feeds.common.labels" . | nindent 4 }} - annotations: {{- include "feeds.common.annotations" (merge (dict "nil" true) .) | nindent 4 }} + labels: {{- include "feeds.common.labels" (merge (dict "component" $component) .) | nindent 4 }} + annotations: {{- include "feeds.common.annotations" (merge (dict "component" $component "nil" true) .) | nindent 4 }} {{- if not .Values.feedsUpgradeJob.force }} "helm.sh/hook": pre-upgrade "helm.sh/hook-weight": "1" From 1d5c4f8a3efe54c16719584611754f95490ed757 Mon Sep 17 00:00:00 2001 From: Hung Nguyen Date: Mon, 20 May 2024 14:01:33 -0400 Subject: [PATCH 2/3] adding tests Signed-off-by: Hung Nguyen --- stable/feeds/tests/common_helpers_test.yaml | 88 +++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/stable/feeds/tests/common_helpers_test.yaml b/stable/feeds/tests/common_helpers_test.yaml index c3b5d123..6b2dd17c 100644 --- a/stable/feeds/tests/common_helpers_test.yaml +++ b/stable/feeds/tests/common_helpers_test.yaml @@ -79,6 +79,94 @@ tests: foo: bar bar: baz + - it: should render component annotations and global annotations + templates: + - templates/hooks/pre-upgrade/upgrade_job.yaml + - templates/hooks/pre-upgrade/upgrade_rbac.yaml + documentIndex: 0 + set: + feedsUpgradeJob: + annotations: + foo: upgradeJobAnnotation1 + bar: upgradeJobAnnotation2 + annotations: + fizz: globalAnnotation1 + boo: globalAnnotation2 + asserts: + - isSubset: + path: metadata.annotations + content: + fizz: globalAnnotation1 + boo: globalAnnotation2 + foo: upgradeJobAnnotation1 + bar: upgradeJobAnnotation2 + + - it: should render component labels and global labels + templates: + - templates/hooks/pre-upgrade/upgrade_job.yaml + - templates/hooks/pre-upgrade/upgrade_rbac.yaml + documentIndex: 0 + set: + feedsUpgradeJob: + labels: + foo: upgradeJoblabel1 + bar: upgradeJoblabel2 + labels: + fizz: global1 + boo: global2 + asserts: + - isSubset: + path: metadata.labels + content: + fizz: global1 + boo: global2 + foo: upgradeJoblabel1 + bar: upgradeJoblabel2 + + - it: should render component labels and global labels postupgradeJob + templates: + - templates/hooks/post-upgrade/upgrade_job.yaml + documentIndex: 0 + set: + feedsUpgradeJob: + usePostUpgradeHook: true + labels: + foo: upgradeJoblabel1 + bar: upgradeJoblabel2 + labels: + fizz: global1 + boo: global2 + asserts: + - isSubset: + path: metadata.labels + content: + fizz: global1 + boo: global2 + foo: upgradeJoblabel1 + bar: upgradeJoblabel2 + + - it: should render component annotations and global annotations postupgradeJob + templates: + - templates/hooks/post-upgrade/upgrade_job.yaml + documentIndex: 0 + set: + feedsUpgradeJob: + usePostUpgradeHook: true + annotations: + foo: upgradeJob1 + bar: upgradeJob2 + annotations: + fizz: global1 + boo: global2 + asserts: + - isSubset: + path: metadata.annotations + content: + fizz: global1 + boo: global2 + foo: upgradeJob1 + bar: upgradeJob2 + - it: should render file checksum/secret annotation template: deployment.yaml documentIndex: 0 From 9740cf00072a4313a5e7222659263144e3f4447e Mon Sep 17 00:00:00 2001 From: Hung Nguyen Date: Mon, 20 May 2024 14:04:03 -0400 Subject: [PATCH 3/3] bumping feeds chart version Signed-off-by: Hung Nguyen --- stable/feeds/Chart.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stable/feeds/Chart.yaml b/stable/feeds/Chart.yaml index 7d77b04a..3c8f41cb 100644 --- a/stable/feeds/Chart.yaml +++ b/stable/feeds/Chart.yaml @@ -1,7 +1,7 @@ apiVersion: v2 name: feeds type: application -version: "2.5.0" +version: "2.5.1" appVersion: "5.5.0" kubeVersion: 1.23.x - 1.27.x || 1.23.x-x - 1.29.x-x description: Anchore feeds service