From bd825495a4ba16e7d7f66f4cca53db37cccdfb79 Mon Sep 17 00:00:00 2001 From: Susanta Gautam Date: Wed, 17 Mar 2021 19:01:27 +0545 Subject: [PATCH] Added helm.sh/hook annotations for nova chart Chart upgrading was failing due to some immutable fields are needed to be upgraded before the jobs can be upgraded. For solving this issue, helm.sh/hook annotations with post-install and post-upgrade has been added. As for hook-weight annotations, we have added these to control the flow of the jobs with hook creation as the jobs are dependent. Like, db-init jobs need to run before db-sync and so on. Also, helm3_hook value is added in values.yaml file in case hooks needs to be disabled if needed. Change-Id: I4d489f5ded94f19dd3fcf58dafde00b18ff5bcae --- nova/Chart.yaml | 2 +- nova/templates/job-bootstrap.yaml | 2 ++ nova/templates/job-db-init.yaml | 8 ++++++++ nova/templates/job-db-sync.yaml | 8 ++++++++ nova/templates/job-image-repo-sync.yaml | 7 +++++++ nova/templates/job-ks-endpoints.yaml | 8 ++++++++ nova/templates/job-ks-service.yaml | 10 +++++++++- nova/templates/job-ks-user.yaml | 8 ++++++++ nova/templates/job-rabbit-init.yaml | 9 +++++++++ nova/values.yaml | 4 ++++ releasenotes/notes/nova.yaml | 1 + 11 files changed, 65 insertions(+), 2 deletions(-) diff --git a/nova/Chart.yaml b/nova/Chart.yaml index b2ed5ddc14..3979a9a23e 100644 --- a/nova/Chart.yaml +++ b/nova/Chart.yaml @@ -14,7 +14,7 @@ apiVersion: v1 appVersion: v1.0.0 description: OpenStack-Helm Nova name: nova -version: 0.2.13 +version: 0.2.14 home: https://docs.openstack.org/nova/latest/ icon: https://www.openstack.org/themes/openstack/images/project-mascots/Nova/OpenStack_Project_Nova_vertical.png sources: diff --git a/nova/templates/job-bootstrap.yaml b/nova/templates/job-bootstrap.yaml index 513e767761..72c66f38e9 100644 --- a/nova/templates/job-bootstrap.yaml +++ b/nova/templates/job-bootstrap.yaml @@ -28,6 +28,8 @@ apiVersion: batch/v1 kind: Job metadata: name: {{ $serviceAccountName | quote }} + labels: + application: {{ $serviceAccountName | quote }} spec: template: metadata: diff --git a/nova/templates/job-db-init.yaml b/nova/templates/job-db-init.yaml index aded33c638..b1ca870544 100644 --- a/nova/templates/job-db-init.yaml +++ b/nova/templates/job-db-init.yaml @@ -12,6 +12,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 := "nova" -}} {{- $dbSvc := dict "adminSecret" .Values.secrets.oslo_db.admin "configFile" (printf "/etc/%s/%s.conf" $serviceName $serviceName ) "logConfigFile" (printf "/etc/%s/logging.conf" $serviceName ) "configDbSection" "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/nova/templates/job-db-sync.yaml b/nova/templates/job-db-sync.yaml index 00953419dc..3cd8cac758 100644 --- a/nova/templates/job-db-sync.yaml +++ b/nova/templates/job-db-sync.yaml @@ -12,6 +12,11 @@ See the License for the specific language governing permissions and limitations under the License. */}} +{{- define "metadata.annotations.job.db_sync" }} +helm.sh/hook: post-install,post-upgrade +helm.sh/hook-weight: "-4" +{{- end }} + {{- define "nova.templates._job_db_sync.env_vars" -}} {{- $envAll := index . 0 }} env: @@ -38,5 +43,8 @@ env: {{- if .Values.manifests.certificates -}} {{- $_ := set $dbSyncJob "dbAdminTlsSecret" .Values.endpoints.oslo_db.auth.admin.secret.tls.internal -}} {{- end -}} +{{- if .Values.helm3_hook }} +{{- $_ := set $dbSyncJob "jobAnnotations" (include "metadata.annotations.job.db_sync" . | fromYaml) }} +{{- end }} {{ $dbSyncJob | include "helm-toolkit.manifests.job_db_sync" }} {{- end }} diff --git a/nova/templates/job-image-repo-sync.yaml b/nova/templates/job-image-repo-sync.yaml index 4e481decba..fe488dd2ad 100644 --- a/nova/templates/job-image-repo-sync.yaml +++ b/nova/templates/job-image-repo-sync.yaml @@ -12,7 +12,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" "nova" -}} +{{- 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/nova/templates/job-ks-endpoints.yaml b/nova/templates/job-ks-endpoints.yaml index 3d9530e0c0..5057ebc119 100644 --- a/nova/templates/job-ks-endpoints.yaml +++ b/nova/templates/job-ks-endpoints.yaml @@ -12,10 +12,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: "-2" +{{- end }} + {{- if .Values.manifests.job_ks_endpoints }} {{- $ksServiceJob := dict "envAll" . "serviceName" "nova" "serviceTypes" ( tuple "compute" ) -}} {{- if .Values.manifests.certificates -}} {{- $_ := set $ksServiceJob "tlsSecret" .Values.secrets.tls.compute.osapi.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/nova/templates/job-ks-service.yaml b/nova/templates/job-ks-service.yaml index 1d4f4e2191..626edcb288 100644 --- a/nova/templates/job-ks-service.yaml +++ b/nova/templates/job-ks-service.yaml @@ -12,10 +12,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: "-3" +{{- end }} + {{- if .Values.manifests.job_ks_service }} -{{- $ksServiceJob := dict "envAll" . "serviceName" "nova" "serviceTypes" ( tuple "compute" ) -}} +{{- $ksServiceJob := dict "envAll" . "serviceName" "nova" "serviceTypes" ( tuple "compute" ) "jobAnnotations" (include "metadata.annotations.job.ks_service" . | fromYaml) -}} {{- if .Values.manifests.certificates -}} {{- $_ := set $ksServiceJob "tlsSecret" .Values.secrets.tls.compute.osapi.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/nova/templates/job-ks-user.yaml b/nova/templates/job-ks-user.yaml index 4fff45560d..e5613cc9f7 100644 --- a/nova/templates/job-ks-user.yaml +++ b/nova/templates/job-ks-user.yaml @@ -12,10 +12,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" "nova" -}} {{- if .Values.manifests.certificates -}} {{- $_ := set $ksUserJob "tlsSecret" .Values.secrets.tls.compute.osapi.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/nova/templates/job-rabbit-init.yaml b/nova/templates/job-rabbit-init.yaml index 780a788848..ffbb270774 100644 --- a/nova/templates/job-rabbit-init.yaml +++ b/nova/templates/job-rabbit-init.yaml @@ -11,10 +11,19 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */}} + +{{- define "metadata.annotations.job.rabbit_init" }} +helm.sh/hook: post-install,post-upgrade +helm.sh/hook-weight: "-4" +{{- end }} + {{- if .Values.manifests.job_rabbit_init }} {{- $rmqUserJob := dict "envAll" . "serviceName" "nova" -}} {{- if .Values.manifests.certificates -}} {{- $_ := set $rmqUserJob "tlsSecret" .Values.endpoints.oslo_messaging.auth.admin.secret.tls.internal -}} {{- end -}} +{{- if .Values.helm3_hook }} +{{- $_ := set $rmqUserJob "jobAnnotations" (include "metadata.annotations.job.rabbit_init" . | fromYaml) }} +{{- end }} {{ $rmqUserJob | include "helm-toolkit.manifests.job_rabbit_init" }} {{- end }} diff --git a/nova/values.yaml b/nova/values.yaml index 29366dfeee..e801c7bb77 100644 --- a/nova/values.yaml +++ b/nova/values.yaml @@ -2799,6 +2799,10 @@ network_policy: egress: - {} +# 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/nova.yaml b/releasenotes/notes/nova.yaml index 71378e5e69..2b748c1e91 100644 --- a/releasenotes/notes/nova.yaml +++ b/releasenotes/notes/nova.yaml @@ -34,4 +34,5 @@ nova: - 0.2.11 Add Victoria and Wallaby releases support - 0.2.12 Bootstrap flavor creation efficiencies - 0.2.13 Add missing 'runlock' hostMount when enable_scsi + - 0.2.14 Use helm.sh/hook annotations for jobs ...