Fix: bashate E010 warnings
[releng/global-jjb.git] / shell / openstack-kubernetes-create.sh
1 #!/bin/bash -l
2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2019 The Linux Foundation and others.
5 #
6 # All rights reserved. This program and the accompanying materials
7 # are made available under the terms of the Eclipse Public License v1.0
8 # which accompanies this distribution, and is available at
9 # http://www.eclipse.org/legal/epl-v10.html
10 ##############################################################################
11 # shellcheck disable=SC2153,SC2034
12 echo "---> Creating kubernetes cluster"
13
14 set -eux -o pipefail
15
16 os_cloud="${OS_CLOUD:-vex}"
17 fixed_network="${FIXED_NETWORK}"
18 fixed_subnet="${FIXED_SUBNET}"
19 cluster_template_name="${CLUSTER_TEMPLATE_NAME}"
20 cluster_name="${CLUSTER_NAME}"
21 base_image="${BASE_IMAGE}"
22 keypair="${KEYPAIR}"
23 master_flavor="${MASTER_FLAVOR}"
24 node_flavor="${NODE_FLAVOR}"
25 master_count="${MASTER_COUNT:-1}"
26 node_count="${NODE_COUNT:-2}"
27 boot_volume_size="${BOOT_VOLUME_SIZE}"
28 docker_volume_size="${DOCKER_VOLUME_SIZE}"
29 k8s_version="${KUBERNETES_VERSION}"
30 cluster_settle_time="${CLUSTER_SETTLE_TIME:-1m}"
31
32
33 # Create the template for the cluster first. Returns the cluster ID as $template_uuid
34 template_uuid=$(openstack coe cluster template create "$cluster_template_name" \
35   --os-cloud "$os_cloud" \
36   --image "$base_image" \
37   --keypair "$keypair" \
38   --external-network public \
39   --fixed-network "$fixed_network" \
40   --fixed-subnet "$fixed_subnet" \
41   --floating-ip-disabled \
42   --master-flavor "$master_flavor" \
43   --flavor "$node_flavor" \
44   --docker-volume-size "$docker_volume_size" \
45   --network-driver flannel \
46   --master-lb-enabled \
47   --volume-driver cinder \
48   --labels boot_volume_type=ssd,boot_volume_size="${boot_volume_size}",kube_version="${k8s_version}",kube_tag="${k8s_version}" \
49   --coe kubernetes \
50   -f value -c uuid | tail -1)
51
52 # Create the kubernetes cluster
53 cluster_uuid=$(openstack coe cluster create "$cluster_name" \
54   --os-cloud "$os_cloud" \
55   --master-count "$master_count" \
56   --node-count "$node_count" \
57   --cluster-template "$template_uuid" | awk -F ' ' '{print $5}')
58
59 # Sleep for a little, because sometimes OpenStack has to catch up with itself
60 sleep 15
61
62 while [ "$(openstack --os-cloud "$os_cloud" coe cluster show "$cluster_uuid" -c status -f value)" == "CREATE_IN_PROGRESS" ]; do
63   # echo "sleeping $(date)"
64   sleep 2m
65 done
66
67 if [ "$(openstack --os-cloud "$os_cloud" coe cluster show "$cluster_uuid" -c status -f value)" == "CREATE_FAILED" ]
68 then
69   echo "Failed to create cluster: $cluster_uuid $(date)"
70   openstack --os-cloud "$os_cloud" coe cluster delete "$cluster_uuid"
71   sleep 5m
72   openstack --os-cloud "$os_cloud" coe cluster template delete "$template_uuid"
73   exit 1
74 fi
75
76 if [ "$(openstack --os-cloud "$os_cloud" coe cluster show "$cluster_uuid" -c status -f value)" == "CREATE_COMPLETE" ]
77 then
78   echo "Successfully created cluster: $cluster_uuid."
79 fi