mirror of
https://github.com/amkartashov/gf-k8s.git
synced 2026-01-10 17:39:43 +00:00
refactor state dir structure
This commit is contained in:
parent
0dfbccadff
commit
d3ba3115eb
7 changed files with 53 additions and 24 deletions
|
|
@ -24,13 +24,15 @@ function main() {
|
||||||
local state_path="$(git rev-parse --show-toplevel)/state/${env_name}"
|
local state_path="$(git rev-parse --show-toplevel)/state/${env_name}"
|
||||||
|
|
||||||
# apply manifests for crucial applications
|
# apply manifests for crucial applications
|
||||||
for app_file in \
|
for app in \
|
||||||
${state_path}/system/argocd.yaml \
|
argocd \
|
||||||
; do
|
; do
|
||||||
|
app_dir=${state_path}/system/${app}
|
||||||
|
app_file=${state_path}/system/${app}/application.yaml
|
||||||
namespace=$(yq -e '.spec.destination.namespace' ${app_file})
|
namespace=$(yq -e '.spec.destination.namespace' ${app_file})
|
||||||
|
|
||||||
${kubectl_cmd} create ns ${namespace} || true
|
${kubectl_cmd} create ns ${namespace} || true
|
||||||
helm_render ${app_file} | ${kubectl_cmd} -n ${namespace} apply -f -
|
helm_render ${app_dir} | ${kubectl_cmd} -n ${namespace} apply -f -
|
||||||
done
|
done
|
||||||
|
|
||||||
${kubectl_cmd} apply -n argocd -R \
|
${kubectl_cmd} apply -n argocd -R \
|
||||||
|
|
@ -61,10 +63,10 @@ function help() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function helm_render() {
|
function helm_render() {
|
||||||
local app_file=$1
|
local app_dir=$1
|
||||||
local values_file=${app_file%.yaml}-values.yaml
|
local app_file=${app_dir}/application.yaml
|
||||||
|
|
||||||
if [ -f ${values_file} ]; then
|
if yq -e '.spec | has("sources")' ${app_file} >/dev/null; then
|
||||||
helm_render_from_sources "$@"
|
helm_render_from_sources "$@"
|
||||||
else
|
else
|
||||||
helm_render_from_source "$@"
|
helm_render_from_source "$@"
|
||||||
|
|
@ -72,7 +74,8 @@ function helm_render() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function helm_render_from_source() {
|
function helm_render_from_source() {
|
||||||
local app_file=$1
|
local app_dir=$1
|
||||||
|
local app_file=${app_dir}/application.yaml
|
||||||
local repo=$(yq -e '.spec.source.repoURL' ${app_file})
|
local repo=$(yq -e '.spec.source.repoURL' ${app_file})
|
||||||
local chart=$(yq -e '.spec.source.chart' ${app_file})
|
local chart=$(yq -e '.spec.source.chart' ${app_file})
|
||||||
local chart_version=$(yq -e '.spec.source.targetRevision' ${app_file})
|
local chart_version=$(yq -e '.spec.source.targetRevision' ${app_file})
|
||||||
|
|
@ -81,17 +84,22 @@ function helm_render_from_source() {
|
||||||
release=$(yq -e '.spec.source.helm.releaseName' ${app_file}) \
|
release=$(yq -e '.spec.source.helm.releaseName' ${app_file}) \
|
||||||
|| release=$(yq -e '.metadata.name' ${app_file})
|
|| release=$(yq -e '.metadata.name' ${app_file})
|
||||||
local namespace=$(yq -e '.spec.destination.namespace' ${app_file})
|
local namespace=$(yq -e '.spec.destination.namespace' ${app_file})
|
||||||
local values_file=$(mktemp /tmp/${release}_${chart}_${chart_version}.yaml.XXXX)
|
local values_arg=""
|
||||||
yq '.spec.source.helm.values // ""' ${app_file} > ${values_file}
|
if yq -e '.spec.source.helm | has("values")' ${app_file}; then
|
||||||
|
local values_file=$(mktemp /tmp/${release}_${chart}_${chart_version}.yaml.XXXX)
|
||||||
|
values_arg="--values ${values_file}"
|
||||||
|
yq '.spec.source.helm.values // ""' ${app_file} > ${values_file}
|
||||||
|
fi
|
||||||
|
|
||||||
helm template ${release} ${chart} \
|
helm template ${release} ${chart} \
|
||||||
--version ${chart_version} --repo ${repo} \
|
--version ${chart_version} --repo ${repo} \
|
||||||
--include-crds \
|
--include-crds \
|
||||||
--namespace ${namespace} --values ${values_file}
|
--namespace ${namespace} ${values_arg}
|
||||||
}
|
}
|
||||||
|
|
||||||
function helm_render_from_sources() {
|
function helm_render_from_sources() {
|
||||||
local app_file=$1
|
local app_dir=$1
|
||||||
|
local app_file=${app_dir}/application.yaml
|
||||||
local repo=$(yq -e '.spec.sources[0].repoURL' ${app_file})
|
local repo=$(yq -e '.spec.sources[0].repoURL' ${app_file})
|
||||||
local chart=$(yq -e '.spec.sources[0].chart' ${app_file})
|
local chart=$(yq -e '.spec.sources[0].chart' ${app_file})
|
||||||
local chart_version=$(yq -e '.spec.sources[0].targetRevision' ${app_file})
|
local chart_version=$(yq -e '.spec.sources[0].targetRevision' ${app_file})
|
||||||
|
|
@ -99,12 +107,16 @@ function helm_render_from_sources() {
|
||||||
release=$(yq -e '.spec.sources[0].helm.releaseName' ${app_file}) \
|
release=$(yq -e '.spec.sources[0].helm.releaseName' ${app_file}) \
|
||||||
|| release=$(yq -e '.metadata.name' ${app_file})
|
|| release=$(yq -e '.metadata.name' ${app_file})
|
||||||
local namespace=$(yq -e '.spec.destination.namespace' ${app_file})
|
local namespace=$(yq -e '.spec.destination.namespace' ${app_file})
|
||||||
local values_file=${app_file%.yaml}-values.yaml
|
local values_file=${app_dir}/values.yaml
|
||||||
|
local values_arg=""
|
||||||
|
if [ -f ${values_file} ]; then
|
||||||
|
values_arg="--values ${values_file}"
|
||||||
|
fi
|
||||||
|
|
||||||
helm template ${release} ${chart} \
|
helm template ${release} ${chart} \
|
||||||
--version ${chart_version} --repo ${repo} \
|
--version ${chart_version} --repo ${repo} \
|
||||||
--include-crds \
|
--include-crds \
|
||||||
--namespace ${namespace} --values ${values_file}
|
--namespace ${namespace} ${values_arg}
|
||||||
}
|
}
|
||||||
|
|
||||||
main "${@}"
|
main "${@}"
|
||||||
|
|
|
||||||
|
|
@ -34,8 +34,8 @@ spec:
|
||||||
targetRevision: main
|
targetRevision: main
|
||||||
directory:
|
directory:
|
||||||
# https://argo-cd.readthedocs.io/en/stable/user-guide/directory/
|
# https://argo-cd.readthedocs.io/en/stable/user-guide/directory/
|
||||||
recurse: false
|
recurse: true
|
||||||
exclude: '{*-values.yaml}'
|
exclude: '{values.yaml,*/manifests/*}'
|
||||||
syncPolicy:
|
syncPolicy:
|
||||||
automated:
|
automated:
|
||||||
prune: true
|
prune: true
|
||||||
|
|
|
||||||
|
|
@ -36,8 +36,8 @@ spec:
|
||||||
targetRevision: main
|
targetRevision: main
|
||||||
directory:
|
directory:
|
||||||
# https://argo-cd.readthedocs.io/en/stable/user-guide/directory/
|
# https://argo-cd.readthedocs.io/en/stable/user-guide/directory/
|
||||||
recurse: false
|
recurse: true
|
||||||
exclude: '{*-values.yaml}'
|
exclude: '{values.yaml,*/manifests/*}'
|
||||||
syncPolicy:
|
syncPolicy:
|
||||||
automated:
|
automated:
|
||||||
prune: true
|
prune: true
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,13 @@ spec:
|
||||||
selfHeal: true
|
selfHeal: true
|
||||||
syncOptions:
|
syncOptions:
|
||||||
- CreateNamespace=true
|
- CreateNamespace=true
|
||||||
source:
|
sources:
|
||||||
repoURL: https://charts.jetstack.io
|
- repoURL: https://charts.jetstack.io
|
||||||
chart: cert-manager
|
chart: cert-manager
|
||||||
targetRevision: 1.12.4
|
targetRevision: 1.12.4
|
||||||
helm:
|
helm:
|
||||||
values: |
|
values: |
|
||||||
# nothing
|
installCRDs: true
|
||||||
|
- repoURL: git@github.com:amkartashov/gf-k8s.git
|
||||||
|
targetRevision: main
|
||||||
|
path: state/gullfaxi/system/cert-manager/manifests/
|
||||||
|
|
@ -0,0 +1,14 @@
|
||||||
|
apiVersion: cert-manager.io/v1
|
||||||
|
kind: ClusterIssuer
|
||||||
|
metadata:
|
||||||
|
name: letsencrypt
|
||||||
|
spec:
|
||||||
|
acme:
|
||||||
|
server: https://acme-v02.api.letsencrypt.org/directory
|
||||||
|
email: a@ioot.xyz
|
||||||
|
privateKeySecretRef:
|
||||||
|
name: letsencrypt
|
||||||
|
solvers:
|
||||||
|
- http01:
|
||||||
|
ingress:
|
||||||
|
class: nginx
|
||||||
Loading…
Reference in a new issue