Skip to content

Commit d332f73

Browse files
committed
Merge pull request #4090 from mboersma/etcd2-min
chore(*): use etcd2 inside a container, extended dance remix
2 parents 8a672ad + 02aac50 commit d332f73

10 files changed

Lines changed: 87 additions & 36 deletions

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ dev-cluster: discovery-url
3030
deisctl install platform
3131

3232
discovery-url:
33-
sed -e "s,# discovery:,discovery:," -e "s,discovery: https://discovery.etcd.io/.*,discovery: $$(curl -s -w '\n' https://discovery.etcd.io/new)," contrib/coreos/user-data.example > contrib/coreos/user-data
33+
sed -e "s,discovery #DISCOVERY_URL,discovery $$(curl -s -w '\n' https://discovery.etcd.io/new?size=$$DEIS_NUM_INSTANCES)," contrib/coreos/user-data.example > contrib/coreos/user-data
3434

3535
build: check-docker
3636
@$(foreach C, $(COMPONENTS), $(MAKE) -C $(C) build &&) echo done

Vagrantfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Vagrant.configure("2") do |config|
9090
end
9191

9292
config.trigger.before :up do
93-
if !File.exists?(CLOUD_CONFIG_PATH) || File.readlines(CLOUD_CONFIG_PATH).grep(/#\s*discovery:/).any?
93+
if !File.exists?(CLOUD_CONFIG_PATH) || File.readlines(CLOUD_CONFIG_PATH).grep(/\s*discovery #DISCOVERY_URL/).any?
9494
raise Vagrant::Errors::VagrantError.new, "Run 'make discovery-url' first to create user-data."
9595
end
9696
end

contrib/aws/gen-json.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,13 @@
101101
# are started
102102
data['coreos']['units'] = new_units + data['coreos']['units']
103103

104-
# configure etcd to use its EBS volume
105-
data['coreos']['etcd']['data-dir'] = '/media/etcd'
106-
107104
header = ["#cloud-config", "---"]
108105
dump = yaml.dump(data, default_flow_style=False)
109106

107+
# configure etcd to use its EBS volume
108+
dump = dump.replace('-data-dir /var/lib/etcd2', '-data-dir /media/etcd')
109+
dump = dump.replace('--volume=/var/lib/etcd2', '--volume=/media/etcd')
110+
110111
template = json.load(open(os.path.join(CURR_DIR, 'deis.template.json'), 'r'))
111112

112113
template['Resources']['CoreOSServerLaunchConfig']['Properties']['UserData']['Fn::Base64']['Fn::Join'] = ["\n", header + dump.split("\n")]

contrib/aws/provision-aws-cluster.sh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,29 @@ ELB_NAME=$(aws elb describe-load-balancers \
136136
$EXTRA_AWS_CLI_ARGS | grep -F $ELB_DNS_NAME | head -n1 | cut -f2)
137137
echo "Using ELB $ELB_NAME at $ELB_DNS_NAME"
138138
139-
echo_green "Your Deis cluster has been successfully deployed to AWS CloudFormation and is started."
140-
echo_green "Please continue to follow the instructions in the documentation."
141-
142139
FIRST_INSTANCE=$(aws ec2 describe-instances \
143140
--filters Name=tag:aws:cloudformation:stack-name,Values=$STACK_NAME Name=instance-state-name,Values=running \
144141
--query 'Reservations[].Instances[].[PublicIpAddress]' \
145142
--output text \
146143
$EXTRA_AWS_CLI_ARGS | head -1)
147144
export DEISCTL_TUNNEL=$FIRST_INSTANCE
148-
echo_green "Enabling proxy protocol"
149145
146+
# loop until etcd2 / fleet are up and running
147+
COUNTER=1
148+
until deisctl list >/dev/null; do
149+
if [ $COUNTER -gt $ATTEMPTS ];
150+
then echo_red "Timed out waiting for fleet, giving up"
151+
break
152+
fi
153+
echo "Waiting until fleet is up and running ..."
154+
sleep 5
155+
let COUNTER=COUNTER+1
156+
done
157+
158+
echo_green "Your Deis cluster has been successfully deployed to AWS CloudFormation and is started."
159+
echo_green "Please continue to follow the instructions in the documentation."
160+
161+
echo_green "Enabling proxy protocol"
150162
if ! deisctl config router set proxyProtocol=1; then
151163
echo_red "#"
152164
echo_red "# Enabling proxy protocol failed, please enable proxy protocol "

contrib/azure/create-azure-user-data

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,12 @@ def main():
6262
configuration = combine_dicts(configuration_coreos_template,
6363
configuration_azure_template)
6464

65-
configuration["coreos"]["etcd"]["discovery"] = url
65+
dump = yaml.dump(configuration, default_flow_style=False)
66+
dump = dump.replace('#DISCOVERY_URL', url)
6667

6768
with azure_user_data as outfile:
6869
try:
69-
outfile.write("#cloud-config\n\n" + yaml.dump(configuration, default_flow_style=False))
70+
outfile.write("#cloud-config\n\n" + dump)
7071
except (IOError, ValueError):
7172
print "There was an issue writing to file " + azure_user_data.name
7273
return 1

contrib/coreos/user-data.example

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
#cloud-config
22
---
33
coreos:
4-
etcd:
5-
# generate a new token for each unique cluster from https://discovery.etcd.io/new
6-
# uncomment the following line and replace it with your discovery URL
7-
# discovery: https://discovery.etcd.io/12345693838asdfasfadf13939923
8-
addr: $private_ipv4:4001
9-
peer-addr: $private_ipv4:7001
10-
# give etcd more time if it's under heavy load - prevent leader election thrashing
11-
peer-election-timeout: 2000
12-
# heartbeat interval should ideally be 1/4 or 1/5 of peer election timeout
13-
peer-heartbeat-interval: 500
144
fleet:
155
# We have to set the public_ip here so this works on Vagrant -- otherwise, Vagrant VMs
166
# will all publish the same private IP. This is harmless for cloud providers.
@@ -20,6 +10,46 @@ coreos:
2010
units:
2111
- name: etcd.service
2212
command: start
13+
content: |
14+
[Unit]
15+
Description=etcd2 container
16+
Requires=early-docker.service
17+
After=early-docker.service
18+
Before=early-docker.target
19+
20+
[Service]
21+
User=etcd
22+
PermissionsStartOnly=true
23+
Restart=always
24+
RestartSec=10s
25+
LimitNOFILE=40000
26+
EnvironmentFile=/etc/environment
27+
Environment="ETCD_IMAGE=quay.io/coreos/etcd:v2.0.13"
28+
Environment="ETCD_ELECTION_TIMEOUT=2000"
29+
Environment="ETCD_HEARTBEAT_INTERVAL=400"
30+
Environment="ETCD_DATA_DIR=/var/lib/etcd2"
31+
Environment="ETCD_NAME=%m"
32+
Environment="DOCKER_HOST=unix:///var/run/early-docker.sock"
33+
ExecStartPre=/bin/sh -c "docker history $ETCD_IMAGE >/dev/null 2>&1 || docker pull $ETCD_IMAGE"
34+
ExecStartPre=/bin/sh -c "docker inspect $ETCD_NAME >/dev/null 2>&1 && docker rm -f $ETCD_NAME || true"
35+
ExecStart=/usr/bin/docker run --net=host --rm \
36+
--volume=${ETCD_DATA_DIR}:/var/lib/etcd2 \
37+
--volume=/usr/share/ca-certificates:/etc/ssl/certs:ro \
38+
-p 4001:4001 -p 2380:2380 -p 2379:2379 -p 7001:7001 \
39+
--name ${ETCD_NAME} \
40+
${ETCD_IMAGE} \
41+
-name ${ETCD_NAME} \
42+
-data-dir /var/lib/etcd2 \
43+
-advertise-client-urls http://${COREOS_PRIVATE_IPV4}:2379,http://${COREOS_PRIVATE_IPV4}:4001 \
44+
-listen-client-urls http://0.0.0.0:2379,http://0.0.0.0:4001 \
45+
-initial-advertise-peer-urls http://${COREOS_PRIVATE_IPV4}:2380,http://${COREOS_PRIVATE_IPV4}:7001 \
46+
-listen-peer-urls http://0.0.0.0:2380,http://0.0.0.0:7001 \
47+
--heartbeat-interval ${ETCD_HEARTBEAT_INTERVAL} \
48+
--election-timeout ${ETCD_ELECTION_TIMEOUT} \
49+
--discovery #DISCOVERY_URL
50+
ExecStop=-/usr/bin/docker stop $ETCD_NAME
51+
- name: etcd2.service
52+
mask: true
2353
- name: docker-tcp.socket
2454
command: start
2555
enable: true
@@ -244,9 +274,16 @@ write_files:
244274
/usr/bin/docker exec deis-store-admin ceph mon remove `hostname -f` # fixme
245275
/usr/bin/docker stop deis-store-metadata || true
246276
fi
247-
NODE=$(curl -L http://127.0.0.1:7001/v2/admin/machines/`cat /etc/machine-id`)
248-
# remove from etcd cluster
249-
if [ $NODE != 'null' ]; then
250-
/usr/bin/curl -L -XDELETE http://127.0.0.1:7001/v2/admin/machines/`cat /etc/machine-id`
277+
278+
# TODO: remove the next check once etcdctl is using etcd2
279+
ETCDCTL=/usr/bin/etcdctl
280+
if ! $ETCDCTL --version | grep -q "etcdctl version 2.0."; then
281+
ETCD_VERSION=2.0.13
282+
curl -sSL https://github.com/coreos/etcd/releases/download/v${ETCD_VERSION}/etcd-v${ETCD_VERSION}-linux-amd64.tar.gz | \
283+
tar zxv -C /opt/bin etcd-v${ETCD_VERSION}-linux-amd64/etcdctl --strip=1
284+
ETCDCTL="/opt/bin/etcdctl"
251285
fi
286+
# removing the node from etcd
287+
NODE=$($ETCDCTL member list | grep `cat /etc/machine-id` | cut -d ':' -f 1)
288+
$ETCDCTL member remove $NODE
252289
manage_etc_hosts: localhost

contrib/gce/create-gce-user-data

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,13 @@ def main():
6262
configuration = combine_dicts(configuration_coreos_template,
6363
configuration_gce_template)
6464

65-
configuration["coreos"]["etcd"]["discovery"] = url
65+
dump = yaml.dump(configuration, default_flow_style=False,
66+
default_style='|')
67+
dump = dump.replace('#DISCOVERY_URL', url)
6668

6769
with gce_user_data as outfile:
6870
try:
69-
outfile.write("#cloud-config\n\n" +
70-
yaml.safe_dump(configuration,
71-
default_flow_style=False,
72-
default_style='|'))
71+
outfile.write("#cloud-config\n\n" + dump)
7372
except (IOError, ValueError):
7473
print "There was an issue writing to file " + gce_user_data.name
7574
return 1

contrib/linode/apply-firewall.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ def get_discovery_url_from_user_data():
4646
try:
4747
current_dir = os.path.dirname(__file__)
4848
user_data_file = file(os.path.abspath(os.path.join(current_dir, name)), 'r')
49-
user_data = yaml.safe_load(user_data_file)
50-
return user_data['coreos']['etcd']['discovery']
49+
return re.search('--discovery (http\S+)', user_data_file.read()).group(1)
5150
except:
5251
raise IOError('Could not load discovery url from ' + name)
5352

contrib/linode/create-linode-user-data.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,13 @@ def main():
7171
configuration_coreos_template = yaml.safe_load(coreos_template)
7272

7373
configuration = combine_dicts(configuration_coreos_template, configuration_linode_template)
74-
configuration['coreos']['etcd']['discovery'] = 'https://discovery.etcd.io/' + str(etcd_token)
7574
configuration['ssh_authorized_keys'] = public_keys
7675

76+
dump = yaml.dump(configuration, default_flow_style=False, default_style='|')
77+
dump = dump.replace('#DISCOVERY_URL', 'https://discovery.etcd.io/' + str(etcd_token))
78+
7779
with linode_user_data as outfile:
78-
outfile.write("#cloud-config\n\n" + yaml.safe_dump(configuration, default_flow_style=False, default_style='|'))
80+
outfile.write("#cloud-config\n\n" + dump)
7981
log_success('Wrote Linode user data to ' + linode_user_data.name)
8082

8183

contrib/util/check-user-data.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ function parse_yaml {
2626
}
2727

2828
if [[ $NUM_INSTANCES -ne 1 ]] ; then
29-
parse_yaml $USER_DATA | grep -q coreos_etcd_discovery
30-
if [[ $? -ne 0 ]]; then
29+
parse_yaml $USER_DATA | grep -q "#DISCOVERY_URL"
30+
if [[ $? -ne 1 ]]; then
3131
echo "No etcd discovery URL set in $USER_DATA"
3232
exit 1
3333
fi

0 commit comments

Comments
 (0)