forked from TheRealHaoLiu/hyper-acm-deploy
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathimport-cluster.sh
executable file
·150 lines (109 loc) · 4.22 KB
/
import-cluster.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/bin/bash
source ./helpers.sh
source ./bash-ini-parser
check_dependency
if [ "$#" -lt 1 ]; then
import_cluster_usage
exit 0
fi
while getopts "c:n:m:k:f:" arg; do
case $arg in
c)
CLUSTER_NAME="${OPTARG}"
;;
n)
CLUSTER_NAMESPACE="${OPTARG}"
;;
m)
MANAGED_CLUSTER_NAME="${OPTARG}"
;;
k)
MANAGED_KUBECONFIG="${OPTARG}"
;;
f)
CONFIG="${OPTARG}"
;;
:)
import_cluster_usage
exit 0
;;
*)
import_cluster_usage
exit 0
;;
esac
done
cfg_parser ${CONFIG}
cfg_writer
cfg.section.ACM_COMPONENTS
if [ "${APP}" = "true" ]; then
install_list="APP"
fi
if [ "${POLICY}" = "true" ]; then
install_list="${install_list} POLICY"
fi
if [ "${OBSERVABILITY}" = "true" ]; then
install_list="${install_list} OBSERVABILITY"
fi
comment "info" "The following ACM addon components [ ${install_list} ] will be enabled on the managed cluster ${CLUSTER_NAME}"
comment "info" "1. Validating management cluster status"
oc config view --minify=true --raw=true > hub.kubeconfig
export KUBECONFIG=./hub.kubeconfig
oc cluster-info
if [ $? -ne 0 ]; then
comment "error" "Failed to access the management cluster."
exit 1
fi
HOSTED_CLUSTER="${CLUSTER_NAMESPACE}-${CLUSTER_NAME}"
comment "info" "2. Validating hosted cluster status in the hosted cluster namespace: ${HOSTED_CLUSTER}"
HOSTED_CLUSTER_KUBECONFIG=`oc get hostedcluster -n ${CLUSTER_NAMESPACE} ${CLUSTER_NAME} -o jsonpath={.status.kubeconfig.name}`
oc get secret -n ${CLUSTER_NAMESPACE} ${HOSTED_CLUSTER_KUBECONFIG} -o jsonpath={.data.kubeconfig} | base64 -d > ${HOSTED_CLUSTER_KUBECONFIG}.kubeconfig
export KUBECONFIG=${HOSTED_CLUSTER_KUBECONFIG}.kubeconfig
oc cluster-info
if [ $? -ne 0 ]; then
comment "error" "Failed to access the hosted cluster."
exit 1
fi
comment "info" "3. Validating managed cluster status"
export KUBECONFIG=${MANAGED_KUBECONFIG}
oc cluster-info
if [ $? -ne 0 ]; then
comment "error" "Failed to access the hosted cluster."
exit 1
fi
comment "info" "4. Create the managed cluster on the hosted cluster"
export KUBECONFIG=${HOSTED_CLUSTER_KUBECONFIG}.kubeconfig
sed -e "s,<MANAGED_CLUSTER_NAME>,${MANAGED_CLUSTER_NAME}," foundation/hosted/01-managedcluster.yaml | oc apply -f -
RUN_CMD="oc get secrets -n ${MANAGED_CLUSTER_NAME} ${MANAGED_CLUSTER_NAME}-import"
WAIT_MSG="The managed cluster import secret is not ready"
waitForCMD "\${RUN_CMD}" "\${WAIT_MSG}"
oc get secret -n ${MANAGED_CLUSTER_NAME} ${MANAGED_CLUSTER_NAME}-import -o jsonpath={.data.crds\\\.yaml} | base64 -d > import-crds.yaml
oc get secret -n ${MANAGED_CLUSTER_NAME} ${MANAGED_CLUSTER_NAME}-import -o jsonpath={.data.import\\\.yaml} | base64 -d > import.yaml
comment "info" "5. apply klusterlet manifest to the managed cluster"
export KUBECONFIG=${MANAGED_KUBECONFIG}
oc apply -f import-crds.yaml
oc apply -f import.yaml
comment "info" "6. Wait for open-cluster-management-agent pods to be Ready"
waitForRes "pods" "klusterlet" "open-cluster-management-agent" ""
comment "info" "7. Check the managed cluster status"
export KUBECONFIG=${HOSTED_CLUSTER_KUBECONFIG}.kubeconfig
sleep 5
oc get managedclusters ${MANAGED_CLUSTER_NAME}
if [ "${APP}" = "true" ]; then
comment "info" "8. Enable app addon on the hosted cluster for the managed cluster ${MANAGED_CLUSTER_NAME}"
oc apply -f app/hosted/2-app-addon.yaml -n ${MANAGED_CLUSTER_NAME}
export KUBECONFIG=${MANAGED_KUBECONFIG}
waitForRes "pods" "application-manager" "open-cluster-management-agent-addon" ""
fi
if [ "${POLICY}" = "true" ]; then
comment "info" "9. Enable policy addon on the hosted cluster for the managed cluster ${MANAGED_CLUSTER_NAME}"
export KUBECONFIG=${HOSTED_CLUSTER_KUBECONFIG}.kubeconfig
oc apply -f policy/hosted/policy-framework-addon.yaml -n ${MANAGED_CLUSTER_NAME}
oc apply -f policy/hosted/config-policy-addon.yaml -n ${MANAGED_CLUSTER_NAME}
export KUBECONFIG=${MANAGED_KUBECONFIG}
waitForRes "pods" "config-policy-controller" "open-cluster-management-agent-addon" ""
waitForRes "pods" "governance-policy-framework" "open-cluster-management-agent-addon" ""
fi
comment "info" "check addon status on the managed cluster"
export KUBECONFIG=${MANAGED_KUBECONFIG}
oc get pods -n open-cluster-management-agent-addon