Skip to content

Commit 48ae23d

Browse files
authored
Merge pull request #1691 from utay/infer-cluster-dns-ipv4
Infer cluster_dns_ipv4 from service_ipv4_cidr
2 parents 9bd4535 + c0064e7 commit 48ae23d

File tree

6 files changed

+14
-12
lines changed

6 files changed

+14
-12
lines changed

control_planes.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ locals {
122122
selinux = var.disable_selinux ? false : (v.selinux == true ? true : false)
123123
cluster-cidr = var.cluster_ipv4_cidr
124124
service-cidr = var.service_ipv4_cidr
125-
cluster-dns = var.cluster_dns_ipv4
125+
cluster-dns = local.cluster_dns_ipv4
126126
write-kubeconfig-mode = "0644" # needed for import into rancher
127127
},
128128
lookup(local.cni_k3s_settings, var.cni_plugin, {}),

docs/terraform.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
| <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 |
127127
| <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 |
128128
| <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 |
129-
| <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 |
129+
| <a name="input_cluster_dns_ipv4"></a> [cluster\_dns\_ipv4](#input\_cluster\_dns\_ipv4) | Internal Service IPv4 address of core-dns. It is automatically inferred from `service_ipv4_cidr` if not explicitly set. | `string` | `null` | no |
130130
| <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 |
131131
| <a name="input_cluster_name"></a> [cluster\_name](#input\_cluster\_name) | Name of the cluster. | `string` | `"k3s"` | no |
132132
| <a name="input_cni_plugin"></a> [cni\_plugin](#input\_cni\_plugin) | CNI plugin for k3s. | `string` | `"flannel"` | no |

init.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ resource "null_resource" "first_control_plane" {
7373
node-label = local.control_plane_nodes[keys(module.control_planes)[0]].labels
7474
cluster-cidr = var.cluster_ipv4_cidr
7575
service-cidr = var.service_ipv4_cidr
76-
cluster-dns = var.cluster_dns_ipv4
76+
cluster-dns = local.cluster_dns_ipv4
7777
},
7878
lookup(local.cni_k3s_settings, var.cni_plugin, {}),
7979
var.use_control_plane_lb ? {

kube.tf.example

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ module "kube-hetzner" {
136136

137137
# Enable automatic backups via Hetzner (default: false)
138138
# backups = true
139-
139+
140140
# To disable public ips (default: false)
141141
# WARNING: If both values are set to "true", your server will only be accessible via a private network. Make sure you have followed
142142
# the instructions regarding this type of setup in README.md: "Use only private IPs in your cluster".
@@ -156,7 +156,7 @@ module "kube-hetzner" {
156156

157157
# Enable automatic backups via Hetzner (default: false)
158158
# backups = true
159-
159+
160160
# To disable public ips (default: false)
161161
# WARNING: If both values are set to "true", your server will only be accessible via a private network. Make sure you have followed
162162
# the instructions regarding this type of setup in README.md: "Use only private IPs in your cluster".
@@ -176,7 +176,7 @@ module "kube-hetzner" {
176176

177177
# Enable automatic backups via Hetzner (default: false)
178178
# backups = true
179-
179+
180180
# To disable public ips (default: false)
181181
# WARNING: If both values are set to "true", your server will only be accessible via a private network. Make sure you have followed
182182
# the instructions regarding this type of setup in README.md: "Use only private IPs in your cluster".
@@ -582,7 +582,7 @@ module "kube-hetzner" {
582582
# Even if patched to remove the "default" label, the local-path storage class will be reset as default on each reboot of
583583
# the node where the controller runs.
584584
# This is not a problem if you explicitly define which storageclass to use in your PVCs.
585-
# Workaround if you don't want two default storage classes: leave this to false and add the local-path-provisioner helm chart
585+
# Workaround if you don't want two default storage classes: leave this to false and add the local-path-provisioner helm chart
586586
# as an extra (https://github.com/kube-hetzner/terraform-hcloud-kube-hetzner#adding-extras).
587587
# enable_local_storage = false
588588

@@ -633,7 +633,7 @@ module "kube-hetzner" {
633633
# Allows you to specify the k3s version. If defined, supersedes initial_k3s_channel.
634634
# See https://github.com/k3s-io/k3s/releases for the available versions.
635635
# install_k3s_version = "v1.30.2+k3s2"
636-
636+
637637
# Allows you to specify either stable, latest, testing or supported minor versions.
638638
# see https://rancher.com/docs/k3s/latest/en/upgrades/basic/ and https://update.k3s.io/v1-release/channels
639639
# ⚠️ If you are going to use Rancher addons for instance, it's always a good idea to fix the kube version to one minor version below the latest stable,
@@ -681,8 +681,8 @@ module "kube-hetzner" {
681681
# "trust anchor --store /root/ca.crt",
682682
# ]
683683

684-
# Structured authentication configuration. Multiple authentication providers support requires v1.30+ of
685-
# kubernetes.
684+
# Structured authentication configuration. Multiple authentication providers support requires v1.30+ of
685+
# kubernetes.
686686
# https://kubernetes.io/docs/reference/access-authn-authz/authentication/#using-authentication-configuration
687687
#
688688
# authentication_config = <<-EOT
@@ -755,7 +755,7 @@ module "kube-hetzner" {
755755
# firewall_ssh_source = ["1.2.3.4/32"]
756756

757757
# By default, SELinux is enabled in enforcing mode on all nodes. For container-specific SELinux issues,
758-
# consider using the pre-installed 'udica' tool to create custom, targeted SELinux policies instead of
758+
# consider using the pre-installed 'udica' tool to create custom, targeted SELinux policies instead of
759759
# disabling SELinux globally. See the "Fix SELinux issues with udica" example in the README for details.
760760
# disable_selinux = false
761761

locals.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ locals {
227227
# The first two subnets are respectively the default subnet 10.0.0.0/16 use for potientially anything and 10.1.0.0/16 used for control plane nodes.
228228
# the rest of the subnets are for agent nodes in each nodepools.
229229
network_ipv4_subnets = [for index in range(256) : cidrsubnet(var.network_ipv4_cidr, 8, index)]
230+
# By convention the DNS service (usually core-dns) is assigned the 10th IP address in the service CIDR block
231+
cluster_dns_ipv4 = var.cluster_dns_ipv4 != null ? var.cluster_dns_ipv4 : cidrhost(var.service_ipv4_cidr, 10)
230232

231233
# if we are in a single cluster config, we use the default klipper lb instead of Hetzner LB
232234
control_plane_count = sum([for v in var.control_plane_nodepools : v.count])

variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ variable "service_ipv4_cidr" {
117117
variable "cluster_dns_ipv4" {
118118
description = "Internal Service IPv4 address of core-dns."
119119
type = string
120-
default = "10.43.0.10"
120+
default = null
121121
}
122122

123123
variable "load_balancer_location" {

0 commit comments

Comments
 (0)