Skip to content

Commit

Permalink
Merge pull request #26 from utilitywarehouse/migrate-aws-nodes-to-v5
Browse files Browse the repository at this point in the history
Upgrade disk mounter to use nvme
  • Loading branch information
hectorhuertas committed Apr 13, 2018
2 parents c721d24 + c856785 commit 8139f92
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 70 deletions.
2 changes: 1 addition & 1 deletion cfssl.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ data "ignition_file" "cfssl-client-config" {

// used by the server
module "cfssl-disk-mounter" {
source = "./systemd_disk_mounter_nvme"
source = "./systemd_disk_mounter"

volumeid = "${var.cfssl_data_volumeid}"
user = "root"
Expand Down
42 changes: 35 additions & 7 deletions etcd.tf
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,40 @@ data "ignition_file" "etcdctl-wrapper" {
}
}

module "etcd-disk-mounter" {
source = "./systemd_disk_mounter"
data "template_file" "disk-formatter" {
count = "${length(var.etcd_data_volumeids)}"
template = "${file("${path.module}/resources/disk-formatter.service")}"

device = "xvdf"
user = "etcd"
group = "etcd"
mountpoint = "/var/lib/etcd"
vars {
volumeid = "${var.etcd_data_volumeids[count.index]}"
user = "etcd"
group = "etcd"
filesystem = "ext4"
}
}

data "ignition_systemd_unit" "disk-formatter" {
count = "${length(var.etcd_data_volumeids)}"
name = "disk-formatter.service"
content = "${element(data.template_file.disk-formatter.*.rendered, count.index)}"
}

data "template_file" "disk-mounter" {
count = "${length(var.etcd_data_volumeids)}"
template = "${file("${path.module}/resources/disk-mounter.mount")}"

vars {
volumeid = "${var.etcd_data_volumeids[count.index]}"
mountpoint = "/var/lib/etcd"
filesystem = "ext4"
disk-formatter = "disk-formatter.service"
}
}

data "ignition_systemd_unit" "var-lib-etcd-mounter" {
count = "${length(var.etcd_data_volumeids)}"
name = "var-lib-etcd.mount"
content = "${element(data.template_file.disk-mounter.*.rendered, count.index)}"
}

resource "null_resource" "etcd_member" {
Expand Down Expand Up @@ -135,8 +162,9 @@ data "ignition_config" "etcd" {
data.ignition_systemd_unit.docker-opts-dropin.id,
data.ignition_systemd_unit.node-exporter.id,
element(data.ignition_systemd_unit.etcd-member-dropin.*.id, count.index),
element(data.ignition_systemd_unit.disk-formatter.*.id, count.index),
element(data.ignition_systemd_unit.var-lib-etcd-mounter.*.id, count.index),
),
module.etcd-disk-mounter.systemd_units,
module.etcd-member-restarter.systemd_units,
var.etcd_additional_systemd_units,
)}"]
Expand Down
7 changes: 7 additions & 0 deletions resources/disk-formatter.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[Unit]
Description=Format device with volume-id: ${volumeid}, if it has no filesystem
[Service]
Type=oneshot
RemainAfterExit=yes
Environment=DEVICE=/dev/disk/by-id/nvme-Amazon_Elastic_Block_Store_${volumeid}
ExecStart=/bin/sh -c "fsck -a $${DEVICE} || (mkfs.${filesystem} $${DEVICE} && mount $${DEVICE} /mnt && chown -R ${user}:${group} /mnt && umount /mnt)"
8 changes: 8 additions & 0 deletions resources/disk-mounter.mount
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Unit]
Description=Mount device ${volumeid} to ${mountpoint}
Requires=${disk-formatter}
After=${disk-formatter}
[Mount]
What=/dev/disk/by-id/nvme-Amazon_Elastic_Block_Store_${volumeid}
Where=${mountpoint}
Type=${filesystem}
15 changes: 7 additions & 8 deletions systemd_disk_mounter/main.tf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
variable "device" {}
variable "volumeid" {}
variable "mountpoint" {}

variable "user" {
Expand All @@ -14,17 +14,16 @@ variable "filesystem" {
}

data "ignition_systemd_unit" "disk-formatter" {
name = "disk-formatter-${var.device}.service"
name = "disk-formatter-${var.volumeid}.service"

content = <<EOS
[Unit]
Description=Format device ${var.device}, if it has no filesystem
After=dev-${var.device}.device
Requires=dev-${var.device}.device
Description=Format device with volume-id: ${var.volumeid}, if it has no filesystem
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/sh -c "fsck -a /dev/${var.device} || (mkfs.${var.filesystem} /dev/${var.device} && mount /dev/${var.device} /mnt && chown -R ${var.user}:${var.group} /mnt && umount /mnt)"
Environment=DEVICE=/dev/disk/by-id/nvme-Amazon_Elastic_Block_Store_${var.volumeid}
ExecStart=/bin/sh -c "fsck -a $${DEVICE} || (mkfs.${var.filesystem} $${DEVICE} && mount $${DEVICE} /mnt && chown -R ${var.user}:${var.group} /mnt && umount /mnt)"
EOS
}

Expand All @@ -33,11 +32,11 @@ data "ignition_systemd_unit" "disk-mounter" {

content = <<EOS
[Unit]
Description=Mount device ${var.device} volume to ${var.mountpoint}
Description=Mount device ${var.volumeid} to ${var.mountpoint}
Requires=${data.ignition_systemd_unit.disk-formatter.name}
After=${data.ignition_systemd_unit.disk-formatter.name}
[Mount]
What=/dev/${var.device}
What=/dev/disk/by-id/nvme-Amazon_Elastic_Block_Store_${var.volumeid}
Where=${var.mountpoint}
Type=${var.filesystem}
EOS
Expand Down
54 changes: 0 additions & 54 deletions systemd_disk_mounter_nvme/main.tf

This file was deleted.

4 changes: 4 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,7 @@ variable "cfssl_server_address" {
}

variable "cfssl_data_volumeid" {}

variable "etcd_data_volumeids" {
type = "list"
}

0 comments on commit 8139f92

Please sign in to comment.