Skip to content

Commit 91fe2ac

Browse files
authored
Merge pull request #1644 from kube-hetzner/staging
Upgrade Networking, Security, and Automation Components
2 parents 8ced266 + 3c77cc9 commit 91fe2ac

File tree

8 files changed

+75
-19
lines changed

8 files changed

+75
-19
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,4 @@ kustomization.yaml
4141
*kustomization_backup.yaml
4242
kube.tf
4343
.terraform.lock.hcl
44+
issue_fix.patch

agents.tf

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,25 @@ module "agents" {
4545
locals {
4646
k3s-agent-config = { for k, v in local.agent_nodes : k => merge(
4747
{
48-
node-name = module.agents[k].name
49-
server = "https://${var.use_control_plane_lb ? hcloud_load_balancer_network.control_plane.*.ip[0] : module.control_planes[keys(module.control_planes)[0]].private_ipv4_address}:6443"
50-
token = local.k3s_token
51-
kubelet-arg = concat(local.kubelet_arg, var.k3s_global_kubelet_args, var.k3s_agent_kubelet_args, v.kubelet_args)
48+
node-name = module.agents[k].name
49+
server = "https://${var.use_control_plane_lb ? hcloud_load_balancer_network.control_plane.*.ip[0] : module.control_planes[keys(module.control_planes)[0]].private_ipv4_address}:6443"
50+
token = local.k3s_token
51+
kubelet-arg = concat(
52+
local.kubelet_arg,
53+
var.k3s_global_kubelet_args,
54+
var.k3s_agent_kubelet_args,
55+
v.kubelet_args
56+
)
5257
flannel-iface = local.flannel_iface
5358
node-ip = module.agents[k].private_ipv4_address
5459
node-label = v.labels
5560
node-taint = v.taints
5661
},
5762
var.agent_nodes_custom_config,
58-
(v.selinux == true ? { selinux = true } : {})
63+
# Force selinux=false if disable_selinux = true.
64+
var.disable_selinux
65+
? { selinux = false }
66+
: (v.selinux == true ? { selinux = true } : {})
5967
) }
6068
}
6169

control_planes.tf

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ resource "hcloud_load_balancer_network" "control_plane" {
6060
load_balancer_id = hcloud_load_balancer.control_plane.*.id[0]
6161
subnet_id = hcloud_network_subnet.control_plane.*.id[0]
6262
enable_public_interface = var.control_plane_lb_enable_public_interface
63-
ip = cidrhost(hcloud_network_subnet.control_plane.*.ip_range[0], 1)
63+
64+
# To ensure backwards compatibility, we ignore changes to the IP address
65+
# as before it was set manually.
66+
lifecycle {
67+
ignore_changes = [ip]
68+
}
6469
}
6570

6671
resource "hcloud_load_balancer_target" "control_plane" {
@@ -103,15 +108,19 @@ locals {
103108
advertise-address = module.control_planes[k].private_ipv4_address
104109
node-label = v.labels
105110
node-taint = v.taints
106-
selinux = true
111+
selinux = var.disable_selinux ? false : (v.selinux == true ? true : false)
107112
cluster-cidr = var.cluster_ipv4_cidr
108113
service-cidr = var.service_ipv4_cidr
109114
cluster-dns = var.cluster_dns_ipv4
110115
write-kubeconfig-mode = "0644" # needed for import into rancher
111116
},
112117
lookup(local.cni_k3s_settings, var.cni_plugin, {}),
113118
var.use_control_plane_lb ? {
114-
tls-san = concat([hcloud_load_balancer.control_plane.*.ipv4[0], hcloud_load_balancer_network.control_plane.*.ip[0]], var.additional_tls_sans)
119+
tls-san = concat([
120+
hcloud_load_balancer.control_plane.*.ipv4[0],
121+
hcloud_load_balancer_network.control_plane.*.ip[0],
122+
var.kubeconfig_server_address != "" ? var.kubeconfig_server_address : null
123+
], var.additional_tls_sans)
115124
} : {
116125
tls-san = concat([
117126
module.control_planes[k].ipv4_address

docs/terraform.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@
116116
| <a name="input_cilium_ipv4_native_routing_cidr"></a> [cilium\_ipv4\_native\_routing\_cidr](#input\_cilium\_ipv4\_native\_routing\_cidr) | Used when Cilium is configured in native routing mode. The CNI assumes that the underlying network stack will forward packets to this destination without the need to apply SNAT. Default: value of "cluster\_ipv4\_cidr" | `string` | `null` | no |
117117
| <a name="input_cilium_routing_mode"></a> [cilium\_routing\_mode](#input\_cilium\_routing\_mode) | Set native-routing mode ("native") or tunneling mode ("tunnel"). | `string` | `"tunnel"` | no |
118118
| <a name="input_cilium_values"></a> [cilium\_values](#input\_cilium\_values) | Additional helm values file to pass to Cilium as 'valuesContent' at the HelmChart. | `string` | `""` | no |
119-
| <a name="input_cilium_version"></a> [cilium\_version](#input\_cilium\_version) | Version of Cilium. See https://github.com/cilium/cilium/releases for the available versions. | `string` | `"1.15.1"` | no |
119+
| <a name="input_cilium_version"></a> [cilium\_version](#input\_cilium\_version) | Version of Cilium. See https://github.com/cilium/cilium/releases for the available versions. | `string` | `"1.17.0"` | no |
120120
| <a name="input_cluster_autoscaler_extra_args"></a> [cluster\_autoscaler\_extra\_args](#input\_cluster\_autoscaler\_extra\_args) | Extra arguments for the Cluster Autoscaler deployment. | `list(string)` | `[]` | no |
121121
| <a name="input_cluster_autoscaler_image"></a> [cluster\_autoscaler\_image](#input\_cluster\_autoscaler\_image) | Image of Kubernetes Cluster Autoscaler for Hetzner Cloud to be used. | `string` | `"registry.k8s.io/autoscaling/cluster-autoscaler"` | no |
122122
| <a name="input_cluster_autoscaler_log_level"></a> [cluster\_autoscaler\_log\_level](#input\_cluster\_autoscaler\_log\_level) | Verbosity level of the logs for cluster-autoscaler | `number` | `4` | no |
123123
| <a name="input_cluster_autoscaler_log_to_stderr"></a> [cluster\_autoscaler\_log\_to\_stderr](#input\_cluster\_autoscaler\_log\_to\_stderr) | Determines whether to log to stderr or not | `bool` | `true` | no |
124124
| <a name="input_cluster_autoscaler_server_creation_timeout"></a> [cluster\_autoscaler\_server\_creation\_timeout](#input\_cluster\_autoscaler\_server\_creation\_timeout) | Timeout (in minutes) until which a newly created server/node has to become available before giving up and destroying it. | `number` | `15` | no |
125125
| <a name="input_cluster_autoscaler_stderr_threshold"></a> [cluster\_autoscaler\_stderr\_threshold](#input\_cluster\_autoscaler\_stderr\_threshold) | Severity level above which logs are sent to stderr instead of stdout | `string` | `"INFO"` | no |
126-
| <a name="input_cluster_autoscaler_version"></a> [cluster\_autoscaler\_version](#input\_cluster\_autoscaler\_version) | Version of Kubernetes Cluster Autoscaler for Hetzner Cloud. Should be aligned with Kubernetes version. Available versions for the official image can be found at https://explore.ggcr.dev/?repo=registry.k8s.io%2Fautoscaling%2Fcluster-autoscaler. | `string` | `"v1.31.5"` | no |
126+
| <a name="input_cluster_autoscaler_version"></a> [cluster\_autoscaler\_version](#input\_cluster\_autoscaler\_version) | Version of Kubernetes Cluster Autoscaler for Hetzner Cloud. Should be aligned with Kubernetes version. Available versions for the official image can be found at https://explore.ggcr.dev/?repo=registry.k8s.io%2Fautoscaling%2Fcluster-autoscaler. | `string` | `"v1.32.0"` | no |
127127
| <a name="input_cluster_dns_ipv4"></a> [cluster\_dns\_ipv4](#input\_cluster\_dns\_ipv4) | Internal Service IPv4 address of core-dns. | `string` | `"10.43.0.10"` | no |
128128
| <a name="input_cluster_ipv4_cidr"></a> [cluster\_ipv4\_cidr](#input\_cluster\_ipv4\_cidr) | Internal Pod CIDR, used for the controller and currently for calico/cilium. | `string` | `"10.42.0.0/16"` | no |
129129
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | Name of the cluster. | `string` | `"k3s"` | no |

init.tf

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,17 +258,13 @@ resource "null_resource" "kustomization" {
258258

259259
# Upload the csi-driver config (ignored if csi is disabled)
260260
provisioner "file" {
261-
content = templatefile(
261+
content = var.disable_hetzner_csi ? "" : templatefile(
262262
"${path.module}/templates/hcloud-csi.yaml.tpl",
263263
{
264-
# local.csi_version is null when disable_hetzner_csi = true
265-
# In that case, we set it to "*" so that the templatefile() can handle it,
266-
# because tempaltefile() does not support null values. Moreover, coalesce() doesn't
267-
# support empty strings either.
268-
# The entire file is ignored by kustomization.yaml anyway if disable_hetzner_csi = true.
269264
version = coalesce(local.csi_version, "*")
270265
values = indent(4, trimspace(local.hetzner_csi_values))
271-
})
266+
}
267+
)
272268
destination = "/var/post_install/hcloud-csi.yaml"
273269
}
274270

locals.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,5 +1055,12 @@ cloudinit_runcmd_common = <<EOT
10551055
10561056
# Cleanup some logs
10571057
- [truncate, '-s', '0', '/var/log/audit/audit.log']
1058+
1059+
# Add logic to truly disable SELinux if disable_selinux = true.
1060+
# We'll do it by appending to cloudinit_runcmd_common.
1061+
%{if var.disable_selinux}
1062+
- [sed, '-i', '-E', 's/^SELINUX=[a-z]+/SELINUX=disabled/', '/etc/selinux/config']
1063+
- [setenforce, '0']
1064+
%{endif}
10581065
EOT
10591066
}

modules/host/main.tf

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,38 @@ WantedBy=multi-user.target
236236

237237
depends_on = [hcloud_server.server]
238238
}
239+
240+
# Resource to toggle transactional-update.timer based on automatically_upgrade_os setting
241+
resource "null_resource" "os_upgrade_toggle" {
242+
triggers = {
243+
os_upgrade_state = var.automatically_upgrade_os ? "enabled" : "disabled"
244+
server_id = hcloud_server.server.id
245+
}
246+
247+
connection {
248+
user = "root"
249+
private_key = var.ssh_private_key
250+
agent_identity = local.ssh_agent_identity
251+
host = hcloud_server.server.ipv4_address
252+
port = var.ssh_port
253+
}
254+
255+
provisioner "remote-exec" {
256+
inline = [
257+
<<-EOT
258+
if [ "${var.automatically_upgrade_os}" = "true" ]; then
259+
echo "automatically_upgrade_os changed to true, enabling transactional-update.timer"
260+
systemctl enable --now transactional-update.timer || true
261+
else
262+
echo "automatically_upgrade_os changed to false, disabling transactional-update.timer"
263+
systemctl disable --now transactional-update.timer || true
264+
fi
265+
EOT
266+
]
267+
}
268+
269+
depends_on = [
270+
hcloud_server.server,
271+
null_resource.registries
272+
]
273+
}

variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ variable "cluster_autoscaler_image" {
278278

279279
variable "cluster_autoscaler_version" {
280280
type = string
281-
default = "v1.31.5"
281+
default = "v1.32.0"
282282
description = "Version of Kubernetes Cluster Autoscaler for Hetzner Cloud. Should be aligned with Kubernetes version. Available versions for the official image can be found at https://explore.ggcr.dev/?repo=registry.k8s.io%2Fautoscaling%2Fcluster-autoscaler."
283283
}
284284

@@ -725,7 +725,7 @@ variable "cilium_values" {
725725

726726
variable "cilium_version" {
727727
type = string
728-
default = "1.15.1"
728+
default = "1.17.0"
729729
description = "Version of Cilium. See https://github.com/cilium/cilium/releases for the available versions."
730730
}
731731

0 commit comments

Comments
 (0)