Skip to content

Commit

Permalink
Merge pull request #32 from utilitywarehouse/gce-provider
Browse files Browse the repository at this point in the history
Alter ignition module to add gcd provider specific variables
  • Loading branch information
ffilippopoulos authored May 1, 2018
2 parents d0c03f9 + c619468 commit 2630fae
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 8 deletions.
21 changes: 21 additions & 0 deletions _data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,26 @@ variable "node_name_command" {
default = {
"" = "hostname -f"
"aws" = "curl -s http://169.254.169.254/latest/meta-data/local-hostname"
"gce" = "curl -s http://metadata.google.internal/computeMetadata/v1/instance/hostname -H Metadata-Flavor:Google"
}
}

variable "get_ip_command" {
type = "map"

default = {
"" = ""
"aws" = "curl -s http://169.254.169.254/latest/meta-data/local-ipv4"
"gce" = "curl -s http://metadata.google.internal/computeMetadata/v1/instance/network-interfaces/0/ip -H Metadata-Flavor:Google"
}
}

variable "kubernetes_master_default_svc" {
type = "map"

default = {
"" = "10.3.0.1"
"aws" = "10.3.0.1"
"gce" = "10.5.0.1"
}
}
14 changes: 12 additions & 2 deletions cfssl.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ data "ignition_file" "cfssl-client-config" {
}

data "template_file" "cfssl-disk-formatter" {
template = "${file("${path.module}/resources/disk-formatter.service")}"
template = "${ var.cloud_provider == "aws" ?
file("${path.module}/resources/aws-disk-formatter.service")
:var.cloud_provider == "gce" ?
file("${path.module}/resources/gce-disk-formatter.service")
:""
}"

vars {
volumeid = "${var.cfssl_data_volumeid}"
Expand All @@ -53,7 +58,12 @@ data "ignition_systemd_unit" "cfssl-disk-formatter" {
}

data "template_file" "cfssl-disk-mounter" {
template = "${file("${path.module}/resources/disk-mounter.mount")}"
template = "${ var.cloud_provider == "aws" ?
file("${path.module}/resources/aws-disk-mounter.mount")
:var.cloud_provider == "gce" ?
file("${path.module}/resources/gce-disk-mounter.mount")
:""
}"

vars {
volumeid = "${var.cfssl_data_volumeid}"
Expand Down
21 changes: 17 additions & 4 deletions etcd.tf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ data "template_file" "etcd-cfssl-new-cert" {
path = "/etc/etcd/ssl"
cn = "${count.index}.etcd.${var.dns_domain}"
org = ""
get_ip = "${var.get_ip_command[var.cloud_provider]}"

extra_names = "${join(",", list(
"etcd.${var.dns_domain}",
Expand Down Expand Up @@ -67,8 +68,14 @@ data "ignition_file" "etcdctl-wrapper" {
}

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

template = "${ var.cloud_provider == "aws" ?
file("${path.module}/resources/aws-disk-formatter.service")
:var.cloud_provider == "gce" ?
file("${path.module}/resources/gce-disk-formatter.service")
:""
}"

vars {
volumeid = "${var.etcd_data_volumeids[count.index]}"
Expand All @@ -85,8 +92,14 @@ data "ignition_systemd_unit" "disk-formatter" {
}

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

template = "${ var.cloud_provider == "aws" ?
file("${path.module}/resources/aws-disk-mounter.mount")
:var.cloud_provider == "gce" ?
file("${path.module}/resources/gce-disk-mounter.mount")
:""
}"

vars {
volumeid = "${var.etcd_data_volumeids[count.index]}"
Expand Down
3 changes: 2 additions & 1 deletion master.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ data "template_file" "master-cfssl-new-cert" {
path = "/etc/kubernetes/ssl"
cn = "system:node:$(${var.node_name_command[var.cloud_provider]})"
org = "system:nodes"
get_ip = "${var.get_ip_command[var.cloud_provider]}"

extra_names = "${join(",", list(
"10.3.0.1",
"${var.kubernetes_master_default_svc[var.cloud_provider]}",
"kubernetes",
"kubernetes.default",
"kubernetes.default.svc",
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion resources/cfssl-new-cert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ set -o errexit
mkdir -p ${path}
cd ${path}

_ip="$(ip addr show dev eth0 | grep 'inet ' | awk '{ print $2; }' | cut -d/ -f1)"
_ip="$(${get_ip})"
_hostname="$(hostname)"

/opt/bin/cfssl gencert \
Expand Down
9 changes: 9 additions & 0 deletions resources/gce-disk-formatter.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[Unit]
Description=Format device with volume-id: ${volumeid}, if it has no filesystem
After=dev-disk-by\x2did-google\x2d${volumeid}.device
Requires=dev-disk-by\x2did-google\x2d${volumeid}.device
[Service]
Type=oneshot
RemainAfterExit=yes
Environment=DEVICE=/dev/disk/by-id/google-${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/gce-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/google-${volumeid}
Where=${mountpoint}
Type=${filesystem}
1 change: 1 addition & 0 deletions worker.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ data "template_file" "worker-cfssl-new-cert" {
path = "/etc/kubernetes/ssl"
cn = "system:node:$(${var.node_name_command[var.cloud_provider]})"
org = "system:nodes"
get_ip = "${var.get_ip_command[var.cloud_provider]}"
extra_names = ""
}
}
Expand Down

0 comments on commit 2630fae

Please sign in to comment.