#!/bin/sh

echo "reset ekman cluster admin token... "
kubectl --context ekman delete -f cluster-admin-token.yaml
sleep 1
kubectl --context ekman apply -f cluster-admin-token.yaml

# secret=$(kubectl --context ekman get secret -n kube-system | grep cluster-admin-token | cut -d' ' -f1)
# token=$(kubectl --context ekman get secret -n kube-system $secret -o yaml | grep ' token:' | cut -d' ' -f4 | base64 -d)
# sed "s/@token@/$token/" cluster-ekman.yaml > _cluster-ekman.yaml
# echo "configure argocd ekman-cluster..."
# cat _cluster-ekman.yaml
# kubectl --context oceanbox apply -f _cluster-ekman.yaml

token=$(kubectl --context ekman get secret -n kube-system argocd-manager-token -o yaml | grep ' token:' | cut -d' ' -f4 | base64 -d)
sed "s/@token@/${token}/" cluster-ekman.yaml > _cluster-ekman.yaml
echo "configure argocd ekman-cluster..."
cat _cluster-ekman.yaml
kubectl --context oceanbox apply -f _cluster-ekman.yaml
echo "done."

