From 0aace1705f883110ca5d42dc2a9903075a978c90 Mon Sep 17 00:00:00 2001 From: Pete Birley Date: Sat, 12 May 2018 12:44:19 -0500 Subject: [PATCH] Helm-Toolkit: Resolve final deltas between OSH and OSH-Infra This PS removes the remaining deltas between OSH and OSH-Infra Change-Id: Ia322b7b62a5b755674d1a244748266e36edcfb8c --- .../templates/manifests/_ingress.yaml.tpl | 3 + .../templates/manifests/_service-ingress.tpl | 3 + .../templates/scripts/_rabbit-init.sh.tpl | 87 +++++++++++-------- .../_kubernetes_entrypoint_init_container.tpl | 8 ++ .../_kubernetes_pod_rbac_serviceaccount.tpl | 9 +- 5 files changed, 71 insertions(+), 39 deletions(-) diff --git a/helm-toolkit/templates/manifests/_ingress.yaml.tpl b/helm-toolkit/templates/manifests/_ingress.yaml.tpl index cf98bf504..09ca8515f 100644 --- a/helm-toolkit/templates/manifests/_ingress.yaml.tpl +++ b/helm-toolkit/templates/manifests/_ingress.yaml.tpl @@ -1,9 +1,12 @@ {{/* Copyright 2017 The Openstack-Helm Authors. + Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/helm-toolkit/templates/manifests/_service-ingress.tpl b/helm-toolkit/templates/manifests/_service-ingress.tpl index 29be3f43b..859b4b116 100644 --- a/helm-toolkit/templates/manifests/_service-ingress.tpl +++ b/helm-toolkit/templates/manifests/_service-ingress.tpl @@ -1,9 +1,12 @@ {{/* Copyright 2017 The Openstack-Helm Authors. + Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at + http://www.apache.org/licenses/LICENSE-2.0 + Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. diff --git a/helm-toolkit/templates/scripts/_rabbit-init.sh.tpl b/helm-toolkit/templates/scripts/_rabbit-init.sh.tpl index 6c45dba44..e54442df7 100644 --- a/helm-toolkit/templates/scripts/_rabbit-init.sh.tpl +++ b/helm-toolkit/templates/scripts/_rabbit-init.sh.tpl @@ -16,52 +16,63 @@ limitations under the License. {{- define "helm-toolkit.scripts.rabbit_init" }} #!/bin/bash -set -ex - +set -e # Extract connection details -RABBIT_HOSTNAME=`echo $RABBITMQ_ADMIN_CONNECTION | awk -F'[@]' '{print $2}' \ - | awk -F'[:/]' '{print $1}'` -RABBIT_PORT=`echo $RABBITMQ_ADMIN_CONNECTION | awk -F'[@]' '{print $2}' \ - | awk -F'[:/]' '{print $2}'` +RABBIT_HOSTNAME=$(echo "${RABBITMQ_ADMIN_CONNECTION}" | \ + awk -F'[@]' '{print $2}' | \ + awk -F'[:/]' '{print $1}') +RABBIT_PORT=$(echo "${RABBITMQ_ADMIN_CONNECTION}" | \ + awk -F'[@]' '{print $2}' | \ + awk -F'[:/]' '{print $2}') # Extract Admin User creadential -RABBITMQ_ADMIN_USERNAME=`echo $RABBITMQ_ADMIN_CONNECTION | awk -F'[@]' '{print $1}' \ - | awk -F'[//:]' '{print $4}'` -RABBITMQ_ADMIN_PASSWORD=`echo $RABBITMQ_ADMIN_CONNECTION | awk -F'[@]' '{print $1}' \ - | awk -F'[//:]' '{print $5}'` +RABBITMQ_ADMIN_USERNAME=$(echo "${RABBITMQ_ADMIN_CONNECTION}" | \ + awk -F'[@]' '{print $1}' | \ + awk -F'[//:]' '{print $4}') +RABBITMQ_ADMIN_PASSWORD=$(echo "${RABBITMQ_ADMIN_CONNECTION}" | \ + awk -F'[@]' '{print $1}' | \ + awk -F'[//:]' '{print $5}') # Extract User creadential -RABBITMQ_USERNAME=`echo $RABBITMQ_USER_CONNECTION | awk -F'[@]' '{print $1}' \ - | awk -F'[//:]' '{print $4}'` -RABBITMQ_PASSWORD=`echo $RABBITMQ_USER_CONNECTION | awk -F'[@]' '{print $1}' \ - | awk -F'[//:]' '{print $5}'` +RABBITMQ_USERNAME=$(echo "${RABBITMQ_USER_CONNECTION}" | \ + awk -F'[@]' '{print $1}' | \ + awk -F'[//:]' '{print $4}') +RABBITMQ_PASSWORD=$(echo "${RABBITMQ_USER_CONNECTION}" | \ + awk -F'[@]' '{print $1}' | \ + awk -F'[//:]' '{print $5}') -# Using admin creadential, list current rabbitmq users -rabbitmqadmin --host=$RABBIT_HOSTNAME --port=$RABBIT_PORT \ - --username=$RABBITMQ_ADMIN_USERNAME --password=$RABBITMQ_ADMIN_PASSWORD \ - list users +# Extract User vHost +RABBITMQ_VHOST=$(echo "${RABBITMQ_USER_CONNECTION}" | \ + awk -F'[@]' '{print $2}' | \ + awk -F'[:/]' '{print $3}') -# if user already exist, credentials will be overwritten -# Using admin creadential, adding new admin rabbitmq user" -rabbitmqadmin --host=$RABBIT_HOSTNAME --port=$RABBIT_PORT \ - --username=$RABBITMQ_ADMIN_USERNAME --password=$RABBITMQ_ADMIN_PASSWORD \ - declare user name=$RABBITMQ_USERNAME password=$RABBITMQ_PASSWORD \ - tags="administrator" +function rabbitmqadmin_cli () { + rabbitmqadmin \ + --host="${RABBIT_HOSTNAME}" \ + --port="${RABBIT_PORT}" \ + --username="${RABBITMQ_ADMIN_USERNAME}" \ + --password="${RABBITMQ_ADMIN_PASSWORD}" \ + ${@} +} -# Declare permissions for new user -rabbitmqadmin --host=$RABBIT_HOSTNAME --port=$RABBIT_PORT \ - --username=$RABBITMQ_ADMIN_USERNAME --password=$RABBITMQ_ADMIN_PASSWORD \ - declare permission vhost="/" user=$RABBITMQ_USERNAME \ - configure=".*" write=".*" read=".*" +echo "Managing: User: ${RABBITMQ_USERNAME}" +rabbitmqadmin_cli \ + declare user \ + name="${RABBITMQ_USERNAME}" \ + password="${RABBITMQ_PASSWORD}" \ + tags="user" -# Using new user creadential, list current rabbitmq users -rabbitmqadmin --host=$RABBIT_HOSTNAME --port=$RABBIT_PORT \ - --username=$RABBITMQ_USERNAME --password=$RABBITMQ_PASSWORD \ - list users - -# Using new user creadential, list permissions -rabbitmqadmin --host=$RABBIT_HOSTNAME --port=$RABBIT_PORT \ - --username=$RABBITMQ_USERNAME --password=$RABBITMQ_PASSWORD \ - list permissions +echo "Managing: vHost: ${RABBITMQ_VHOST}" +rabbitmqadmin_cli \ + declare vhost \ + name="${RABBITMQ_VHOST}" +echo "Managing: Permissions: ${RABBITMQ_USERNAME} on ${RABBITMQ_VHOST}" +rabbitmqadmin_cli \ + declare permission \ + vhost="${RABBITMQ_VHOST}" \ + user="${RABBITMQ_USERNAME}" \ + configure=".*" \ + write=".*" \ + read=".*" {{- end }} diff --git a/helm-toolkit/templates/snippets/_kubernetes_entrypoint_init_container.tpl b/helm-toolkit/templates/snippets/_kubernetes_entrypoint_init_container.tpl index 70a11ec66..79dd63a54 100644 --- a/helm-toolkit/templates/snippets/_kubernetes_entrypoint_init_container.tpl +++ b/helm-toolkit/templates/snippets/_kubernetes_entrypoint_init_container.tpl @@ -22,10 +22,18 @@ limitations under the License. {{- $_ := set $envAll.Values "__kubernetes_entrypoint_init_container" dict -}} {{- $_ := set $envAll.Values.__kubernetes_entrypoint_init_container "deps" dict -}} {{- if and ($envAll.Values.images.local_registry.active) (ne $component "image_repo_sync") -}} +{{- if eq $component "pod_dependency" -}} +{{- $_ := include "helm-toolkit.utils.merge" ( tuple $envAll.Values.__kubernetes_entrypoint_init_container.deps ( index $envAll.Values.pod_dependency ) $envAll.Values.dependencies.dynamic.common.local_image_registry ) -}} +{{- else -}} {{- $_ := include "helm-toolkit.utils.merge" ( tuple $envAll.Values.__kubernetes_entrypoint_init_container.deps ( index $envAll.Values.dependencies.static $component ) $envAll.Values.dependencies.dynamic.common.local_image_registry ) -}} +{{- end -}} +{{- else -}} +{{- if eq $component "pod_dependency" -}} +{{- $_ := set $envAll.Values.__kubernetes_entrypoint_init_container "deps" ( index $envAll.Values.pod_dependency ) -}} {{- else -}} {{- $_ := set $envAll.Values.__kubernetes_entrypoint_init_container "deps" ( index $envAll.Values.dependencies.static $component ) -}} {{- end -}} +{{- end -}} {{- $deps := $envAll.Values.__kubernetes_entrypoint_init_container.deps }} - name: init diff --git a/helm-toolkit/templates/snippets/_kubernetes_pod_rbac_serviceaccount.tpl b/helm-toolkit/templates/snippets/_kubernetes_pod_rbac_serviceaccount.tpl index e0a234f15..b4cf1a65b 100644 --- a/helm-toolkit/templates/snippets/_kubernetes_pod_rbac_serviceaccount.tpl +++ b/helm-toolkit/templates/snippets/_kubernetes_pod_rbac_serviceaccount.tpl @@ -25,12 +25,19 @@ limitations under the License. {{- $_ := set $envAll.Values "__kubernetes_entrypoint_init_container" dict -}} {{- $_ := set $envAll.Values.__kubernetes_entrypoint_init_container "deps" dict -}} {{- if and ($envAll.Values.images.local_registry.active) (ne $component "image_repo_sync") -}} +{{- if eq $component "pod_dependency" -}} +{{- $_ := include "helm-toolkit.utils.merge" ( tuple $envAll.Values.__kubernetes_entrypoint_init_container.deps ( index $envAll.Values.pod_dependency ) $envAll.Values.dependencies.dynamic.common.local_image_registry ) -}} +{{- else -}} {{- $_ := include "helm-toolkit.utils.merge" ( tuple $envAll.Values.__kubernetes_entrypoint_init_container.deps ( index $envAll.Values.dependencies.static $component ) $envAll.Values.dependencies.dynamic.common.local_image_registry ) -}} +{{- end -}} +{{- else -}} +{{- if eq $component "pod_dependency" -}} +{{- $_ := set $envAll.Values.__kubernetes_entrypoint_init_container "deps" ( index $envAll.Values.pod_dependency ) -}} {{- else -}} {{- $_ := set $envAll.Values.__kubernetes_entrypoint_init_container "deps" ( index $envAll.Values.dependencies.static $component ) -}} {{- end -}} +{{- end -}} {{- $deps := $envAll.Values.__kubernetes_entrypoint_init_container.deps }} - --- apiVersion: v1 kind: ServiceAccount