feat: new custom helm hooks
This commit is contained in:
parent
30bc95408a
commit
af29836a27
@ -5,7 +5,7 @@ set -x
|
|||||||
|
|
||||||
ARTIFACTS=($(echo $1 | tr "," "\n"))
|
ARTIFACTS=($(echo $1 | tr "," "\n"))
|
||||||
ACTION="${2:-apply}"
|
ACTION="${2:-apply}"
|
||||||
ARGOCD="${3:-false}"
|
ARGOCD="${3:-true}"
|
||||||
|
|
||||||
LOCAL_DEV=1
|
LOCAL_DEV=1
|
||||||
|
|
||||||
@ -36,46 +36,6 @@ parse_version() {
|
|||||||
|
|
||||||
KUBE_VERSION=$(parse_version $KUBE_VERSION)
|
KUBE_VERSION=$(parse_version $KUBE_VERSION)
|
||||||
|
|
||||||
### Various hooks for modules
|
|
||||||
|
|
||||||
################
|
|
||||||
# cert-manager #
|
|
||||||
################
|
|
||||||
function cert-manager-post() {
|
|
||||||
# If any error occurs, wait for initial webhook deployment and try again
|
|
||||||
# see: https://cert-manager.io/docs/concepts/webhook/#webhook-connection-problems-shortly-after-cert-manager-installation
|
|
||||||
|
|
||||||
if [ $rc -ne 0 ]; then
|
|
||||||
wait_for "kubectl get deployment -n $namespace cert-manager-webhook"
|
|
||||||
kubectl rollout status deployment -n $namespace cert-manager-webhook
|
|
||||||
wait_for 'kubectl get validatingwebhookconfigurations -o yaml | grep "caBundle: LS0"'
|
|
||||||
fi
|
|
||||||
|
|
||||||
wait_for "kubectl get ClusterIssuer -n $namespace kubezero-local-ca-issuer"
|
|
||||||
kubectl wait --timeout=180s --for=condition=Ready -n $namespace ClusterIssuer/kubezero-local-ca-issuer
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
###########
|
|
||||||
# ArgoCD #
|
|
||||||
###########
|
|
||||||
function argocd-pre() {
|
|
||||||
kubectl delete job argo-argocd-redis-secret-init -n argocd || true
|
|
||||||
|
|
||||||
for f in $CLUSTER/secrets/argocd-*.yaml; do
|
|
||||||
kubectl apply -f $f
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
###########
|
|
||||||
# Metrics #
|
|
||||||
###########
|
|
||||||
# Cleanup patch jobs from previous runs , ArgoCD does this automatically
|
|
||||||
function metrics-pre() {
|
|
||||||
kubectl delete jobs --field-selector status.successful=1 -n monitoring
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
### Main
|
### Main
|
||||||
get_kubezero_values $ARGOCD
|
get_kubezero_values $ARGOCD
|
||||||
|
@ -139,7 +139,7 @@ function delete_ns() {
|
|||||||
|
|
||||||
|
|
||||||
# Extract crds via helm calls
|
# Extract crds via helm calls
|
||||||
function _crds() {
|
function crds() {
|
||||||
helm secrets --evaluate-templates template $(chart_location $chart) -n $namespace --name-template $module $targetRevision --include-crds -f $WORKDIR/values.yaml $API_VERSIONS --kube-version $KUBE_VERSION $@ | python3 -c '
|
helm secrets --evaluate-templates template $(chart_location $chart) -n $namespace --name-template $module $targetRevision --include-crds -f $WORKDIR/values.yaml $API_VERSIONS --kube-version $KUBE_VERSION $@ | python3 -c '
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
import yaml
|
import yaml
|
||||||
@ -201,9 +201,18 @@ function _helm() {
|
|||||||
|
|
||||||
yq eval '.spec.source.helm.valuesObject' $WORKDIR/kubezero/templates/${module}.yaml > $WORKDIR/values.yaml
|
yq eval '.spec.source.helm.valuesObject' $WORKDIR/kubezero/templates/${module}.yaml > $WORKDIR/values.yaml
|
||||||
|
|
||||||
|
# extract remote chart or copy local to access hooks
|
||||||
|
if [ -z "$LOCAL_DEV" ]; then
|
||||||
|
helm pull $(chart_location $chart) --untar -d $WORKDIR
|
||||||
|
else
|
||||||
|
cp -r $(chart_location $chart) $WORKDIR
|
||||||
|
fi
|
||||||
|
|
||||||
if [ $action == "crds" ]; then
|
if [ $action == "crds" ]; then
|
||||||
# Allow custom CRD handling
|
# Pre-crd hook
|
||||||
declare -F ${module}-crds && ${module}-crds || _crds
|
[ -x $WORKDIR/$chart/hooks.d/pre-crds.sh ] && (cd $WORKDIR; ./$chart/hooks.d/pre-crds.sh)
|
||||||
|
|
||||||
|
crds
|
||||||
|
|
||||||
elif [ $action == "apply" -o $action == "replace" ]; then
|
elif [ $action == "apply" -o $action == "replace" ]; then
|
||||||
echo "using values to $action of module $module: "
|
echo "using values to $action of module $module: "
|
||||||
@ -213,7 +222,7 @@ function _helm() {
|
|||||||
create_ns $namespace
|
create_ns $namespace
|
||||||
|
|
||||||
# Optional pre hook
|
# Optional pre hook
|
||||||
declare -F ${module}-pre && ${module}-pre
|
[ -x $WORKDIR/$chart/hooks.d/pre-install.sh ] && (cd $WORKDIR; ./$chart/hooks.d/pre-install.sh)
|
||||||
|
|
||||||
render
|
render
|
||||||
[ $action == "replace" ] && kubectl replace -f $WORKDIR/helm.yaml $(field_manager $ARGOCD) && rc=$? || rc=$?
|
[ $action == "replace" ] && kubectl replace -f $WORKDIR/helm.yaml $(field_manager $ARGOCD) && rc=$? || rc=$?
|
||||||
@ -222,7 +231,7 @@ function _helm() {
|
|||||||
[ $action == "apply" -o $rc -ne 0 ] && kubectl apply -f $WORKDIR/helm.yaml --server-side --force-conflicts $(field_manager $ARGOCD) && rc=$? || rc=$?
|
[ $action == "apply" -o $rc -ne 0 ] && kubectl apply -f $WORKDIR/helm.yaml --server-side --force-conflicts $(field_manager $ARGOCD) && rc=$? || rc=$?
|
||||||
|
|
||||||
# Optional post hook
|
# Optional post hook
|
||||||
declare -F ${module}-post && ${module}-post
|
[ -x $WORKDIR/$chart/hooks.d/post-install.sh ] && (cd $WORKDIR; ./$chart/hooks.d/post-install.sh)
|
||||||
|
|
||||||
elif [ $action == "delete" ]; then
|
elif [ $action == "delete" ]; then
|
||||||
render
|
render
|
||||||
|
@ -8,10 +8,18 @@ import yaml
|
|||||||
def migrate(values):
|
def migrate(values):
|
||||||
"""Actual changes here"""
|
"""Actual changes here"""
|
||||||
|
|
||||||
# remove syncOptions from root app
|
# migrate kubezero root app of apps to Argo chart
|
||||||
try:
|
try:
|
||||||
if values["kubezero"]["syncPolicy"]:
|
if values["kubezero"]:
|
||||||
values["kubezero"].pop("syncPolicy")
|
try:
|
||||||
|
values["kubezero"].pop("syncPolicy")
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
values["kubezero"]["gitSync"]["repoUrl"] = values["kubezero"]["gitSync"].pop("repoURL")
|
||||||
|
|
||||||
|
values["argo"]["argo-cd"]["kubezero"] = values["kubezero"]["gitSync"]
|
||||||
|
|
||||||
|
values.pop("kubezero")
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
30
charts/kubezero-argo/.helmignore
Normal file
30
charts/kubezero-argo/.helmignore
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
# Patterns to ignore when building packages.
|
||||||
|
# This supports shell glob matching, relative path matching, and
|
||||||
|
# negation (prefixed with !). Only one pattern per line.
|
||||||
|
.DS_Store
|
||||||
|
# Common VCS dirs
|
||||||
|
.git/
|
||||||
|
.gitignore
|
||||||
|
.bzr/
|
||||||
|
.bzrignore
|
||||||
|
.hg/
|
||||||
|
.hgignore
|
||||||
|
.svn/
|
||||||
|
# Common backup files
|
||||||
|
*.swp
|
||||||
|
*.bak
|
||||||
|
*.tmp
|
||||||
|
*.orig
|
||||||
|
*~
|
||||||
|
# Various IDEs
|
||||||
|
.project
|
||||||
|
.idea/
|
||||||
|
*.tmproj
|
||||||
|
.vscode/
|
||||||
|
|
||||||
|
README.md.gotmpl
|
||||||
|
dashboards.yaml
|
||||||
|
*.patch
|
||||||
|
*.sh
|
||||||
|
*.py
|
||||||
|
jsonnet
|
6
charts/kubezero-argo/hooks.d/pre-install.sh
Executable file
6
charts/kubezero-argo/hooks.d/pre-install.sh
Executable file
@ -0,0 +1,6 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Bootstrap kubezero-git-sync app if it doenst exist
|
||||||
|
kubectl get application kubezero-git-sync -n argocd && rc=$? || rc=$?
|
||||||
|
|
||||||
|
[ $rc != 0 ] && yq -i '.argo-cd.kubezero.bootstrap=true' values.yaml
|
Loading…
x
Reference in New Issue
Block a user