From f0da6fb7483d9fabcd5b3911fa5bcde551d70ba1 Mon Sep 17 00:00:00 2001 From: Andrei Kartashov Date: Mon, 4 Sep 2023 12:16:19 +0700 Subject: [PATCH] bootstrap: fix rendering helm from app with multiple sources --- scripts/bootstrap.sh | 29 ++++++++++++++++++++++++++++- state/gullfaxi/system/argocd.yaml | 7 ++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/scripts/bootstrap.sh b/scripts/bootstrap.sh index 95d4d94..b6639ba 100755 --- a/scripts/bootstrap.sh +++ b/scripts/bootstrap.sh @@ -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 "${@}" diff --git a/state/gullfaxi/system/argocd.yaml b/state/gullfaxi/system/argocd.yaml index c50714e..7432182 100644 --- a/state/gullfaxi/system/argocd.yaml +++ b/state/gullfaxi/system/argocd.yaml @@ -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