From 2e474753b0b7161f35ea2a8f7a5d94d83d623cd9 Mon Sep 17 00:00:00 2001 From: anon6789 Date: Fri, 14 Aug 2020 09:51:45 +0200 Subject: [PATCH] add hcloud csi driver volume support --- README.md | 1 + install-hcloud-csi.tf | 20 ++++++++++++++++++++ scripts/install-hcloud-csi.sh | 7 +++++++ variables.tf | 3 +++ 4 files changed, 31 insertions(+) create mode 100644 install-hcloud-csi.tf create mode 100644 scripts/install-hcloud-csi.sh diff --git a/README.md b/README.md index 1bce29f..dbaa192 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,7 @@ $ KUBECONFIG=secrets/admin.conf kubectl expose deploy nginx --port=80 --type Nod | `kubernetes_version` | `1.18.6` | Kubernetes version that will be installed | No | | `feature_gates` | `` | Add your own Feature Gates for Kubeadm | No | | `calico_enabled` | `false` | Installs Calico Network Provider after the master comes up | No | +| `csi_driver_enabled` | `false` | Installs [hcloud-csi driver](https://github.com/hetznercloud/csi-driver) for persistent volume support | No | All variables cloud be passed through `environment variables` or a `tfvars` file. diff --git a/install-hcloud-csi.tf b/install-hcloud-csi.tf new file mode 100644 index 0000000..7714fb9 --- /dev/null +++ b/install-hcloud-csi.tf @@ -0,0 +1,20 @@ +resource "null_resource" "hcloud-csi" { + count = var.csi_driver_enabled ? 1 : 0 + + connection { + host = hcloud_server.master.0.ipv4_address + private_key = file(var.ssh_private_key) + } + + provisioner "file" { + source = "scripts/install-hcloud-csi.sh" + destination = "/root/install-hcloud-csi.sh" + } + + provisioner "remote-exec" { + inline = ["HCLOUD_TOKEN=${var.hcloud_token} bash /root/install-hcloud-csi.sh"] + } + + depends_on = [hcloud_server.master] +} + diff --git a/scripts/install-hcloud-csi.sh b/scripts/install-hcloud-csi.sh new file mode 100644 index 0000000..73ce698 --- /dev/null +++ b/scripts/install-hcloud-csi.sh @@ -0,0 +1,7 @@ +#!/usr/bin/bas +set -eu + +#create secret with hcloud token for hcloud-csi driver +kubectl -n kube-system create secret generic hcloud-csi --from-literal=token=$HCLOUD_TOKEN --dry-run=client -o yaml | kubectl apply -f - + +kubectl apply -f https://raw.githubusercontent.com/hetznercloud/csi-driver/v1.4.0/deploy/kubernetes/hcloud-csi.yml \ No newline at end of file diff --git a/variables.tf b/variables.tf index 2158cd7..74a013b 100755 --- a/variables.tf +++ b/variables.tf @@ -54,3 +54,6 @@ variable "calico_enabled" { default = false } +variable "csi_driver_enabled" { + default = false +} \ No newline at end of file