-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbas-script-functions.bash
179 lines (151 loc) · 5.15 KB
/
bas-script-functions.bash
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#!/bin/bash
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;36m'
NC='\033[0m'
function echoGreen() {
echo -e "${GREEN}$1${NC}"
}
function echoRed() {
echo -e "${RED}$1${NC}"
}
function echoBlue() {
echo -e "${BLUE}$1${NC}"
}
function echoYellow() {
echo -e "${YELLOW}$1${NC}"
}
function displayStepHeader() {
stepHeader=$(stepLog "$1" "$2")
echoBlue "$stepHeader"
}
function stepLog() {
echo -e "STEP $1/12: $2"
}
function validatePropertiesfile(){
file="./cr.properties"
if [ -f "$file" ]
then
echo "$file found."
while IFS='=' read -r key value
do
key_name=$(echo $key | grep -v '^#')
if [[ -z "$key_name" || "$key_name" == " " || $key_name == " " ]];then
continue
fi
if [[ -z "${!key_name}" || "${!key_name}" == "" || ${!key_name} == "" ]]; then
echoRed "$key_name is empty"
exit 1
fi
done < "$file"
else
echoRed "$file not found."
exit 1
fi
}
function checkPropertyValuesprompt(){
echoBlue "Please check below Properties values and confirm to Continue with installation"
file="./cr.properties"
while IFS= read -r line
do
key_name=$(echo $line | grep -v '^#')
if [[ -z "$key_name" || "$key_name" == " " || $key_name == " " ]];then
continue
fi
echo "$line"
done < "$file"
echoBlue "Are you sure, you want to Continue with Installation? [Y/n]: "
read -r continueInstall </dev/tty
if [[ ! $continueInstall || $continueInstall = *[^Yy] ]]; then
echoRed "Aborting installation of Behavior Analytics Services Operator"
exit 0
fi
}
function checkOCServerVersion() {
currentOCServerVersion="$(oc version -o json | jq .serverVersion.gitVersion)"
echo $currentOCServerVersion
echo $requiredServerVersion
if ! [[ $currentOCServerVersion =~ $requiredServerVersion ]]; then
if [ "$currentOCServerVersion" = null ]; then
echoRed "Unsupported OpenShift Server version detected. Supported OpenShift Server versions are 1.16 and above."
else
echoRed "Unsupported OpenShift Server version $currentOCServerVersion detected. Supported OpenShift versions are 1.16 and above."
fi
exit 1
fi
}
function checkOCClientVersion() {
currentClientVersion="$(oc version -o json | jq .clientVersion.gitVersion)"
if ! [[ $currentClientVersion =~ $requiredVersion ]]; then
echoRed "Unsupported oc cli version $currentClientVersion detected. Supported oc cli versions are 4.3 and above."
exit 1
fi
}
function checkOpenshiftVersion() {
currentOpenshiftVersion="$(oc version -o json | jq .openshiftVersion)"
echo OCP version is "$currentOpenshiftVersion"
if [[ $currentOpenshiftVersion =~ $ocpVersion ]]; then
echo "install BAS 1.1.1"
basVersion=v1.1.0
elif [[ $currentOpenshiftVersion =~ $ocpVersion45 ]]; then
echo "install BAS 1.0.0"
basVersion=v1.0.0
else
echo "Unsupportedd Openshift version $currentOpenshiftVersion.Supported OpenShift versions are 4.5 to 4.7."
exit 1
fi
}
function createProject(){
existingns=$(oc get projects | grep -w "${projectName}" | awk '{print $1}')
if [ "${existingns}" == "${projectName}" ]; then
echoYellow "Project ${existingns} already exists, do you want to continue BAS operator installation in the existing project? [Y/n]: "
read -r continueInstall </dev/tty
if [[ ! $continueInstall || $continueInstall = *[^Yy] ]]; then
echoRed "Aborting installation of BAS Operator, please set new value for the Project in the cr.properties file."
exit 0;
fi
else
oc new-project "${projectName}" 2>&1 >> "${logFile}"
if [ $? -ne 0 ];then
echoRed "FAILED: Project:${projectName} creation failed"
exit 1
fi
fi
}
function checkClusterServiceVersionSucceeded() {
retryCount=20
retries=0
check_for_csv_success=$(oc get csv -n "$projectName" --ignore-not-found | awk '$1 ~ /behavior-analytics-services-operator/ { print }' | awk -F' ' '{print $NF}')
until [[ $retries -eq $retryCount || $check_for_csv_success = "Succeeded" ]]; do
sleep 5
check_for_csv_success=$(oc get csv -n "$projectName" --ignore-not-found | awk '$1 ~ /behavior-analytics-services-operator/ { print }' | awk -F' ' '{print $NF}')
retries=$((retries + 1))
done
echo "$check_for_csv_success"
}
function checkDeploymentStatus() {
retryCount=90
retries=0
check_for_deployment_status=$(oc get csv -n "$projectName" --ignore-not-found | awk '$1 ~ /behavior-analytics-services-operator/ { print }' | awk -F' ' '{print $NF}')
until [[ $retries -eq $retryCount || $check_for_deployment_status = "Ready" ]]; do
sleep 30
check_for_deployment_status=$(oc get AnalyticsProxy analyticsproxydeployment --output="jsonpath={.status.phase}")
retries=$((retries + 1))
done
echo "$check_for_deployment_status"
}
function getGenerateAPIKey() {
retryCount=10
retries=0
check_for_key=$(oc get secret bas-api-key --ignore-not-found)
until [[ $retries -eq $retryCount || $check_for_key != "" ]]; do
sleep 5
check_for_key=$(oc get secret bas-api-key --ignore-not-found)
retries=$((retries + 1))
done
if [[ $check_for_key != "" ]]; then
check_for_key=$(oc get secret bas-api-key --output="jsonpath={.data.apikey}" | base64 -d)
fi
echo "$check_for_key"
}