From 7ca67915a307479d6e9c6d008137c7dda85c5cac Mon Sep 17 00:00:00 2001 From: Susanta Gautam Date: Wed, 17 Mar 2021 19:12:42 +0545 Subject: [PATCH] Added helm.sh/hook annotations for placement chart jobs Chart upgrade fails as some immutable fields in job are needed to be applied earlier then the job manifests. To solve the problem, helm.sh/hook annotations with post-install and post-upgrade values can be used so that the jobs are the last one to be applied after all the manifests. As jobs are dependent one services, hook weight is used to maintain the job creation order. Change-Id: I7551977599d376e4d240fff5cb9d002fc918d9fe --- placement/Chart.yaml | 2 +- placement/templates/job-db-init.yaml | 8 ++++++++ placement/templates/job-image-repo-sync.yaml | 7 +++++++ placement/templates/job-ks-endpoints.yaml | 8 ++++++++ placement/templates/job-ks-service.yaml | 8 ++++++++ placement/templates/job-ks-user.yaml | 8 ++++++++ placement/values.yaml | 4 ++++ releasenotes/notes/placement.yaml | 1 + 8 files changed, 45 insertions(+), 1 deletion(-) diff --git a/placement/Chart.yaml b/placement/Chart.yaml index ca7c2ee59d..c33d8f5f91 100644 --- a/placement/Chart.yaml +++ b/placement/Chart.yaml @@ -16,7 +16,7 @@ apiVersion: v1 appVersion: v1.0.0 description: OpenStack-Helm Placement name: placement -version: 0.2.2 +version: 0.2.3 home: https://docs.openstack.org/placement/latest/ icon: https://www.openstack.org/themes/openstack/images/project-mascots/Placement/OpenStack_Project_Placement_vertical.png sources: diff --git a/placement/templates/job-db-init.yaml b/placement/templates/job-db-init.yaml index c74667aad2..31e1aec749 100644 --- a/placement/templates/job-db-init.yaml +++ b/placement/templates/job-db-init.yaml @@ -14,6 +14,11 @@ See the License for the specific language governing permissions and limitations under the License. */}} +{{- define "metadata.annotations.job.db_init" }} +helm.sh/hook: post-install,post-upgrade +helm.sh/hook-weight: "-5" +{{- end }} + {{- if .Values.manifests.job_db_init }} {{- $serviceName := "placement" -}} {{- $dbApi := dict "adminSecret" .Values.secrets.oslo_db.admin "configFile" (printf "/etc/%s/%s.conf" $serviceName $serviceName ) "logConfigFile" (printf "/etc/%s/logging.conf" $serviceName ) "configDbSection" "placement_database" "configDbKey" "connection" -}} @@ -22,5 +27,8 @@ limitations under the License. {{- if .Values.manifests.certificates -}} {{- $_ := set $dbInitJob "dbAdminTlsSecret" .Values.endpoints.oslo_db.auth.admin.secret.tls.internal -}} {{- end -}} +{{- if .Values.helm3_hook }} +{{- $_ := set $dbInitJob "jobAnnotations" (include "metadata.annotations.job.db_init" . | fromYaml) -}} +{{- end }} {{ $dbInitJob | include "helm-toolkit.manifests.job_db_init_mysql" }} {{- end }} diff --git a/placement/templates/job-image-repo-sync.yaml b/placement/templates/job-image-repo-sync.yaml index dc135df931..dd89227688 100644 --- a/placement/templates/job-image-repo-sync.yaml +++ b/placement/templates/job-image-repo-sync.yaml @@ -14,7 +14,14 @@ See the License for the specific language governing permissions and limitations under the License. */}} +{{- define "metadata.annotations.job.repo_sync" }} +helm.sh/hook: post-install,post-upgrade +{{- end }} + {{- if and .Values.manifests.job_image_repo_sync .Values.images.local_registry.active }} {{- $imageRepoSyncJob := dict "envAll" . "serviceName" "placement" -}} +{{- if .Values.helm3_hook }} +{{- $_ := set $imageRepoSyncJob "jobAnnotations" (include "metadata.annotations.job.repo_sync" . | fromYaml) }} +{{- end }} {{ $imageRepoSyncJob | include "helm-toolkit.manifests.job_image_repo_sync" }} {{- end }} diff --git a/placement/templates/job-ks-endpoints.yaml b/placement/templates/job-ks-endpoints.yaml index ce5f634705..abd7994c8c 100644 --- a/placement/templates/job-ks-endpoints.yaml +++ b/placement/templates/job-ks-endpoints.yaml @@ -14,10 +14,18 @@ See the License for the specific language governing permissions and limitations under the License. */}} +{{- define "metadata.annotations.job.ks_endpoints" }} +helm.sh/hook: post-install,post-upgrade +helm.sh/hook-weight: "1" +{{- end }} + {{- if .Values.manifests.job_ks_endpoints }} {{- $ksServiceJob := dict "envAll" . "serviceName" "placement" "serviceTypes" ( tuple "placement" ) -}} {{- if .Values.manifests.certificates -}} {{- $_ := set $ksServiceJob "tlsSecret" .Values.secrets.tls.placement.api.internal -}} {{- end -}} +{{- if .Values.helm3_hook }} +{{- $_ := set $ksServiceJob "jobAnnotations" (include "metadata.annotations.job.ks_endpoints" . | fromYaml) -}} +{{- end }} {{ $ksServiceJob | include "helm-toolkit.manifests.job_ks_endpoints" }} {{- end }} diff --git a/placement/templates/job-ks-service.yaml b/placement/templates/job-ks-service.yaml index ee6b896649..f972aba4e3 100644 --- a/placement/templates/job-ks-service.yaml +++ b/placement/templates/job-ks-service.yaml @@ -14,10 +14,18 @@ See the License for the specific language governing permissions and limitations under the License. */}} +{{- define "metadata.annotations.job.ks_service" }} +helm.sh/hook: post-install,post-upgrade +helm.sh/hook-weight: "-2" +{{- end }} + {{- if .Values.manifests.job_ks_service }} {{- $ksServiceJob := dict "envAll" . "serviceName" "placement" "serviceTypes" ( tuple "placement" ) -}} {{- if .Values.manifests.certificates -}} {{- $_ := set $ksServiceJob "tlsSecret" .Values.secrets.tls.placement.api.internal -}} {{- end -}} +{{- if .Values.helm3_hook }} +{{- $_ := set $ksServiceJob "jobAnnotations" (include "metadata.annotations.job.ks_service" . | fromYaml) -}} +{{- end }} {{ $ksServiceJob | include "helm-toolkit.manifests.job_ks_service" }} {{- end }} diff --git a/placement/templates/job-ks-user.yaml b/placement/templates/job-ks-user.yaml index 70d9207450..6670913312 100644 --- a/placement/templates/job-ks-user.yaml +++ b/placement/templates/job-ks-user.yaml @@ -14,10 +14,18 @@ See the License for the specific language governing permissions and limitations under the License. */}} +{{- define "metadata.annotations.job.ks_user" }} +helm.sh/hook: post-install,post-upgrade +helm.sh/hook-weight: "-1" +{{- end }} + {{- if .Values.manifests.job_ks_user }} {{- $ksUserJob := dict "envAll" . "serviceName" "placement" -}} {{- if .Values.manifests.certificates -}} {{- $_ := set $ksUserJob "tlsSecret" .Values.secrets.tls.placement.api.internal -}} {{- end -}} +{{- if .Values.helm3_hook }} +{{- $_ := set $ksUserJob "jobAnnotations" (include "metadata.annotations.job.ks_user" . | fromYaml) -}} +{{- end }} {{ $ksUserJob | include "helm-toolkit.manifests.job_ks_user" }} {{- end }} diff --git a/placement/values.yaml b/placement/values.yaml index 5cda0ea85b..57d9eb480a 100644 --- a/placement/values.yaml +++ b/placement/values.yaml @@ -483,6 +483,10 @@ dependencies: - endpoint: internal service: oslo_db +# NOTE(helm_hook): helm_hook might break for helm2 binary. +# set helm3_hook: false when using the helm2 binary. +helm3_hook: true + manifests: certificates: false configmap_bin: true diff --git a/releasenotes/notes/placement.yaml b/releasenotes/notes/placement.yaml index c46b5c9456..85945aa4ed 100644 --- a/releasenotes/notes/placement.yaml +++ b/releasenotes/notes/placement.yaml @@ -11,4 +11,5 @@ placement: - 0.2.0 Remove support for releases before T - 0.2.1 Add Ussuri release support - 0.2.2 Add Victoria and Wallaby releases support + - 0.2.3 Added helm.sh/hook annotations for Jobs ...