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
|
2024-10-22 12:54:19 +00:00
|
|
|
ARGOCD="False"
|
2024-05-23 21:17:00 +00:00
|
|
|
|
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"
|
|
|
|
|
2024-08-09 10:45:27 +00:00
|
|
|
# Guess platform from current context
|
|
|
|
_auth_cmd=$(kubectl config view | yq .users[0].user.exec.command)
|
|
|
|
if [ "$_auth_cmd" == "gke-gcloud-auth-plugin" ]; then
|
|
|
|
PLATFORM=gke
|
|
|
|
elif [ "$_auth_cmd" == "aws-iam-authenticator" ]; then
|
|
|
|
PLATFORM=aws
|
|
|
|
else
|
|
|
|
PLATFORM=nocloud
|
|
|
|
fi
|
|
|
|
|
|
|
|
parse_version() {
|
|
|
|
echo $([[ $1 =~ ^v[0-9]+\.[0-9]+\.[0-9]+ ]] && echo "${BASH_REMATCH[0]//v/}")
|
|
|
|
}
|
|
|
|
|
|
|
|
KUBE_VERSION=$(parse_version $KUBE_VERSION)
|
|
|
|
|
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() {
|
2024-10-28 14:21:11 +00:00
|
|
|
kubectl delete job argo-argocd-redis-secret-init -n argocd || true
|
|
|
|
|
2023-11-20 20:44:37 +00:00
|
|
|
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
|
2024-10-22 12:54:19 +00:00
|
|
|
get_kubezero_values $ARGOCD
|
2023-08-16 10:17:39 +00:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
2024-11-04 13:41:40 +00:00
|
|
|
# Root KubeZero apply directly and exit
|
|
|
|
if [ ${ARTIFACTS[0]} == "kubezero" ]; then
|
|
|
|
kubectl apply -f $WORKDIR/kubezero/templates
|
|
|
|
exit $?
|
|
|
|
|
|
|
|
# "catch all" apply all enabled modules
|
|
|
|
elif [ ${ARTIFACTS[0]} == "all" ]; then
|
2023-11-20 20:44:37 +00:00
|
|
|
ARTIFACTS=($(ls $WORKDIR/kubezero/templates | sed -e 's/.yaml//g'))
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Delete in reverse order, continue even if errors
|
2024-08-09 10:45:27 +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
|