2023-08-16 10:17:39 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#set -eEx
|
|
|
|
#set -o pipefail
|
|
|
|
set -x
|
|
|
|
|
2023-11-20 20:44:37 +00:00
|
|
|
ARTIFACTS=($(echo $1 | tr "," "\n"))
|
2024-07-19 18:32:18 +00:00
|
|
|
ACTION=$2
|
2023-11-20 20:44:37 +00:00
|
|
|
|
2024-05-23 21:17:00 +00:00
|
|
|
LOCAL_DEV=1
|
|
|
|
|
2023-08-16 10:17:39 +00:00
|
|
|
#VERSION="latest"
|
2023-11-20 20:44:37 +00:00
|
|
|
KUBE_VERSION="$(kubectl version -o json | jq -r .serverVersion.gitVersion)"
|
|
|
|
|
2023-08-16 10:17:39 +00:00
|
|
|
WORKDIR=$(mktemp -p /tmp -d kubezero.XXX)
|
2023-11-20 20:44:37 +00:00
|
|
|
[ -z "$DEBUG" ] && trap 'rm -rf $WORKDIR' ERR EXIT
|
2023-08-16 10:17:39 +00:00
|
|
|
|
|
|
|
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
|
|
|
|
# shellcheck disable=SC1091
|
|
|
|
. "$SCRIPT_DIR"/libhelm.sh
|
|
|
|
CHARTS="$(dirname $SCRIPT_DIR)/charts"
|
|
|
|
|
2023-11-20 20:44:37 +00:00
|
|
|
### Various hooks for modules
|
|
|
|
|
|
|
|
################
|
|
|
|
# cert-manager #
|
|
|
|
################
|
|
|
|
function cert-manager-post() {
|
|
|
|
# If any error occurs, wait for initial webhook deployment and try again
|
2024-06-21 17:28:45 +00:00
|
|
|
# see: https://cert-manager.io/docs/concepts/webhook/#webhook-connection-problems-shortly-after-cert-manager-installation
|
2023-11-20 20:44:37 +00:00
|
|
|
|
|
|
|
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"'
|
|
|
|
apply
|
|
|
|
fi
|
|
|
|
|
|
|
|
wait_for "kubectl get ClusterIssuer -n $namespace kubezero-local-ca-issuer"
|
2024-06-21 17:28:45 +00:00
|
|
|
kubectl wait --timeout=180s --for=condition=Ready -n $namespace ClusterIssuer/kubezero-local-ca-issuer
|
2023-11-20 20:44:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
###########
|
|
|
|
# ArgoCD #
|
|
|
|
###########
|
|
|
|
function argocd-pre() {
|
|
|
|
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
|
2023-08-16 10:17:39 +00:00
|
|
|
get_kubezero_values
|
|
|
|
|
|
|
|
# Always use embedded kubezero chart
|
|
|
|
helm template $CHARTS/kubezero -f $WORKDIR/kubezero-values.yaml --kube-version $KUBE_VERSION --version ~$KUBE_VERSION --devel --output-dir $WORKDIR
|
|
|
|
|
2023-11-20 20:44:37 +00:00
|
|
|
# Resolve all the all enabled artifacts
|
|
|
|
if [ ${ARTIFACTS[0]} == "all" ]; then
|
|
|
|
ARTIFACTS=($(ls $WORKDIR/kubezero/templates | sed -e 's/.yaml//g'))
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Delete in reverse order, continue even if errors
|
2024-07-19 18:32:18 +00:00
|
|
|
if [ $ACTION == "delete" ]; then
|
2023-11-20 20:44:37 +00:00
|
|
|
set +e
|
|
|
|
for (( idx=${#ARTIFACTS[@]}-1 ; idx>=0 ; idx-- )) ; do
|
|
|
|
_helm delete ${ARTIFACTS[idx]} || true
|
|
|
|
done
|
2024-07-19 18:32:18 +00:00
|
|
|
else
|
|
|
|
if [ "$ACTION" == "" -o "$ACTION" == "crds" ]; then
|
|
|
|
for t in ${ARTIFACTS[@]}; do
|
|
|
|
_helm crds $t || true
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
for t in ${ARTIFACTS[@]}; do
|
|
|
|
_helm apply $t || true
|
|
|
|
done
|
2023-11-20 20:44:37 +00:00
|
|
|
fi
|