feat(pipeline): enables images value override

This patch set allows the ability to override the application image
tag key so it takes in the correct image information during the
deployment stage of Jarvis.

This patch set rebases on [0] to leverage a multichart configmap
paradigm rather than a single chart.

[0] https://review.opendev.org/c/airship/charts/+/772135

Signed-off-by: Tin Lam <tin@irrational.io>
Change-Id: Idbf76bf27460fdd49fa9acf0cd64fb440202c20f
This commit is contained in:
Tin Lam 2021-02-05 18:19:31 -06:00
parent 9675bafb3b
commit 8992254b3f
4 changed files with 96 additions and 45 deletions

View File

@ -54,13 +54,18 @@ data:
},
"namespace": "development-pipeline",
"release_name": "mongodb-bitnami",
"images": {
"applications": {
"mongodb-sharded": {
"tag": "1.0",
"name": "mongodb",
"repo": "mongodb"
"sources": {
"image_map": {
"tag": ["releases", "image", "tag"],
"tmp_name": ["releases", "image", "repository"],
"tmp_repo": ["releases", "image", "registry"]
}
},
"releases": {
"image": {
"registry": "docker.io",
"repository": "bitnami/mongodb-sharded",
"tag": "4.4.3-debian-10-r44"
}
}
},
@ -78,6 +83,14 @@ data:
},
"namespace": "development-pipeline",
"release_name": "mongodb",
"sources": {
"image_map": {
"tag": ["releases", "images", "applications", "mongodb", "tag"],
"tmp_name": ["releases", "images", "applications", "mongodb", "name"],
"tmp_repo": ["releases", "images", "applications", "mongodb", "repo"]
}
},
"releases": {
"images": {
"applications": {
"mongodb": {
@ -88,6 +101,7 @@ data:
}
}
}
}
]
default.json: |
{

View File

@ -23,13 +23,22 @@ spec:
script: |
#!/bin/sh
update-ca-certificates
ansible-playbook -vvv {{ $.Values.tasks.functional.functionalPlaybook }} -i hosts -e '{"stage":"deploy"}' -e @"$(workspaces.development_pipeline_data.path)/default.json" -e @"$(workspaces.development_pipeline_data.path)/cluster.json" -e 'loop_source="$(workspaces.development_pipeline_data.path)/chart.json"'
ansible-playbook -vvv {{ $.Values.tasks.functional.functionalPlaybook }} -i hosts \
-e '{"stage":"deploy"}' \
-e @"$(workspaces.development_pipeline_data.path)/default.json" \
-e @"$(workspaces.development_pipeline_data.path)/cluster.json" \
-e 'loop_source="$(workspaces.development_pipeline_data.path)/chart.json"' \
-e 'datapath="$(workspaces.development_pipeline_data.path)"'
- name: run-helm-tests
image: {{ $.Values.tasks.functional.functionalTestImage }}
script: |
#!/bin/sh
ansible-playbook -vvv {{ $.Values.tasks.functional.functionalPlaybook }} -i hosts -e '{"stage":"test"}' -e @"$(workspaces.development_pipeline_data.path)/default.json" -e @"$(workspaces.development_pipeline_data.path)/cluster.json" -e 'loop_source="$(workspaces.development_pipeline_data.path)/chart.json"'
ansible-playbook -vvv {{ $.Values.tasks.functional.functionalPlaybook }} -i hosts \
-e '{"stage":"test"}' \
-e @"$(workspaces.development_pipeline_data.path)/default.json" \
-e @"$(workspaces.development_pipeline_data.path)/cluster.json" \
-e 'loop_source="$(workspaces.development_pipeline_data.path)/chart.json"'
volumes:
- name: helm-publish-creds
secret:

View File

@ -21,6 +21,7 @@ RUN apt-get update ;\
ca-certificates \
gnupg-agent \
software-properties-common \
moreutils \
gettext-base ;\
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - ;\
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" ;\

View File

@ -6,9 +6,36 @@
when: ("{{ stage }}" == "deploy")
block:
#Deploy CNF
- name: Deploy charts
shell: helm upgrade --install --kubeconfig="{{ cluster_kubeconfig_path }}/kubeconfig" "{{ chart.release_name }}" "{{ chart.project }}-staging/{{ chart.chart_name }}" --version="{{ chart.version }}" --namespace="{{ chart.namespace }}"
shell: |
set -xe ;
CHARTNAME={{ chart.chart_name }} ;
REPO={{ docker_registry }} ;
NAME={{ chart.project }}-staging/{{ chart.chart_name }} ;
jq -c --arg c $CHARTNAME --arg v $REPO 'map(if .repo == $c then .["tmp_repo"] = $v else . end)' {{ datapath }}/image.json | sponge {{ datapath }}/image.json ;
jq -c --arg c $CHARTNAME --arg v $NAME 'map(if .repo == $c then .["tmp_name"] = $v else . end)' {{ datapath }}/image.json | sponge {{ datapath }}/image.json ;
M=$(jq -c --arg c $CHARTNAME 'map(select(.chart_name == $c)) | first | .sources.image_map' {{ datapath }}/chart.json) ;
if [ "$M" != "null" ] && [ -n "$M" ] ; then \
echo $M | jq -r 'keys[]' | while IFS= read -r k; do \
v=$(echo $M | jq -c --arg k $k '.[$k]') ;\
filter=".$k" ;\
value=$(jq -c --arg c $CHARTNAME 'map(select(.image_name == $c)) | first' {{ datapath}}/image.json | jq -r $filter) ;\
jq -r --arg c $CHARTNAME --argjson k $v --arg v $value 'map(if .chart_name == $c then getpath($k) = $v else . end)' {{ datapath }}/chart.json | sponge {{ datapath }}/chart.json ;\
done ; \
fi ;
jq -c --arg c $CHARTNAME 'map(select(.chart_name == $c)) | first | .releases' \
{{ datapath }}/chart.json > {{ datapath }}/{{ chart.chart_name }}-overrides.json ;
cat {{ datapath }}/{{ chart.chart_name }}-overrides.json ;
helm upgrade --install \
--kubeconfig="{{ cluster_kubeconfig_path }}/kubeconfig" \
"{{ chart.release_name }}" "{{ chart.project }}-staging/{{ chart.chart_name }}" \
--version="{{ chart.version }}" \
--values="{{ datapath }}/{{ chart.chart_name }}-overrides.json" \
--namespace="{{ chart.namespace }}"
args:
executable: /bin/bash
loop: "{{ charts }}"
loop_control:
loop_var: "chart"