Skip to content

Commit d89ea98

Browse files
committed
Merge pull request #3665 from carmstrong/aws-ebs-for-etcd
fix(contrib/ec2): use EBS volume for etcd data
2 parents b8bfefd + db18ae9 commit d89ea98

2 files changed

Lines changed: 42 additions & 39 deletions

File tree

contrib/ec2/deis.template.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,10 @@
275275
{
276276
"DeviceName" : "/dev/xvdf",
277277
"Ebs" : { "VolumeSize" : "100", "VolumeType": { "Ref": "EC2EBSVolumeType" } }
278+
},
279+
{
280+
"DeviceName" : "/dev/xvdg",
281+
"Ebs" : { "VolumeSize" : "10", "VolumeType": { "Ref": "EC2EBSVolumeType" } }
278282
}
279283
]
280284
}

contrib/ec2/gen-json.py

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,6 @@
66
CURR_DIR = os.path.dirname(os.path.realpath(__file__))
77

88
# Add EC2-specific units to the shared user-data
9-
FORMAT_EPHEMERAL_VOLUME = '''
10-
[Unit]
11-
Description=Formats the ephemeral volume
12-
ConditionPathExists=!/etc/ephemeral-volume-formatted
13-
[Service]
14-
Type=oneshot
15-
RemainAfterExit=yes
16-
ExecStart=/usr/sbin/wipefs -f /dev/xvdb
17-
ExecStart=/usr/sbin/mkfs.ext4 -i 4096 -b 4096 /dev/xvdb
18-
ExecStart=/bin/touch /etc/ephemeral-volume-formatted
19-
'''
20-
MOUNT_EPHEMERAL_VOLUME = '''
21-
[Unit]
22-
Description=Formats and mounts the ephemeral drive
23-
Requires=format-ephemeral-volume.service
24-
After=format-ephemeral-volume.service
25-
[Mount]
26-
What=/dev/xvdb
27-
Where=/media/ephemeral
28-
Type=ext4
29-
'''
30-
PREPARE_ETCD_DATA_DIRECTORY = '''
31-
[Unit]
32-
Description=Prepares the etcd data directory
33-
Requires=media-ephemeral.mount
34-
After=media-ephemeral.mount
35-
Before=etcd.service
36-
[Service]
37-
Type=oneshot
38-
RemainAfterExit=yes
39-
ExecStart=/usr/bin/mkdir -p /media/ephemeral/etcd
40-
ExecStart=/usr/bin/chown -R etcd:etcd /media/ephemeral/etcd
41-
'''
429
FORMAT_DOCKER_VOLUME = '''
4310
[Unit]
4411
Description=Formats the added EBS volume for Docker
@@ -61,13 +28,45 @@
6128
Where=/var/lib/docker
6229
Type=ext4
6330
'''
31+
FORMAT_ETCD_VOLUME = '''
32+
[Unit]
33+
Description=Formats the etcd device
34+
ConditionPathExists=!/etc/etcd-volume-formatted
35+
[Service]
36+
Type=oneshot
37+
RemainAfterExit=yes
38+
ExecStart=/usr/sbin/wipefs -f /dev/xvdg
39+
ExecStart=/usr/sbin/mkfs.ext4 -i 4096 -b 4096 /dev/xvdg
40+
ExecStart=/bin/touch /etc/etcd-volume-formatted
41+
'''
42+
MOUNT_ETCD_VOLUME = '''
43+
[Unit]
44+
Description=Formats and mounts the ephemeral drive
45+
Requires=format-etcd-volume.service
46+
After=format-etcd-volume.service
47+
[Mount]
48+
What=/dev/xvdg
49+
Where=/media/etcd
50+
Type=ext4
51+
'''
52+
PREPARE_ETCD_DATA_DIRECTORY = '''
53+
[Unit]
54+
Description=Prepares the etcd data directory
55+
Requires=media-etcd.mount
56+
After=media-etcd.mount
57+
Before=etcd.service
58+
[Service]
59+
Type=oneshot
60+
RemainAfterExit=yes
61+
ExecStart=/usr/bin/chown -R etcd:etcd /media/etcd
62+
'''
6463

6564
new_units = [
66-
dict({'name': 'format-ephemeral-volume.service', 'command': 'start', 'content': FORMAT_EPHEMERAL_VOLUME}),
67-
dict({'name': 'media-ephemeral.mount', 'command': 'start', 'content': MOUNT_EPHEMERAL_VOLUME}),
68-
dict({'name': 'prepare-etcd-data-directory.service', 'command': 'start', 'content': PREPARE_ETCD_DATA_DIRECTORY}),
6965
dict({'name': 'format-docker-volume.service', 'command': 'start', 'content': FORMAT_DOCKER_VOLUME}),
70-
dict({'name': 'var-lib-docker.mount', 'command': 'start', 'content': MOUNT_DOCKER_VOLUME})
66+
dict({'name': 'var-lib-docker.mount', 'command': 'start', 'content': MOUNT_DOCKER_VOLUME}),
67+
dict({'name': 'format-etcd-volume.service', 'command': 'start', 'content': FORMAT_ETCD_VOLUME}),
68+
dict({'name': 'media-etcd.mount', 'command': 'start', 'content': MOUNT_ETCD_VOLUME}),
69+
dict({'name': 'prepare-etcd-data-directory.service', 'command': 'start', 'content': PREPARE_ETCD_DATA_DIRECTORY})
7170
]
7271

7372
data = yaml.load(file(os.path.join(CURR_DIR, '..', 'coreos', 'user-data'), 'r'))
@@ -76,8 +75,8 @@
7675
# are started
7776
data['coreos']['units'] = new_units + data['coreos']['units']
7877

79-
# configure etcd to use the ephemeral drive
80-
data['coreos']['etcd']['data-dir'] = '/media/ephemeral/etcd'
78+
# configure etcd to use its EBS volume
79+
data['coreos']['etcd']['data-dir'] = '/media/etcd'
8180

8281
header = ["#cloud-config", "---"]
8382
dump = yaml.dump(data, default_flow_style=False)

0 commit comments

Comments
 (0)