forked from shiftstack/shiftstack-ci
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_ocp.sh
executable file
·152 lines (130 loc) · 5.43 KB
/
run_ocp.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
151
152
#!/usr/bin/env bash
set -e
CONFIG=${CONFIG:-cluster_config.sh}
if [ ! -r "$CONFIG" ]; then
echo "Could not find cluster configuration file."
echo "Make sure $CONFIG file exists in the shiftstack-ci directory and that it is readable"
exit 1
fi
# shellcheck disable=SC1090
source "${CONFIG}"
set -x
declare -r installer="${OPENSHIFT_INSTALLER:-$GOPATH/src/github.com/openshift/installer/bin/openshift-install}"
# check whether we have a free floating IP
FLOATING_IP=$(openstack floating ip list --status DOWN --network "$OPENSTACK_EXTERNAL_NETWORK" --long --format value -c "Floating IP Address" -c Description | grep "${CLUSTER_NAME}-api" | head -n 1 | sed 's/ .*//g' | cut -d ' ' -f1)
# create new floating ip if doesn't exist
if [ -z "$FLOATING_IP" ]; then
FLOATING_IP=$(openstack floating ip create "$OPENSTACK_EXTERNAL_NETWORK" --description "${CLUSTER_NAME}-api" --format value --column floating_ip_address)
fi
hosts="# Generated by shiftstack for $CLUSTER_NAME - Do not edit
$FLOATING_IP api.${CLUSTER_NAME}.${BASE_DOMAIN}
# End of $CLUSTER_NAME nodes"
old_hosts=$(awk "/# Generated by shiftstack for $CLUSTER_NAME - Do not edit/,/# End of $CLUSTER_NAME nodes/" /etc/hosts)
if [ "${hosts}" != "${old_hosts}" ]; then
echo Updating hosts file
sudo sed -i "/# Generated by shiftstack for $CLUSTER_NAME - Do not edit/,/# End of $CLUSTER_NAME nodes/d" /etc/hosts
echo "$hosts" | sudo tee -a /etc/hosts
fi
ssh_config="# Generated by shiftstack for $CLUSTER_NAME - Do not edit
Host openshift-api-$CLUSTER_NAME
Hostname $FLOATING_IP
User core
Port 22
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
# End of $CLUSTER_NAME nodes"
if [ ! -f "$HOME/.ssh/config" ]; then
touch "$HOME/.ssh/config"
chmod 600 "$HOME/.ssh/config"
fi
old_ssh_config=$(awk "/# Generated by shiftstack for $CLUSTER_NAME - Do not edit/,/# End of $CLUSTER_NAME nodes/" "$HOME"/.ssh/config)
if [ "${ssh_config}" != "${old_ssh_config}" ]; then
echo Updating ssh config file
sed -i "/# Generated by shiftstack for $CLUSTER_NAME - Do not edit/,/# End of $CLUSTER_NAME nodes/d" "$HOME"/.ssh/config
echo "$ssh_config" >> "$HOME"/.ssh/config
fi
ARTIFACT_DIR=clusters/${CLUSTER_NAME}
rm -rf "${ARTIFACT_DIR}"
mkdir -p "${ARTIFACT_DIR}"
: "${OPENSTACK_WORKER_FLAVOR:=${OPENSTACK_FLAVOR}}"
MASTER_ROOT_VOLUME=""
if [[ ${OPENSTACK_MASTER_VOLUME_TYPE} != "" ]]; then
MASTER_ROOT_VOLUME="rootVolume:
size: ${OPENSTACK_MASTER_VOLUME_SIZE:-25}
type: ${OPENSTACK_MASTER_VOLUME_TYPE}"
fi
WORKER_ROOT_VOLUME=""
if [[ ${OPENSTACK_WORKER_VOLUME_TYPE} != "" ]]; then
WORKER_ROOT_VOLUME="rootVolume:
size: ${OPENSTACK_WORKER_VOLUME_SIZE:-25}
type: ${OPENSTACK_WORKER_VOLUME_TYPE}"
fi
if [ ! -f "${ARTIFACT_DIR}"/install-config.yaml ]; then
cat > "${ARTIFACT_DIR}"/install-config.yaml << EOF
apiVersion: v1
baseDomain: ${BASE_DOMAIN}
compute:
- name: worker
platform:
openstack:
type: ${OPENSTACK_WORKER_FLAVOR}
${WORKER_ROOT_VOLUME}
replicas: ${WORKER_COUNT}
controlPlane:
name: master
platform:
openstack:
type: ${OPENSTACK_FLAVOR}
${MASTER_ROOT_VOLUME}
replicas: ${MASTER_COUNT}
metadata:
name: ${CLUSTER_NAME}
networking:
clusterNetwork:
- cidr: 10.128.0.0/14
hostPrefix: 23
machineNetwork:
- cidr: 10.0.128.0/17
networkType: ${OPENSHIFT_NETWORKTYPE}
serviceNetwork:
- 172.30.0.0/16
platform:
openstack:
cloud: ${OS_CLOUD}
externalNetwork: ${OPENSTACK_EXTERNAL_NETWORK}
computeFlavor: ${OPENSTACK_FLAVOR}
lbFloatingIP: ${FLOATING_IP}
pullSecret: |
${PULL_SECRET}
sshKey: |
${SSH_PUB_KEY}
EOF
fi
"$installer" --log-level=debug "${1:-create}" "${2:-cluster}" --dir "${ARTIFACT_DIR}"
# Attaching FIP to ingress port to access the cluster from outside
# check whether we have a free floating IP
INGRESS_PORT=$(openstack port list --format value -c Name | awk "/${CLUSTER_NAME}-.{5}-ingress-port/ {print}")
if [ -n "$INGRESS_PORT" ]; then
APPS_FLOATING_IP=$(openstack floating ip list --status DOWN --network "$OPENSTACK_EXTERNAL_NETWORK" --long --format value -c "Floating IP Address" -c Description | grep "${CLUSTER_NAME}-apps" | head -n 1 | sed 's/ .*//g' | cut -d ' ' -f1)
# create new floating ip if doesn't exist
if [ -z "$APPS_FLOATING_IP" ]; then
APPS_FLOATING_IP=$(openstack floating ip create "$OPENSTACK_EXTERNAL_NETWORK" --description "${CLUSTER_NAME}-apps" --format value --column floating_ip_address --port "$INGRESS_PORT")
else
# attach the port
openstack floating ip set --port "$INGRESS_PORT" "$APPS_FLOATING_IP"
fi
hosts="# Generated by shiftstack for $CLUSTER_NAME - Do not edit
$FLOATING_IP api.${CLUSTER_NAME}.${BASE_DOMAIN}
$APPS_FLOATING_IP console-openshift-console.apps.${CLUSTER_NAME}.${BASE_DOMAIN}
$APPS_FLOATING_IP integrated-oauth-server-openshift-authentication.apps.${CLUSTER_NAME}.${BASE_DOMAIN}
$APPS_FLOATING_IP oauth-openshift.apps.${CLUSTER_NAME}.${BASE_DOMAIN}
$APPS_FLOATING_IP prometheus-k8s-openshift-monitoring.apps.${CLUSTER_NAME}.${BASE_DOMAIN}
$APPS_FLOATING_IP grafana-openshift-monitoring.apps.${CLUSTER_NAME}.${BASE_DOMAIN}
# End of $CLUSTER_NAME nodes"
old_hosts=$(awk "/# Generated by shiftstack for $CLUSTER_NAME - Do not edit/,/# End of $CLUSTER_NAME nodes/" /etc/hosts)
if [ "${hosts}" != "${old_hosts}" ]; then
echo Updating hosts file
sudo sed -i "/# Generated by shiftstack for $CLUSTER_NAME - Do not edit/,/# End of $CLUSTER_NAME nodes/d" /etc/hosts
echo "$hosts" | sudo tee -a /etc/hosts
fi
fi