forked from Call-for-Code-for-Racial-Justice/Legit-Info
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathicc
executable file
·50 lines (50 loc) · 1.72 KB
/
icc
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
#!/bin/bash
CLUSTER_ID="$1"
if [[ -z "${CLUSTER_ID}" ]]; then
echo "Listing Cluster IDs"
echo "$(yq r ~/.ibmcloud.yaml clusters)"
exit
fi
if [[ ! -f ~/.ibmcloud.yaml ]]; then
echo "Provide configuration in ~/.ibmcloud.yaml"
exit 1
fi
RESOURCE_GROUP="$(yq r ~/.ibmcloud.yaml clusters.${CLUSTER_ID}.resourceGroup)"
if [[ -z "${RESOURCE_GROUP}" ]]; then
echo "Resource group not found in config"
exit 1
fi
CLUSTER_NAME="$(yq r ~/.ibmcloud.yaml clusters.${CLUSTER_ID}.cluster)"
if [[ -z "${CLUSTER_NAME}" ]]; then
CLUSTER_NAME="${RESOURCE_GROUP}-cluster"
fi
REGION="$(yq r ~/.ibmcloud.yaml clusters.${CLUSTER_ID}.region)"
if [[ -z "${REGION}" ]]; then
REGION="us-east"
fi
ACCOUNT_NAME="$(yq r ~/.ibmcloud.yaml clusters.${CLUSTER_ID}.account)"
APIKEY="$(yq r ~/.ibmcloud.yaml accounts.${ACCOUNT_NAME})"
if [[ -z "${APIKEY}" ]]; then
echo "APIKEY not found in config"
exit 1
fi
if [[ -z "${TMP_DIR}" ]]; then
TMP_DIR="./.tmp"
fi
mkdir -p "${TMP_DIR}"
ibmcloud config --check-version=false 1> /dev/null 2> /dev/null
echo "Logging into ibmcloud: ${REGION}/${RESOURCE_GROUP}"
ibmcloud login \
--apikey ${APIKEY} \
-g ${RESOURCE_GROUP} \
-r ${REGION} 1> /dev/null 2> /dev/null
OPENSHIFT=$(ibmcloud ks cluster get --cluster ${CLUSTER_NAME} | grep Version | grep openshift)
if [[ -z "${OPENSHIFT}" ]]; then
echo "Logging into IKS cluster: ${CLUSTER_NAME}"
export IKS_BETA_VERSION=1
ibmcloud ks cluster config --cluster ${CLUSTER_NAME}
else
SERVER_URL=$(ibmcloud ks cluster get --cluster ${CLUSTER_NAME} | grep "Public Service Endpoint URL" | sed -E "s/.*(http.*)/\1/g" | xargs -I{} echo -n {})
echo "Logging into OpenShift cluster: ${CLUSTER_NAME}"
oc login -u apikey -p ${APIKEY} --server=${SERVER_URL} 1> /dev/null 2> /dev/null
fi