Skip to content

Commit

Permalink
terraform-openstack: Added possibility to enable dhcp flag critical o…
Browse files Browse the repository at this point in the history
…n one interface (#10446)

* terraform-openstack: Updated extra partitions to use empty list by default

* terraform-openstack: Added possibility to enable dhcp flag critical on one interface
  • Loading branch information
Xartos committed Sep 20, 2023
1 parent a81c6d5 commit d669b93
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 7 deletions.
1 change: 1 addition & 0 deletions contrib/terraform/openstack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ k8s_nodes:
mount_path: string # Path to where the partition should be mounted
partition_start: string # Where the partition should start (e.g. 10GB ). Note, if you set the partition_start to 0 there will be no space left for the root partition
partition_end: string # Where the partition should end (e.g. 10GB or -1 for end of volume)
netplan_critical_dhcp_interface: string # Name of interface to set the dhcp flag critical = true, to circumvent [this issue](https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1776013).
```

For example:
Expand Down
7 changes: 4 additions & 3 deletions contrib/terraform/openstack/modules/compute/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ data "cloudinit_config" "cloudinit" {
part {
content_type = "text/cloud-config"
content = templatefile("${path.module}/templates/cloudinit.yaml.tmpl", {
# template_file doesn't support lists
extra_partitions = ""
extra_partitions = [],
netplan_critical_dhcp_interface = ""
})
}
}
Expand Down Expand Up @@ -821,7 +821,8 @@ resource "openstack_compute_instance_v2" "k8s_nodes" {
flavor_id = each.value.flavor
key_pair = openstack_compute_keypair_v2.k8s.name
user_data = each.value.cloudinit != null ? templatefile("${path.module}/templates/cloudinit.yaml.tmpl", {
extra_partitions = each.value.cloudinit.extra_partitions
extra_partitions = each.value.cloudinit.extra_partitions,
netplan_critical_dhcp_interface = each.value.cloudinit.netplan_critical_dhcp_interface,
}) : data.cloudinit_config.cloudinit.rendered

dynamic "block_device" {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
%{~ if length(extra_partitions) > 0 }
%{~ if length(extra_partitions) > 0 || netplan_critical_dhcp_interface != "" }
#cloud-config
bootcmd:
%{~ for idx, partition in extra_partitions }
Expand All @@ -8,11 +8,26 @@ bootcmd:
%{~ endfor }

runcmd:
%{~ if netplan_critical_dhcp_interface != "" }
- netplan apply
%{~ endif }
%{~ for idx, partition in extra_partitions }
- mkdir -p ${partition.mount_path}
- chown nobody:nogroup ${partition.mount_path}
- mount ${partition.partition_path} ${partition.mount_path}
%{~ endfor }
%{~ endfor ~}

%{~ if netplan_critical_dhcp_interface != "" }
write_files:
- path: /etc/netplan/90-critical-dhcp.yaml
content: |
network:
version: 2
ethernets:
${ netplan_critical_dhcp_interface }:
dhcp4: true
critical: true
%{~ endif }

mounts:
%{~ for idx, partition in extra_partitions }
Expand Down
5 changes: 3 additions & 2 deletions contrib/terraform/openstack/modules/compute/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,14 @@ variable "k8s_nodes" {
additional_server_groups = optional(list(string))
server_group = optional(string)
cloudinit = optional(object({
extra_partitions = list(object({
extra_partitions = optional(list(object({
volume_path = string
partition_path = string
partition_start = string
partition_end = string
mount_path = string
}))
})), [])
netplan_critical_dhcp_interface = optional(string, "")
}))
}))
}
Expand Down

0 comments on commit d669b93

Please sign in to comment.