-
Notifications
You must be signed in to change notification settings - Fork 18
/
common_run.sh
executable file
·100 lines (85 loc) · 2.92 KB
/
common_run.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
#!/bin/bash
# Logging format
log() {
echo -e "\033[1m$(date "+%d-%m-%YT%H:%M:%S") ${*}\033[0m"
}
# Check if oc is installed
check_oc() {
log "Checking if OpenShift client is installed"
if ! which oc;
then
log "Looks like OpenShift client is not installed, please install before continuing"
log "Exiting"
exit 1
fi
}
# Check if kubectl is installed
check_kubectl() {
log "Checking if kubernetes client is installed"
if ! which kubectl;
then
log "Looks like Kubernetes client is not installed, please install before continuing"
log "Exiting"
exit 1
fi
}
# Check if cluster exists and print the clusterversion under test
check_cluster_version() {
if ! kubectl version;
then
log "Unable to connect to the cluster, please check if it's up and make sure the KUBECONFIG is set correctly"
exit 1
fi
kubectl get clusterversion || log "Not an OpenShift environment"
}
# sets kubernetes distribution in krkn config if platform is kubernetes included automatically
# on all the builds to keep krkn compatible with both the platform
# called in the checks method below
set_kubernetes_platform() {
if ! kubectl get clusterversion;
then
yq -i '.kraken.distribution="kubernetes"' /home/krkn/kraken/config/config.yaml.template
fi
}
checks() {
check_oc
check_kubectl
check_cluster_version
set_kubernetes_platform
}
# Config substitutions
config_setup(){
envsubst < /home/krkn/kraken/config/kube_burner.yaml.template > /home/krkn/kraken/config/kube_burner.yaml
}
setup_arcaflow_env(){
# will create the arcaflow input.yaml replacing the env variables
# and creating an input_list entry per each node selector passed as
# NODE_SELECTORS env
# check for yq in $PATH
YQ=`which yq`
[ -z $YQ ] && echo "Error: yq not found in PATH" && exit 1
# blank the default input file
echo > $1/input.yaml
IFS=';' read -r -a SELECTORS <<< $NODE_SELECTORS
if [[ "${#SELECTORS[@]}" > 0 ]]
then
for selector in "${SELECTORS[@]}"
do
# if the selector is in the format kubernetes.io/os= will become kubernetes.io/os=''
[[ $selector =~ ^.+\=$ ]] && selector="$selector''"
# if the selector is in the format kubernetes.io/os will become kubernetes.io/os=''
[[ ! $selector =~ ^.+\=.+ ]] && selector="$selector=''"
IFS='=' read -r -a SPLITTED_SELECTOR <<< $selector
export SELECTOR=${SPLITTED_SELECTOR[0]}
export SELECTOR_VALUE=${SPLITTED_SELECTOR[1]}
export TEMPLATE=`envsubst < $1/input.yaml.template`
$YQ e '.input_list += [env(TEMPLATE)]' -i $1/input.yaml
done
else
export SELECTOR="none"
export SELECTOR_VALUE="none"
export TEMPLATE=`envsubst < $1/input.yaml.template`
TEMPLATE=`echo "${TEMPLATE}" | yq e '.node_selector={}'`
$YQ e '.input_list += [env(TEMPLATE)]' -i $1/input.yaml
fi
}