bootstrap: fix rendering helm from app with multiple sources

This commit is contained in:
Andrei Kartashov 2023-09-04 12:16:19 +07:00
parent a592e648fd
commit f0da6fb748
2 changed files with 32 additions and 4 deletions

View file

@ -25,9 +25,10 @@ function main() {
# apply manifests for crucial applications
for app_file in \
${state_path}/system/argo-cd.yaml \
${state_path}/system/argocd.yaml \
; do
namespace=$(yq -e '.spec.destination.namespace' ${app_file})
${kubectl_cmd} create ns ${namespace} || true
helm_render ${app_file} | ${kubectl_cmd} -n ${namespace} apply -f -
done
@ -60,6 +61,17 @@ function help() {
}
function helm_render() {
local app_file=$1
local values_file=${app_file%.yaml}-values.yaml
if [ -f ${values_file} ]; then
helm_render_from_sources "$@"
else
helm_render_from_source "$@"
fi
}
function helm_render_from_source() {
local app_file=$1
local repo=$(yq -e '.spec.source.repoURL' ${app_file})
local chart=$(yq -e '.spec.source.chart' ${app_file})
@ -75,4 +87,19 @@ function helm_render() {
--namespace ${namespace} --values ${values_file}
}
function helm_render_from_sources() {
local app_file=$1
local repo=$(yq -e '.spec.sources[0].repoURL' ${app_file})
local chart=$(yq -e '.spec.sources[0].chart' ${app_file})
local chart_version=$(yq -e '.spec.sources[0].targetRevision' ${app_file})
local release=$(yq -e '.spec.sources[0].helm.releaseName' ${app_file})
local namespace=$(yq -e '.spec.destination.namespace' ${app_file})
local values_file=${app_file%.yaml}-values.yaml
helm template ${release} ${chart} \
--version ${chart_version} --repo ${repo} \
--include-crds \
--namespace ${namespace} --values ${values_file}
}
main "${@}"

View file

@ -16,12 +16,13 @@ spec:
- CreateNamespace=true
# https://argo-cd.readthedocs.io/en/stable/user-guide/multiple_sources/#helm-value-files-from-external-git-repository
sources:
- repoURL: git@github.com:amkartashov/gf-k8s.git
targetRevision: main
ref: values
- repoURL: https://argoproj.github.io/argo-helm
chart: argo-cd
targetRevision: 5.45.0
helm:
releaseName: argocd
valueFiles:
- $values/state/gullfaxi/system/argocd-values.yaml
- repoURL: git@github.com:amkartashov/gf-k8s.git
targetRevision: main
ref: values