2 # SPDX-License-Identifier: EPL-1.0
3 ##############################################################################
4 # Copyright (c) 2019 The Linux Foundation and others.
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"
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}"
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}"
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 \
47 --volume-driver cinder \
49 boot_volume_type=ssd,boot_volume_size="${boot_volume_size}",\
50 kube_version="${k8s_version}",kube_tag="${k8s_version}" \
52 -f value -c uuid | tail -1)
54 # Create the kubernetes cluster
55 cluster_uuid=$(openstack coe cluster create "$cluster_name" \
56 --os-cloud "$os_cloud" \
57 --master-count "$master_count" \
58 --node-count "$node_count" \
59 --cluster-template "$template_uuid" | awk -F ' ' '{print $5}')
61 # Sleep for a little, because sometimes OpenStack has to catch up with itself
65 [ "$(openstack --os-cloud "$os_cloud" coe cluster show "$cluster_uuid" \
66 -c status -f value)" == "CREATE_IN_PROGRESS" ]; do
67 # echo "sleeping $(date)"
71 if [ "$(openstack --os-cloud "$os_cloud" coe cluster show "$cluster_uuid" \
72 -c status -f value)" == "CREATE_FAILED" ]; then
73 echo "Failed to create cluster: $cluster_uuid $(date)"
74 openstack --os-cloud "$os_cloud" coe cluster delete "$cluster_uuid"
76 openstack --os-cloud "$os_cloud" coe cluster template delete "$template_uuid"
80 if [ "$(openstack --os-cloud "$os_cloud" coe cluster show "$cluster_uuid" \
81 -c status -f value)" == "CREATE_COMPLETE" ]; then
82 echo "Successfully created cluster: $cluster_uuid."