KubeZero - ZeroDownTime Kubernetes Platform
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

96 lines
4.3 KiB

  1. #!/bin/bash
  2. set -e
  3. DEPLOY_DIR=$( dirname $( realpath $0 ))
  4. which yq || { echo "yq not found!"; exit 1; }
  5. # Waits for max 300s and retries
  6. function wait_for() {
  7. local TRIES=0
  8. while true; do
  9. $@ && break
  10. [ $TRIES -eq 200 ] && return 1
  11. let TRIES=$TRIES+1
  12. sleep 3
  13. done
  14. }
  15. helm repo add kubezero https://zero-down-time.github.io/kubezero
  16. helm repo update
  17. # Determine if we bootstrap or update
  18. helm list -n argocd -f kubezero -q | grep -q kubezero && rc=$? || rc=$?
  19. if [ $rc -eq 0 ]; then
  20. helm template $DEPLOY_DIR -f values.yaml -f cloudbender.yaml > generated-values.yaml
  21. helm upgrade -n argocd kubezero kubezero/kubezero-argo-cd -f generated-values.yaml
  22. else
  23. # During bootstrap we first generate a minimal values.yaml to prevent various deadlocks
  24. # Generate ArgoCD password if not in values.yaml yet and add it
  25. grep -q argocdServerAdminPassword values.yaml && rc=$? || rc=$?
  26. if [ $rc -ne 0 ]; then
  27. _argo_date="$(date -u --iso-8601=seconds)"
  28. _argo_passwd="$($DEPLOY_DIR/argocd_password.py)"
  29. cat <<EOF > _argocd_values.yaml
  30. argo-cd:
  31. configs:
  32. secret:
  33. # ArgoCD password: ${_argo_passwd%%:*} Please move to secure location !
  34. argocdServerAdminPassword: "${_argo_passwd##*:}"
  35. argocdServerAdminPasswordMtime: "$_argo_date"
  36. EOF
  37. yq merge -i --overwrite values.yaml _argocd_values.yaml && rm -f _argocd_values.yaml
  38. fi
  39. # Deploy initial argocd
  40. helm template $DEPLOY_DIR -f values.yaml -f cloudbender.yaml -f $DEPLOY_DIR/values-step-1.yaml > generated-values.yaml
  41. helm install -n argocd kubezero kubezero/kubezero-argo-cd --create-namespace -f generated-values.yaml
  42. # Wait for argocd-server to be running
  43. kubectl rollout status deployment -n argocd kubezero-argocd-server
  44. # Now wait for cert-manager and the local CA to be bootstrapped
  45. echo "Waiting for cert-manager to be deployed..."
  46. wait_for kubectl get deployment -n cert-manager cert-manager-webhook 2>/dev/null 1>&2
  47. kubectl rollout status deployment -n cert-manager cert-manager-webhook
  48. # Either inject cert-manager backup or bootstrap
  49. if [ -f cert-manager-backup.yaml ]; then
  50. kubectl apply -f cert-manager-backup.yaml
  51. else
  52. helm template $DEPLOY_DIR -f values.yaml -f cloudbender.yaml -f $DEPLOY_DIR/values-step-2.yaml > generated-values.yaml
  53. helm upgrade -n argocd kubezero kubezero/kubezero-argo-cd -f generated-values.yaml
  54. wait_for kubectl get Issuer -n kube-system kubezero-local-ca-issuer 2>/dev/null 1>&2
  55. kubectl wait --for=condition=Ready -n kube-system Issuer/kubezero-local-ca-issuer
  56. fi
  57. # Make sure kube-system is allowed to kiam
  58. kubectl annotate --overwrite namespace kube-system 'iam.amazonaws.com/permitted=.*'
  59. # Now that we have the cert-manager webhook, get the kiam certs in place but do NOT deploy kiam yet
  60. helm template $DEPLOY_DIR -f values.yaml -f cloudbender.yaml -f $DEPLOY_DIR/values-step-3.yaml > generated-values.yaml
  61. helm upgrade -n argocd kubezero kubezero/kubezero-argo-cd -f generated-values.yaml
  62. kubectl wait --for=condition=Ready -n kube-system certificates/kiam-server
  63. # Now lets make sure kiam is working
  64. helm template $DEPLOY_DIR -f values.yaml -f cloudbender.yaml -f $DEPLOY_DIR/values-step-4.yaml > generated-values.yaml
  65. helm upgrade -n argocd kubezero kubezero/kubezero-argo-cd -f generated-values.yaml
  66. wait_for kubectl get daemonset -n kube-system kiam-agent 2>/dev/null 1>&2
  67. kubectl rollout status daemonset -n kube-system kiam-agent
  68. # Install Istio if enabled, but keep ArgoCD istio support disabled for now in case
  69. helm template $DEPLOY_DIR -f values.yaml -f cloudbender.yaml -f $DEPLOY_DIR/values-step-5.yaml > generated-values.yaml
  70. helm upgrade -n argocd kubezero kubezero/kubezero-argo-cd -f generated-values.yaml
  71. wait_for kubectl get deployment -n istio-operator istio-operator 2>/dev/null 1>&2
  72. kubectl rollout status deployment -n istio-operator istio-operator
  73. # Metrics
  74. helm template $DEPLOY_DIR -f values.yaml -f cloudbender.yaml -f $DEPLOY_DIR/values-step-6.yaml > generated-values.yaml
  75. helm upgrade -n argocd kubezero kubezero/kubezero-argo-cd -f generated-values.yaml
  76. wait_for kubectl get crds servicemonitors.monitoring.coreos.com 2>/dev/null 1>&2
  77. # Finally we could enable the actual config and deploy all
  78. helm template $DEPLOY_DIR -f values.yaml -f cloudbender.yaml > generated-values.yaml
  79. helm upgrade -n argocd kubezero kubezero/kubezero-argo-cd -f generated-values.yaml
  80. fi