Skip to content

Commit 95c5928

Browse files
scruplelesswizardpierreprinetti
authored andcommitted
Explicitly require OS_CLOUD to be set (openshift#141)
1 parent 4c6ec84 commit 95c5928

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

cmd/clusterctl/examples/openstack/generate-yaml.sh

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
set -e
33

4-
# Function that prints out the help message, describing the script
4+
# Function that prints out the help message, describing the script
55
print_help()
66
{
77
echo "$SCRIPT - generates input yaml files for Cluster API on openstack"
@@ -85,6 +85,11 @@ if test -z "$SUPPORTED_PROVIDER_OS"; then
8585
exit 1
8686
fi
8787

88+
if [ -z "$OS_CLOUD" ]; then
89+
echo "OS_CLOUD environment variable is not set. Please set OS_CLOUD before running this script."
90+
exit 1
91+
fi
92+
8893
if ! hash yq 2>/dev/null; then
8994
echo "'yq' is not available, please install it. (https://github.com/mikefarah/yq)"
9095
print_help
@@ -125,7 +130,7 @@ MACHINE_CONTROLLER_SSH_HOME=${HOME}/.ssh/
125130

126131
OVERWRITE=${OVERWRITE:-0}
127132
CLOUDS_PATH=${CLOUDS_PATH:-""}
128-
CLOUD="${OS_CLOUD}"
133+
129134

130135
if [ $OVERWRITE -ne 1 ] && [ -f "$MACHINE_GENERATED_FILE" ]; then
131136
echo "File $MACHINE_GENERATED_FILE already exists. Delete it manually before running this script."
@@ -142,14 +147,10 @@ if [ $OVERWRITE -ne 1 ] && [ -f "$PROVIDERCOMPONENT_GENERATED_FILE" ]; then
142147
exit 1
143148
fi
144149

145-
if [ -z "$CLOUD" ]; then
146-
CLOUD=openstack
147-
fi
148-
149150
mkdir -p "${OUTPUT_DIR}"
150151

151152
if [ -n "$CLOUDS_PATH" ]; then
152-
# Read clouds.yaml from file if a path is provided
153+
# Read clouds.yaml from file if a path is provided
153154
OPENSTACK_CLOUD_CONFIG_PLAIN=$(cat "$CLOUDS_PATH")
154155
else
155156
# Collect user input to generate a clouds.yaml file
@@ -173,12 +174,12 @@ else
173174
fi
174175

175176
# Just blindly parse the cloud.conf here, overwriting old vars.
176-
AUTH_URL=$(echo "$OPENSTACK_CLOUD_CONFIG_PLAIN" | yq r - clouds.$CLOUD.auth.auth_url)
177-
USERNAME=$(echo "$OPENSTACK_CLOUD_CONFIG_PLAIN" | yq r - clouds.$CLOUD.auth.username)
178-
PASSWORD=$(echo "$OPENSTACK_CLOUD_CONFIG_PLAIN" | yq r - clouds.$CLOUD.auth.password)
179-
REGION=$(echo "$OPENSTACK_CLOUD_CONFIG_PLAIN" | yq r - clouds.$CLOUD.region_name)
180-
PROJECT_ID=$(echo "$OPENSTACK_CLOUD_CONFIG_PLAIN" | yq r - clouds.$CLOUD.auth.project_id)
181-
DOMAIN_NAME=$(echo "$OPENSTACK_CLOUD_CONFIG_PLAIN" | yq r - clouds.$CLOUD.auth.user_domain_name)
177+
AUTH_URL=$(echo "$OPENSTACK_CLOUD_CONFIG_PLAIN" | yq -r .clouds.$OS_CLOUD.auth.auth_url)
178+
USERNAME=$(echo "$OPENSTACK_CLOUD_CONFIG_PLAIN" | yq -r .clouds.$OS_CLOUD.auth.username)
179+
PASSWORD=$(echo "$OPENSTACK_CLOUD_CONFIG_PLAIN" | yq -r .clouds.$OS_CLOUD.auth.password)
180+
REGION=$(echo "$OPENSTACK_CLOUD_CONFIG_PLAIN" | yq -r .clouds.$OS_CLOUD.region_name)
181+
PROJECT_ID=$(echo "$OPENSTACK_CLOUD_CONFIG_PLAIN" | yq -r .clouds.$OS_CLOUD.auth.project_id)
182+
DOMAIN_NAME=$(echo "$OPENSTACK_CLOUD_CONFIG_PLAIN" | yq -r .clouds.$OS_CLOUD.auth.user_domain_name)
182183

183184

184185
# Basic cloud.conf, no LB configuration as that data is not known yet.
@@ -230,7 +231,7 @@ do
230231
done
231232
for file in `ls "${PROVIDER_MANAGER_DIR}"`
232233
do
233-
sed "s/{OS_CLOUD}/$CLOUD/g" "${PROVIDER_MANAGER_DIR}/${file}" >> "$PROVIDERCOMPONENT_GENERATED_FILE"
234+
sed "s/{OS_CLOUD}/$OS_CLOUD/g" "${PROVIDER_MANAGER_DIR}/${file}" >> "$PROVIDERCOMPONENT_GENERATED_FILE"
234235
echo "---" >> "$PROVIDERCOMPONENT_GENERATED_FILE"
235236
done
236237
for file in `ls "${CLUSTER_MANAGER_DIR}"`
@@ -275,4 +276,3 @@ cat "$CLUSTER_TEMPLATE_FILE" \
275276

276277
echo "Done generating $PROVIDERCOMPONENT_GENERATED_FILE $MACHINE_GENERATED_FILE $CLUSTER_GENERATED_FILE"
277278
echo "You should now manually change your cluster configuration by editing the generated files."
278-

0 commit comments

Comments
 (0)