feat: new custom helm hooks

This commit is contained in:
Stefan Reimer 2025-03-18 14:47:55 +00:00
parent 30bc95408a
commit af29836a27
5 changed files with 62 additions and 49 deletions

View File

@ -5,7 +5,7 @@ set -x
ARTIFACTS=($(echo $1 | tr "," "\n"))
ACTION="${2:-apply}"
ARGOCD="${3:-false}"
ARGOCD="${3:-true}"
LOCAL_DEV=1
@ -36,46 +36,6 @@ parse_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
get_kubezero_values $ARGOCD

View File

@ -139,7 +139,7 @@ function delete_ns() {
# 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 '
#!/usr/bin/python3
import yaml
@ -201,9 +201,18 @@ function _helm() {
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
# Allow custom CRD handling
declare -F ${module}-crds && ${module}-crds || _crds
# Pre-crd hook
[ -x $WORKDIR/$chart/hooks.d/pre-crds.sh ] && (cd $WORKDIR; ./$chart/hooks.d/pre-crds.sh)
crds
elif [ $action == "apply" -o $action == "replace" ]; then
echo "using values to $action of module $module: "
@ -213,7 +222,7 @@ function _helm() {
create_ns $namespace
# 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
[ $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=$?
# 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
render

View File

@ -8,10 +8,18 @@ import yaml
def migrate(values):
"""Actual changes here"""
# remove syncOptions from root app
# migrate kubezero root app of apps to Argo chart
try:
if values["kubezero"]["syncPolicy"]:
values["kubezero"].pop("syncPolicy")
if values["kubezero"]:
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:
pass

View 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

View 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