Skip to content

Commit

Permalink
Merge pull request #18 from nimbolus/fix-data-volume-mount
Browse files Browse the repository at this point in the history
fix mount data volume by label
  • Loading branch information
lu1as authored May 4, 2022
2 parents f4fd590 + 1fe7718 commit f30007c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
3 changes: 2 additions & 1 deletion k3s-openstack/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
locals {
create_data_volume = var.data_volume_size > 0
data_volume_name = var.image_scsi_bus ? "/dev/sdb" : "/dev/vdb"
data_volume_name = var.ephemeral_data_volume ? "ephemeral0" : (var.image_scsi_bus ? "/dev/sdb" : "/dev/vdb")
}

data "openstack_compute_flavor_v2" "k3s" {
Expand Down Expand Up @@ -43,6 +43,7 @@ module "k3s" {
bootstrap_token_id = var.bootstrap_token_id
bootstrap_token_secret = var.bootstrap_token_secret
persistent_volume_dev = local.create_data_volume ? local.data_volume_name : ""
persistent_volume_label = var.ephemeral_data_volume ? "ephemeral0" : "k3s-data"
}

resource "openstack_compute_instance_v2" "node" {
Expand Down
8 changes: 6 additions & 2 deletions k3s/cloud-init/k3s.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

%{if persistent_volume_dev != ""~}
fs_setup:
- label: k3s-data
- label: ${persistent_volume_label}
filesystem: ext4
device: ${persistent_volume_dev}

mounts:
- [${persistent_volume_dev}, /mnt/persistent]
%{if persistent_volume_dev == persistent_volume_label~}
# clear default mount for ephemeral disk
- [${persistent_volume_dev}, null]
%{endif~}
- [LABEL=${persistent_volume_label}, /mnt/persistent]
%{endif~}

write_files:
Expand Down
1 change: 1 addition & 0 deletions k3s/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ output "user_data" {
ip = var.k3s_ip
external_ip = var.k3s_external_ip
persistent_volume_dev = var.persistent_volume_dev
persistent_volume_label = var.persistent_volume_label
is_server = contains(var.k3s_args, "server")
k3s_config = base64encode(<<-EOT
K3S_TOKEN=${var.cluster_token}
Expand Down
5 changes: 5 additions & 0 deletions k3s/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ variable "persistent_volume_dev" {
description = "optional device for persistent data (e.g. /dev/vdb)"
}

variable "persistent_volume_label" {
default = "k3s-data"
description = "filesystem label for persistent data"
}

variable "cni_plugins_version" {
default = "v0.9.0"
}

0 comments on commit f30007c

Please sign in to comment.