From 20cf2db961a05285a751b3bc96b8fa4e51e3b412 Mon Sep 17 00:00:00 2001 From: Chris Wedgwood Date: Fri, 2 Apr 2021 01:02:36 -0500 Subject: [PATCH] [htk] Jobs; put labels only in the template spec This is an update to address a behavior change introduced with 0ae8f4d21ac2a091f1612e50f4786da5065d4398. Job labels if empty/unspecified are taken from the template. If (any) labels are specified on the job we do not get this behavior. Specifically if we *apply*: apiVersion: batch/v1 kind: Job metadata: # no "labels:" here name: placement-db-init namespace: openstack spec: template: metadata: labels: application: placement component: db-init release_group: placement spec: containers: # do stuffs then *query* we see: apiVersion: batch/v1 kind: Job metadata: # k8s did this for us! labels: application: placement component: db-init job-name: placement-db-init release_group: placement name: placement-db-init namespace: openstack spec: template: metadata: labels: application: placement component: db-init release_group: placement spec: containers: # do stuffs The aforementioned change causes objects we apply and query to look like: apiVersion: batch/v1 kind: Job metadata: # k8s did this for us! labels: application: placement # nothing else! name: placement-db-init namespace: openstack spec: template: metadata: labels: application: placement component: db-init release_group: placement spec: containers: # do stuffs Current users rely on this behavior and deployment systems use job labels for synchronization, those labels being only specified in the template and propagating to the job. This change preserves functionality added recently and restores the previous behavior. The explicit "application" label is no longer needed as the helm-toolkit.snippets.kubernetes_metadata_labels macro provides it. Change-Id: I1582d008217b8848103579b826fae065c538aaf0 --- helm-toolkit/Chart.yaml | 2 +- helm-toolkit/templates/manifests/_job-bootstrap.tpl | 8 +++----- helm-toolkit/templates/manifests/_job-db-drop-mysql.tpl | 8 +++----- helm-toolkit/templates/manifests/_job-db-init-mysql.tpl | 8 +++----- helm-toolkit/templates/manifests/_job-db-sync.tpl | 8 +++----- helm-toolkit/templates/manifests/_job-ks-endpoints.tpl | 8 +++----- helm-toolkit/templates/manifests/_job-ks-service.tpl | 8 +++----- helm-toolkit/templates/manifests/_job-ks-user.yaml.tpl | 8 +++----- .../templates/manifests/_job-rabbit-init.yaml.tpl | 8 +++----- helm-toolkit/templates/manifests/_job-s3-bucket.yaml.tpl | 8 +++----- helm-toolkit/templates/manifests/_job-s3-user.yaml.tpl | 8 +++----- helm-toolkit/templates/manifests/_job_image_repo_sync.tpl | 8 +++----- releasenotes/notes/helm-toolkit.yaml | 1 + 13 files changed, 35 insertions(+), 56 deletions(-) diff --git a/helm-toolkit/Chart.yaml b/helm-toolkit/Chart.yaml index 2df7ddd5e..f22d61e3b 100644 --- a/helm-toolkit/Chart.yaml +++ b/helm-toolkit/Chart.yaml @@ -15,7 +15,7 @@ apiVersion: v1 appVersion: v1.0.0 description: OpenStack-Helm Helm-Toolkit name: helm-toolkit -version: 0.2.8 +version: 0.2.9 home: https://docs.openstack.org/openstack-helm icon: https://www.openstack.org/themes/openstack/images/project-mascots/OpenStack-Helm/OpenStack_Project_OpenStackHelm_vertical.png sources: diff --git a/helm-toolkit/templates/manifests/_job-bootstrap.tpl b/helm-toolkit/templates/manifests/_job-bootstrap.tpl index 946f312f0..63e76083e 100644 --- a/helm-toolkit/templates/manifests/_job-bootstrap.tpl +++ b/helm-toolkit/templates/manifests/_job-bootstrap.tpl @@ -48,11 +48,6 @@ metadata: "helm.sh/hook-delete-policy": before-hook-creation {{- if $jobAnnotations }} {{ toYaml $jobAnnotations | indent 4 }} -{{- end }} - labels: - application: {{ $serviceName }} -{{- if $jobLabels }} -{{ toYaml $jobLabels | indent 4 }} {{- end }} spec: backoffLimit: {{ $backoffLimit }} @@ -63,6 +58,9 @@ spec: metadata: labels: {{ tuple $envAll $serviceName "bootstrap" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 8 }} +{{- if $jobLabels }} +{{ toYaml $jobLabels | indent 8 }} +{{- end }} annotations: {{ tuple $envAll | include "helm-toolkit.snippets.release_uuid" | indent 8 }} spec: diff --git a/helm-toolkit/templates/manifests/_job-db-drop-mysql.tpl b/helm-toolkit/templates/manifests/_job-db-drop-mysql.tpl index 46a6889e1..cfd64ff02 100644 --- a/helm-toolkit/templates/manifests/_job-db-drop-mysql.tpl +++ b/helm-toolkit/templates/manifests/_job-db-drop-mysql.tpl @@ -50,11 +50,6 @@ metadata: "helm.sh/hook-delete-policy": hook-succeeded {{- if $jobAnnotations }} {{ toYaml $jobAnnotations | indent 4 }} -{{- end }} - labels: - application: {{ $serviceName }} -{{- if $jobLabels }} -{{ toYaml $jobLabels | indent 4 }} {{- end }} spec: backoffLimit: {{ $backoffLimit }} @@ -65,6 +60,9 @@ spec: metadata: labels: {{ tuple $envAll $serviceName "db-drop" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 8 }} +{{- if $jobLabels }} +{{ toYaml $jobLabels | indent 8 }} +{{- end }} spec: serviceAccountName: {{ $serviceAccountName }} restartPolicy: OnFailure diff --git a/helm-toolkit/templates/manifests/_job-db-init-mysql.tpl b/helm-toolkit/templates/manifests/_job-db-init-mysql.tpl index de798b657..d5751c829 100644 --- a/helm-toolkit/templates/manifests/_job-db-init-mysql.tpl +++ b/helm-toolkit/templates/manifests/_job-db-init-mysql.tpl @@ -49,11 +49,6 @@ metadata: "helm.sh/hook-delete-policy": before-hook-creation {{- if $jobAnnotations }} {{ toYaml $jobAnnotations | indent 4 }} -{{- end }} - labels: - application: {{ $serviceName }} -{{- if $jobLabels }} -{{ toYaml $jobLabels | indent 4 }} {{- end }} spec: backoffLimit: {{ $backoffLimit }} @@ -64,6 +59,9 @@ spec: metadata: labels: {{ tuple $envAll $serviceName "db-init" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 8 }} +{{- if $jobLabels }} +{{ toYaml $jobLabels | indent 8 }} +{{- end }} annotations: {{ tuple $envAll | include "helm-toolkit.snippets.release_uuid" | indent 8 }} spec: diff --git a/helm-toolkit/templates/manifests/_job-db-sync.tpl b/helm-toolkit/templates/manifests/_job-db-sync.tpl index 76daa9f9c..8e62f4269 100644 --- a/helm-toolkit/templates/manifests/_job-db-sync.tpl +++ b/helm-toolkit/templates/manifests/_job-db-sync.tpl @@ -46,11 +46,6 @@ metadata: "helm.sh/hook-delete-policy": before-hook-creation {{- if $jobAnnotations }} {{ toYaml $jobAnnotations | indent 4 }} -{{- end }} - labels: - application: {{ $serviceName }} -{{- if $jobLabels }} -{{ toYaml $jobLabels | indent 4 }} {{- end }} spec: backoffLimit: {{ $backoffLimit }} @@ -61,6 +56,9 @@ spec: metadata: labels: {{ tuple $envAll $serviceName "db-sync" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 8 }} +{{- if $jobLabels }} +{{ toYaml $jobLabels | indent 8 }} +{{- end }} annotations: {{ tuple $envAll | include "helm-toolkit.snippets.release_uuid" | indent 8 }} spec: diff --git a/helm-toolkit/templates/manifests/_job-ks-endpoints.tpl b/helm-toolkit/templates/manifests/_job-ks-endpoints.tpl index e5377b41e..c1641f4f9 100644 --- a/helm-toolkit/templates/manifests/_job-ks-endpoints.tpl +++ b/helm-toolkit/templates/manifests/_job-ks-endpoints.tpl @@ -49,11 +49,6 @@ metadata: "helm.sh/hook-delete-policy": before-hook-creation {{- if $jobAnnotations }} {{ toYaml $jobAnnotations | indent 4 }} -{{- end }} - labels: - application: {{ $serviceName }} -{{- if $jobLabels }} -{{ toYaml $jobLabels | indent 4 }} {{- end }} spec: backoffLimit: {{ $backoffLimit }} @@ -64,6 +59,9 @@ spec: metadata: labels: {{ tuple $envAll $serviceName "ks-endpoints" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 8 }} +{{- if $jobLabels }} +{{ toYaml $jobLabels | indent 8 }} +{{- end }} annotations: {{ tuple $envAll | include "helm-toolkit.snippets.release_uuid" | indent 8 }} spec: diff --git a/helm-toolkit/templates/manifests/_job-ks-service.tpl b/helm-toolkit/templates/manifests/_job-ks-service.tpl index e5d4f7532..2ab5c443d 100644 --- a/helm-toolkit/templates/manifests/_job-ks-service.tpl +++ b/helm-toolkit/templates/manifests/_job-ks-service.tpl @@ -49,11 +49,6 @@ metadata: "helm.sh/hook-delete-policy": before-hook-creation {{- if $jobAnnotations }} {{ toYaml $jobAnnotations | indent 4 }} -{{- end }} - labels: - application: {{ $serviceName }} -{{- if $jobLabels }} -{{ toYaml $jobLabels | indent 4 }} {{- end }} spec: backoffLimit: {{ $backoffLimit }} @@ -64,6 +59,9 @@ spec: metadata: labels: {{ tuple $envAll $serviceName "ks-service" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 8 }} +{{- if $jobLabels }} +{{ toYaml $jobLabels | indent 8 }} +{{- end }} annotations: {{ tuple $envAll | include "helm-toolkit.snippets.release_uuid" | indent 8 }} spec: diff --git a/helm-toolkit/templates/manifests/_job-ks-user.yaml.tpl b/helm-toolkit/templates/manifests/_job-ks-user.yaml.tpl index f38337b2a..3f089a0d6 100644 --- a/helm-toolkit/templates/manifests/_job-ks-user.yaml.tpl +++ b/helm-toolkit/templates/manifests/_job-ks-user.yaml.tpl @@ -49,11 +49,6 @@ metadata: "helm.sh/hook-delete-policy": before-hook-creation {{- if $jobAnnotations }} {{ toYaml $jobAnnotations | indent 4 }} -{{- end }} - labels: - application: {{ $serviceName }} -{{- if $jobLabels }} -{{ toYaml $jobLabels | indent 4 }} {{- end }} spec: backoffLimit: {{ $backoffLimit }} @@ -64,6 +59,9 @@ spec: metadata: labels: {{ tuple $envAll $serviceName "ks-user" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 8 }} +{{- if $jobLabels }} +{{ toYaml $jobLabels | indent 8 }} +{{- end }} annotations: {{ tuple $envAll | include "helm-toolkit.snippets.release_uuid" | indent 8 }} spec: diff --git a/helm-toolkit/templates/manifests/_job-rabbit-init.yaml.tpl b/helm-toolkit/templates/manifests/_job-rabbit-init.yaml.tpl index 02727d99d..3f2eb8994 100644 --- a/helm-toolkit/templates/manifests/_job-rabbit-init.yaml.tpl +++ b/helm-toolkit/templates/manifests/_job-rabbit-init.yaml.tpl @@ -36,11 +36,6 @@ metadata: "helm.sh/hook-delete-policy": before-hook-creation {{- if $jobAnnotations }} {{ toYaml $jobAnnotations | indent 4 }} -{{- end }} - labels: - application: {{ $serviceName }} -{{- if $jobLabels }} -{{ toYaml $jobLabels | indent 4 }} {{- end }} spec: backoffLimit: {{ $backoffLimit }} @@ -51,6 +46,9 @@ spec: metadata: labels: {{ tuple $envAll $serviceName "rabbit-init" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 8 }} +{{- if $jobLabels }} +{{ toYaml $jobLabels | indent 8 }} +{{- end }} annotations: {{ tuple $envAll | include "helm-toolkit.snippets.release_uuid" | indent 8 }} spec: diff --git a/helm-toolkit/templates/manifests/_job-s3-bucket.yaml.tpl b/helm-toolkit/templates/manifests/_job-s3-bucket.yaml.tpl index ef3dd0382..0d04e63b4 100644 --- a/helm-toolkit/templates/manifests/_job-s3-bucket.yaml.tpl +++ b/helm-toolkit/templates/manifests/_job-s3-bucket.yaml.tpl @@ -44,11 +44,6 @@ metadata: "helm.sh/hook-delete-policy": before-hook-creation {{- if $jobAnnotations }} {{ toYaml $jobAnnotations | indent 4 }} -{{- end }} - labels: - application: {{ $serviceName }} -{{- if $jobLabels }} -{{ toYaml $jobLabels | indent 4 }} {{- end }} spec: backoffLimit: {{ $backoffLimit }} @@ -59,6 +54,9 @@ spec: metadata: labels: {{ tuple $envAll $serviceName "s3-bucket" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 8 }} +{{- if $jobLabels }} +{{ toYaml $jobLabels | indent 8 }} +{{- end }} spec: serviceAccountName: {{ $serviceAccountName | quote }} restartPolicy: OnFailure diff --git a/helm-toolkit/templates/manifests/_job-s3-user.yaml.tpl b/helm-toolkit/templates/manifests/_job-s3-user.yaml.tpl index 9a8fe8581..715602bb2 100644 --- a/helm-toolkit/templates/manifests/_job-s3-user.yaml.tpl +++ b/helm-toolkit/templates/manifests/_job-s3-user.yaml.tpl @@ -43,11 +43,6 @@ metadata: {{ tuple $envAll | include "helm-toolkit.snippets.release_uuid" }} {{- if $jobAnnotations }} {{ toYaml $jobAnnotations | indent 4 }} -{{- end }} - labels: - application: {{ $serviceName }} -{{- if $jobLabels }} -{{ toYaml $jobLabels | indent 4 }} {{- end }} spec: backoffLimit: {{ $backoffLimit }} @@ -58,6 +53,9 @@ spec: metadata: labels: {{ tuple $envAll $serviceName "s3-user" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 8 }} +{{- if $jobLabels }} +{{ toYaml $jobLabels | indent 8 }} +{{- end }} spec: serviceAccountName: {{ $serviceAccountName | quote }} restartPolicy: OnFailure diff --git a/helm-toolkit/templates/manifests/_job_image_repo_sync.tpl b/helm-toolkit/templates/manifests/_job_image_repo_sync.tpl index 3e3facb33..2e67006b4 100644 --- a/helm-toolkit/templates/manifests/_job_image_repo_sync.tpl +++ b/helm-toolkit/templates/manifests/_job_image_repo_sync.tpl @@ -42,11 +42,6 @@ metadata: "helm.sh/hook-delete-policy": before-hook-creation {{- if $jobAnnotations }} {{ toYaml $jobAnnotations | indent 4 }} -{{- end }} - labels: - application: {{ $serviceName }} -{{- if $jobLabels }} -{{ toYaml $jobLabels | indent 4 }} {{- end }} spec: backoffLimit: {{ $backoffLimit }} @@ -57,6 +52,9 @@ spec: metadata: labels: {{ tuple $envAll $serviceName "image-repo-sync" | include "helm-toolkit.snippets.kubernetes_metadata_labels" | indent 8 }} +{{- if $jobLabels }} +{{ toYaml $jobLabels | indent 8 }} +{{- end }} spec: serviceAccountName: {{ $serviceAccountName }} restartPolicy: OnFailure diff --git a/releasenotes/notes/helm-toolkit.yaml b/releasenotes/notes/helm-toolkit.yaml index 243cf3eca..ab79001b9 100644 --- a/releasenotes/notes/helm-toolkit.yaml +++ b/releasenotes/notes/helm-toolkit.yaml @@ -15,4 +15,5 @@ helm-toolkit: - 0.2.6 Add metadata in job templates - 0.2.7 Replace brace expansion with more standardized Posix approach - 0.2.8 Override the expiry of Ingress TLS certificate + - 0.2.9 Jobs; put labels only in the template spec ...