diff --git a/README.md b/README.md index d9fb2b3..8c92c5d 100644 --- a/README.md +++ b/README.md @@ -54,13 +54,12 @@ Follow those simple steps, and your world's cheapest Kube cluster will be up and First and foremost, you need to have a Hetzner Cloud account. You can sign up for free [here](https://hetzner.com/cloud/). -Then you'll need to have [terraform](https://learn.hashicorp.com/tutorials/terraform/install-cli), [kubectl](https://kubernetes.io/docs/tasks/tools/) cli, [helm]() Helm and [hcloud]() the Hetzner cli. The easiest way is to use the [homebrew](https://brew.sh/) package manager to install them (available on Linux, Mac, and Windows Linux Subsystem). +Then you'll need to have [terraform](https://learn.hashicorp.com/tutorials/terraform/install-cli), [kubectl](https://kubernetes.io/docs/tasks/tools/) cli and [hcloud]() the Hetzner cli. The easiest way is to use the [homebrew](https://brew.sh/) package manager to install them (available on Linux, Mac, and Windows Linux Subsystem). ```sh brew install terraform brew install kubectl brew install hcloud -brew install helm ``` diff --git a/helm/longhorn.yaml b/helm/longhorn.yaml deleted file mode 100644 index bd3e6f2..0000000 --- a/helm/longhorn.yaml +++ /dev/null @@ -1,22 +0,0 @@ ---- -helmDefaults: - timeout: 3600 - wait: true - force: false - atomic: true - -repositories: - - name: longhorn - url: https://charts.longhorn.io - -releases: - - name: longhorn - namespace: longhorn - chart: longhorn/longhorn - values: - - persistence: - defaultClass: {{ requiredEnv "HETZNER_CSI_DISABLED" }} - defaultFsType: ext4 - defaultClassReplicaCount: 2 - - defaultSettings: - defaultDataPath: /var/longhorn diff --git a/init.tf b/init.tf index 77ee7f7..f790c8f 100644 --- a/init.tf +++ b/init.tf @@ -87,6 +87,7 @@ resource "null_resource" "kustomization" { "https://raw.githubusercontent.com/rancher/system-upgrade-controller/master/manifests/system-upgrade-controller.yaml", ], var.disable_hetzner_csi ? [] : ["https://raw.githubusercontent.com/hetznercloud/csi-driver/${local.csi_version}/deploy/kubernetes/hcloud-csi.yml"], + var.enable_longhorn ? ["longhorn.yaml"] : [], local.is_single_node_cluster ? [] : var.traefik_enabled ? ["traefik_config.yaml"] : [], var.cni_plugin == "calico" ? ["https://projectcalico.docs.tigera.io/manifests/calico.yaml"] : [] ), @@ -128,6 +129,16 @@ resource "null_resource" "kustomization" { destination = "/var/post_install/plans.yaml" } + # Upload the Longhorn config + provisioner "file" { + content = templatefile( + "${path.module}/templates/longhorn.yaml.tpl", + { + disable_hetzner_csi = var.disable_hetzner_csi + }) + destination = "/var/post_install/longhorn.yaml" + } + # Deploy secrets, logging is automatically disabled due to sensitive variables provisioner "remote-exec" { inline = [ @@ -171,24 +182,3 @@ resource "null_resource" "kustomization" { local_sensitive_file.kubeconfig ] } - -resource "null_resource" "longhorn" { - # If longhorn isn't enabled, we don't want any Helm resources - count = var.enable_longhorn ? 1 : 0 - - # Install Helm charts - provisioner "local-exec" { - when = create - command = <<-EOT - export KUBECONFIG=$(readlink -f ${path.module}/kubeconfig.yaml) - export HETZNER_CSI_DISABLED=${var.disable_hetzner_csi ? "true" : "false"} - helmfile -f ${path.module}/helm/longhorn.yaml apply - EOT - on_failure = continue - } - - depends_on = [ - null_resource.first_control_plane, - local_sensitive_file.kubeconfig - ] -} diff --git a/templates/longhorn.yaml.tpl b/templates/longhorn.yaml.tpl new file mode 100644 index 0000000..fc28768 --- /dev/null +++ b/templates/longhorn.yaml.tpl @@ -0,0 +1,22 @@ +--- +apiVersion: v1 +kind: Namespace +metadata: + name: longhorn +--- +apiVersion: helm.cattle.io/v1 +kind: HelmChart +metadata: + name: longhorn + namespace: kube-system +spec: + chart: longhorn + repo: https://charts.longhorn.io + targetNamespace: longhorn + valuesContent: |- + defaultSettings: + defaultDataPath: /var/longhorn + persistence: + defaultFsType: ext4 + defaultClassReplicaCount: 2 + %{ if disable_hetzner_csi ~}defaultClass: true%{ else ~}defaultClass: false%{ endif ~} diff --git a/templates/plans.yaml.tpl b/templates/plans.yaml.tpl index 337aa59..508dcca 100644 --- a/templates/plans.yaml.tpl +++ b/templates/plans.yaml.tpl @@ -47,4 +47,4 @@ spec: serviceAccountName: system-upgrade cordon: true upgrade: - image: rancher/k3s-upgrade \ No newline at end of file + image: rancher/k3s-upgrade