Skip to content

Commit

Permalink
do all customizations at the end so we just need one sync/health loop
Browse files Browse the repository at this point in the history
  • Loading branch information
jkleinlercher authored May 7, 2024
1 parent 86f4f29 commit e3f0fb6
Showing 1 changed file with 14 additions and 64 deletions.
78 changes: 14 additions & 64 deletions install-platform.sh
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,15 @@ else
kubectl apply -f https://raw.githubusercontent.com/suxess-it/sx-cnp-oss/main/bootstrap-app-k3d.yaml -n argocd
fi

# max wait for 5 minutes
end=$((SECONDS+300))
argocd_apps="argocd sx-kube-prometheus-stack"
# wait for all apps to be synced and health
if [ "${TARGET_TYPE}" == "METALSTACK" ] ; then
argocd_apps="argocd sx-kubecost sx-crossplane sx-bootstrap-app sx-kargo approved-application-team-app sx-cert-manager sx-argo-rollouts sx-kyverno sx-kube-prometheus-stack"
else
argocd_apps="argocd sx-loki sx-kubecost sx-keycloak sx-promtail sx-tempo sx-crossplane sx-bootstrap-app sx-kargo approved-application-team-app sx-cert-manager sx-argo-rollouts sx-external-secrets sx-kyverno sx-kube-prometheus-stack"
fi

# max wait for 15 minutes
end=$((SECONDS+900))

all_apps_synced="true"
while [ $SECONDS -lt $end ]; do
Expand All @@ -80,9 +86,11 @@ while [ $SECONDS -lt $end ]; do
kubectl get application -n argocd
sleep 10
done

echo "status of all pods"
kubectl get pods -A
if [ ${all_apps_synced} != "true" ] ; then
echo "not all apps synced and healthy after limit reached :("
kubectl get pods -A
exit 1
else
echo "all apps are synced. ready for take off :)"
Expand All @@ -109,66 +117,8 @@ export ARGOCD_AUTH_TOKEN="argocd.token=$( ./argocd account generate-token --acco
ID=$( curl -k -X POST https://grafana-127-0-0-1.nip.io/api/serviceaccounts --user 'admin:prom-operator' -H "Content-Type: application/json" -d '{"name": "backstage","role": "Viewer","isDisabled": false}' | jq -r .id )
export GRAFANA_TOKEN=$(curl -k -X POST https://grafana-127-0-0-1.nip.io/api/serviceaccounts/${ID}/tokens --user 'admin:prom-operator' -H "Content-Type: application/json" -d '{"name": "backstage"}' | jq -r .key)

# max wait for 3 minutes
end=$((SECONDS+180))
argocd_apps="sx-backstage"

all_apps_synced="true"
while [ $SECONDS -lt $end ]; do
all_apps_synced="true"
for app in ${argocd_apps} ; do
kubectl get application -n argocd ${app} | grep "Synced"
exit_code=$?
if [[ $exit_code -ne 0 ]]; then
all_apps_synced="false"
fi
done
if [ ${all_apps_synced} = "true" ] ; then
echo "${argocd_apps} apps are synced"
break
fi
kubectl get application -n argocd
sleep 10
done
if [ ${all_apps_synced} != "true" ] ; then
echo "not all apps synced and healthy after limit reached :("
kubectl get pods -A
exit 1
else
echo "all apps are synced. ready for take off :)"
fi

export K8S_SA_TOKEN=$( kubectl get secret backstage-locator -n backstage -o jsonpath='{.data.token}' | base64 -d )

# create manual-secret secret with all tokens for backstage
kubectl create secret generic -n backstage manual-secret --from-literal=GITHUB_CLIENTSECRET=${GITHUB_CLIENTSECRET} --from-literal=GITHUB_CLIENTID=${GITHUB_CLIENTID} --from-literal=GITHUB_ORG=${GITHUB_ORG} --from-literal=GITHUB_TOKEN=${GITHUB_TOKEN} --from-literal=K8S_SA_TOKEN=${K8S_SA_TOKEN} --from-literal=ARGOCD_AUTH_TOKEN=${ARGOCD_AUTH_TOKEN} --from-literal=GRAFANA_TOKEN=${GRAFANA_TOKEN}
kubectl rollout restart deploy/sx-backstage -n backstage

# max wait for 15 minutes
end=$((SECONDS+900))
argocd_apps="argocd sx-backstage sx-loki sx-kubecost sx-keycloak sx-promtail sx-tempo sx-crossplane sx-bootstrap-app sx-kargo approved-application-team-app sx-cert-manager sx-argo-rollouts sx-external-secrets sx-kyverno sx-kube-prometheus-stack"

all_apps_synced="true"
while [ $SECONDS -lt $end ]; do
all_apps_synced="true"
for app in ${argocd_apps} ; do
kubectl get application -n argocd ${app} | grep "Synced.*Healthy"
exit_code=$?
if [[ $exit_code -ne 0 ]]; then
all_apps_synced="false"
fi
done
if [ ${all_apps_synced} = "true" ] ; then
echo "${argocd_apps} apps are synced"
break
fi
kubectl get application -n argocd
sleep 10
done

echo "status of all pods"
kubectl get pods -A
if [ ${all_apps_synced} != "true" ] ; then
echo "not all apps synced and healthy after limit reached :("
exit 1
else
echo "all apps are synced. ready for take off :)"
fi

0 comments on commit e3f0fb6

Please sign in to comment.