Skip to content

Commit 78efe2c

Browse files
committed
Make $node_name unique to avoid deleting wrong droplet on failed provision
1 parent 82a4799 commit 78efe2c

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

contrib/digitalocean/provision-digitalocean-controller.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,18 @@ api_key=${DIGITALOCEAN_API_KEY:-$(knife exec -E"puts Chef::Config[:knife][:digit
3030
# Check that client ID and API key was set
3131
if test -z $client_id; then
3232
echo "Please add your Digital Ocean Client ID to the shell's environment or knife.rb."
33+
exit 1
3334
fi
3435

3536
if test -z $api_key; then
3637
echo "Please add your Digital Ocean API Key to the shell's environment or knife.rb."
38+
exit 1
3739
fi
3840

3941
#################
4042
# chef settings #
4143
#################
42-
node_name=deis-controller
44+
node_name="deis-controller-$(tr -dc A-Za-z0-9 < /dev/urandom | head -c 5 | xargs)"
4345
run_list="recipe[deis::controller]"
4446
chef_version=11.6.2
4547

@@ -117,7 +119,7 @@ set +x
117119
if [ $result -ne 0 ]; then
118120
echo_color "Knife botstrap failed."
119121
# Destroy droplet
120-
droplet_id=$(knife digital_ocean droplet list | grep deis-controller | awk '{print $1}')
122+
droplet_id=$(knife digital_ocean droplet list | grep $node_name | awk '{print $1}')
121123
echo_color "Destroying Droplet $droplet_id..."
122124
knife digital_ocean droplet destroy -S $droplet_id
123125
# Remove node and client from Chef Server
@@ -130,4 +132,3 @@ else
130132
# Need Chef admin permission in order to add and remove nodes and clients
131133
echo -e "\033[35mPlease ensure that \"deis-controller\" is added to the Chef \"admins\" group.\033[0m"
132134
fi
133-

0 commit comments

Comments
 (0)