-
Notifications
You must be signed in to change notification settings - Fork 3
/
06_make_tks-admin_self-managing.sh
executable file
·70 lines (60 loc) · 2.23 KB
/
06_make_tks-admin_self-managing.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/bash
set -e
source lib/common.sh
case $TKS_ADMIN_CLUSTER_INFRA_PROVIDER in
"aws")
if [ -z "$1" ] || [ -z "$2" ]
then
echo "usage: $0 <ssh_key.pem> <values.yaml for admin cluster>"
exit 1
fi
SSH_KEY=$1
HELM_VALUE_FILE=$2
;;
"byoh")
;;
esac
export KUBECONFIG=~/.kube/config
case $TKS_ADMIN_CLUSTER_INFRA_PROVIDER in
"aws")
log_info "Copying all local resources to the bastion host"
if grep -Fq "eksEnabled: true" $HELM_VALUE_FILE;then
BASTION_HOST_IP=$(kubectl get awsmanagedcontrolplanes $CLUSTER_NAME -o jsonpath='{.status.bastion.addresses[?(@.type == "ExternalIP")].address}')
else
BASTION_HOST_IP=$(kubectl get awscluster $CLUSTER_NAME -o jsonpath='{.status.bastion.addresses[?(@.type == "ExternalIP")].address}')
fi
ssh -i $SSH_KEY -o StrictHostKeyChecking=no ubuntu@$BASTION_HOST_IP sudo rm -rf "${PWD##*/}"
scp -r -q -i $SSH_KEY -o StrictHostKeyChecking=no $PWD ubuntu@$BASTION_HOST_IP:
;;
"byoh")
;;
esac
export KUBECONFIG=~/.kube/config
log_info "Pre-check before pivot"
clusterctl move --to-kubeconfig output/kubeconfig_$CLUSTER_NAME --dry-run -v10
case $TKS_ADMIN_CLUSTER_INFRA_PROVIDER in
"aws")
grep -Fq "eksEnabled: true" $HELM_VALUE_FILE
eks_enabled=$?
if test $eks_enabled -neq 0; then
# Fix for 'MP_NAME is invalid: spec.awsLaunchTemplate.rootVolume.deviceName: Forbidden: root volume shouldn't have device name'
for awsmp_name in $(kubectl get mp -ojsonpath={.items[*].metadata.name}); do
kubectl patch awsmp $awsmp_name --type json -p='[{"op": "remove", "path": "/spec/awsLaunchTemplate/rootVolume/deviceName"}]'
done
fi
;;
"byoh")
;;
esac
gum confirm "Are you sure you want to move the Cluster API objects to the admin cluster?" || exit 1
log_info "Pivoting to make TKS admin cluster self-managing"
clusterctl move --to-kubeconfig output/kubeconfig_$CLUSTER_NAME
case $TKS_ADMIN_CLUSTER_INFRA_PROVIDER in
"aws")
log_info "Finished. Check the status of all cluster API resources in the admin cluster and use the bastion host: $BASTION_HOST_IP"
;;
"byoh")
log_info "Finished. Check the status of all cluster API resources in the admin cluster"
#kubectl patch cluster tks-admin --type='json' -p='[{ "op": "add", "path": "/spec/paused", "value": true }]'
;;
esac