Skip to content

Commit db9dc32

Browse files
committed
fix(contrib): check that coreos/user-data has a discovery_url set
1 parent ca5abd0 commit db9dc32

4 files changed

Lines changed: 49 additions & 0 deletions

File tree

Vagrantfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ Vagrant.configure("2") do |config|
4949

5050
# user-data bootstrapping
5151
config.vm.provision :file, :source => "contrib/coreos/user-data", :destination => "/tmp/vagrantfile-user-data"
52+
# check that the CoreOS user-data file is valid
53+
config.vm.provision :shell do |s|
54+
s.path = "contrib/util/check-user-data.sh"
55+
s.args = ["/tmp/vagrantfile-user-data", "#{DEIS_NUM_INSTANCES}"]
56+
end
5257
config.vm.provision :shell, :inline => "mv /tmp/vagrantfile-user-data /var/lib/coreos-vagrant/", :privileged => true
5358
end
5459
end

contrib/ec2/provision-ec2-cluster.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ if ! which aws > /dev/null; then
1616
exit 1
1717
fi
1818

19+
if [ -z "$DEIS_NUM_INSTANCES" ]; then
20+
DEIS_NUM_INSTANCES=3
21+
fi
22+
23+
# check that the CoreOS user-data file is valid
24+
$CONTRIB_DIR/util/check-user-data.sh
25+
1926
# create an EC2 cloudformation stack based on CoreOS's default template
2027
aws cloudformation create-stack \
2128
--template-body "$(./gen-json.py)" \

contrib/rackspace/provision-rackspace-cluster.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ if [ -z "$DEIS_NUM_INSTANCES" ]; then
3737
DEIS_NUM_INSTANCES=3
3838
fi
3939

40+
# check that the CoreOS user-data file is valid
41+
$CONTRIB_DIR/util/check-user-data.sh
42+
4043
i=1 ; while [[ $i -le $DEIS_NUM_INSTANCES ]] ; do \
4144
echo_yellow "Provisioning deis-$i..."
4245
supernova production boot --image 24614284-19a9-4348-bee3-a504d7094d1b --flavor $FLAVOR --key-name $1 --user-data ../coreos/user-data --no-service-net --nic net-id=$NETWORK_ID --config-drive true deis-$i ; \

contrib/util/check-user-data.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash
2+
3+
THIS_DIR=$(cd $(dirname $0); pwd) # absolute path
4+
CONTRIB_DIR=$(dirname $THIS_DIR)
5+
6+
# Use the first command-line argument as the user-data path
7+
USER_DATA=${1:-$CONTRIB_DIR/coreos/user-data}
8+
# Use the second command-line argument as DEIS_NUM_INSTANCES
9+
NUM_INSTANCES=${2:-DEIS_NUM_INSTANCES}
10+
11+
function parse_yaml {
12+
local prefix=$2
13+
local s='[[:space:]]*' w='[a-zA-Z0-9_]*' fs=$(echo @|tr @ '\034')
14+
sed -ne "s|^\($s\):|\1|" \
15+
-e "s|^\($s\)\($w\)$s:$s[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
16+
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" $1 |
17+
awk -F$fs '{
18+
indent = length($1)/2;
19+
vname[indent] = $2;
20+
for (i in vname) {if (i > indent) {delete vname[i]}}
21+
if (length($3) > 0) {
22+
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
23+
printf("%s%s%s=\"%s\"\n", "'$prefix'",vn, $2, $3);
24+
}
25+
}'
26+
}
27+
28+
if [[ $NUM_INSTANCES -ne 1 ]] ; then
29+
parse_yaml $USER_DATA | grep -q coreos_etcd_discovery
30+
if [[ $? -ne 0 ]]; then
31+
echo "No etcd discovery URL set in $USER_DATA"
32+
exit 1
33+
fi
34+
fi

0 commit comments

Comments
 (0)