Skip to content

Commit 541dbb2

Browse files
feat: Support additional cluster DNS IPs with Bottlerocket based AMIs (#3051)
* Support adding additional cluster dns ranges to bottlerocket template * Add example for multiple dns ips * fmt, and tf docs * fix: Use a list by default for cluster-dns-ip --------- Co-authored-by: Bryant Biggs <[email protected]>
1 parent f90f15e commit 541dbb2

File tree

11 files changed

+30
-10
lines changed

11 files changed

+30
-10
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/antonbabenko/pre-commit-terraform
3-
rev: v1.89.1
3+
rev: v1.90.0
44
hooks:
55
- id: terraform_fmt
66
- id: terraform_docs

examples/user_data/main.tf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ module "eks_mng_bottlerocket_custom_ami" {
244244
cluster_endpoint = local.cluster_endpoint
245245
cluster_auth_base64 = local.cluster_auth_base64
246246
cluster_service_cidr = local.cluster_service_cidr
247+
additional_cluster_dns_ips = [
248+
"169.254.20.10"
249+
]
247250

248251
enable_bootstrap_user_data = true
249252

examples/user_data/rendered/bottlerocket/eks-mng-custom-ami.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cluster-name" = "ex-user-data"
33
"api-server" = "https://012345678903AB2BAE5D1E0BFE0E2B50.gr7.us-east-1.eks.amazonaws.com"
44
"cluster-certificate" = "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUM1ekNDQWMrZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKbXFqQ1VqNGdGR2w3ZW5PeWthWnZ2RjROOTVOUEZCM2o0cGhVZUsrWGFtN2ZSQnZya0d6OGxKZmZEZWF2b2plTwpQK2xOZFlqdHZncmxCUEpYdHZIZmFzTzYxVzdIZmdWQ2EvamdRM2w3RmkvL1dpQmxFOG9oWUZkdWpjc0s1SXM2CnNkbk5KTTNYUWN2TysrSitkV09NT2ZlNzlsSWdncmdQLzgvRU9CYkw3eUY1aU1hS3lsb1RHL1V3TlhPUWt3ZUcKblBNcjdiUmdkQ1NCZTlXYXowOGdGRmlxV2FOditsTDhsODBTdFZLcWVNVlUxbjQyejVwOVpQRTd4T2l6L0xTNQpYV2lXWkVkT3pMN0xBWGVCS2gzdkhnczFxMkI2d1BKZnZnS1NzWllQRGFpZTloT1NNOUJkNFNPY3JrZTRYSVBOCkVvcXVhMlYrUDRlTWJEQzhMUkVWRDdCdVZDdWdMTldWOTBoL3VJUy9WU2VOcEdUOGVScE5DakszSjc2aFlsWm8KWjNGRG5QWUY0MWpWTHhiOXF0U1ROdEp6amYwWXBEYnFWci9xZzNmQWlxbVorMzd3YWM1eHlqMDZ4cmlaRUgzZgpUM002d2lCUEVHYVlGeWN5TmNYTk5aYW9DWDJVL0N1d2JsUHAKLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQ=="
5-
"cluster-dns-ip" = "192.168.0.10"
5+
"cluster-dns-ip" = ["192.168.0.10", "169.254.20.10"]
66
# extra args added
77
[settings.kernel]
88
lockdown = "integrity"

examples/user_data/rendered/bottlerocket/self-mng-bootstrap.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"cluster-name" = "ex-user-data"
33
"api-server" = "https://012345678903AB2BAE5D1E0BFE0E2B50.gr7.us-east-1.eks.amazonaws.com"
44
"cluster-certificate" = "LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUM1ekNDQWMrZ0F3SUJBZ0lCQURBTkJna3Foa2lHOXcwQkFRc0ZBREFWTVJNd0VRWURWUVFERXdwcmRXSmwKbXFqQ1VqNGdGR2w3ZW5PeWthWnZ2RjROOTVOUEZCM2o0cGhVZUsrWGFtN2ZSQnZya0d6OGxKZmZEZWF2b2plTwpQK2xOZFlqdHZncmxCUEpYdHZIZmFzTzYxVzdIZmdWQ2EvamdRM2w3RmkvL1dpQmxFOG9oWUZkdWpjc0s1SXM2CnNkbk5KTTNYUWN2TysrSitkV09NT2ZlNzlsSWdncmdQLzgvRU9CYkw3eUY1aU1hS3lsb1RHL1V3TlhPUWt3ZUcKblBNcjdiUmdkQ1NCZTlXYXowOGdGRmlxV2FOditsTDhsODBTdFZLcWVNVlUxbjQyejVwOVpQRTd4T2l6L0xTNQpYV2lXWkVkT3pMN0xBWGVCS2gzdkhnczFxMkI2d1BKZnZnS1NzWllQRGFpZTloT1NNOUJkNFNPY3JrZTRYSVBOCkVvcXVhMlYrUDRlTWJEQzhMUkVWRDdCdVZDdWdMTldWOTBoL3VJUy9WU2VOcEdUOGVScE5DakszSjc2aFlsWm8KWjNGRG5QWUY0MWpWTHhiOXF0U1ROdEp6amYwWXBEYnFWci9xZzNmQWlxbVorMzd3YWM1eHlqMDZ4cmlaRUgzZgpUM002d2lCUEVHYVlGeWN5TmNYTk5aYW9DWDJVL0N1d2JsUHAKLS0tLS1FTkQgQ0VSVElGSUNBVEUtLS0tLQ=="
5-
"cluster-dns-ip" = "192.168.0.10"
5+
"cluster-dns-ip" = ["192.168.0.10"]
66
# extra args added
77
[settings.kernel]
88
lockdown = "integrity"

modules/_user_data/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ No modules.
3636

3737
| Name | Description | Type | Default | Required |
3838
|------|-------------|------|---------|:--------:|
39+
| <a name="input_additional_cluster_dns_ips"></a> [additional\_cluster\_dns\_ips](#input\_additional\_cluster\_dns\_ips) | Additional DNS IP addresses to use for the cluster. Only used when `ami_type` = `BOTTLEROCKET_*` | `list(string)` | `[]` | no |
3940
| <a name="input_ami_type"></a> [ami\_type](#input\_ami\_type) | Type of Amazon Machine Image (AMI) associated with the EKS Node Group. See the [AWS documentation](https://docs.aws.amazon.com/eks/latest/APIReference/API_Nodegroup.html#AmazonEKS-Type-Nodegroup-amiType) for valid values | `string` | `null` | no |
4041
| <a name="input_bootstrap_extra_args"></a> [bootstrap\_extra\_args](#input\_bootstrap\_extra\_args) | Additional arguments passed to the bootstrap script. When `ami_type` = `BOTTLEROCKET_*`; these are additional [settings](https://github.com/bottlerocket-os/bottlerocket#settings) that are provided to the Bottlerocket user data | `string` | `""` | no |
4142
| <a name="input_cloudinit_post_nodeadm"></a> [cloudinit\_post\_nodeadm](#input\_cloudinit\_post\_nodeadm) | Array of cloud-init document parts that are created after the nodeadm document part | <pre>list(object({<br> content = string<br> content_type = optional(string)<br> filename = optional(string)<br> merge_type = optional(string)<br> }))</pre> | `[]` | no |

modules/_user_data/main.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ locals {
4343
}
4444

4545
cluster_service_cidr = try(coalesce(var.cluster_service_ipv4_cidr, var.cluster_service_cidr), "")
46+
cluster_dns_ips = flatten(concat([try(cidrhost(local.cluster_service_cidr, 10), "")], var.additional_cluster_dns_ips))
4647

4748
user_data = base64encode(templatefile(
4849
coalesce(var.user_data_template_path, local.template_path[local.user_data_type]),
@@ -57,8 +58,9 @@ locals {
5758

5859
cluster_service_cidr = local.cluster_service_cidr
5960
cluster_ip_family = var.cluster_ip_family
61+
6062
# Bottlerocket
61-
cluster_dns_ip = try(cidrhost(local.cluster_service_cidr, 10), "")
63+
cluster_dns_ips = "[${join(", ", formatlist("\"%s\"", local.cluster_dns_ips))}]"
6264

6365
# Optional
6466
bootstrap_extra_args = var.bootstrap_extra_args

modules/_user_data/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ variable "cluster_ip_family" {
5858
default = "ipv4"
5959
}
6060

61+
variable "additional_cluster_dns_ips" {
62+
description = "Additional DNS IP addresses to use for the cluster. Only used when `ami_type` = `BOTTLEROCKET_*`"
63+
type = list(string)
64+
default = []
65+
}
66+
6167
# TODO - remove at next breaking change
6268
variable "cluster_service_ipv4_cidr" {
6369
description = "[Deprecated] The CIDR block to assign Kubernetes service IP addresses from. If you don't specify a block, Kubernetes assigns addresses from either the 10.100.0.0/16 or 172.20.0.0/16 CIDR blocks"

modules/self-managed-node-group/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ module "self_managed_node_group" {
8282

8383
| Name | Description | Type | Default | Required |
8484
|------|-------------|------|---------|:--------:|
85+
| <a name="input_additional_cluster_dns_ips"></a> [additional\_cluster\_dns\_ips](#input\_additional\_cluster\_dns\_ips) | Additional DNS IP addresses to use for the cluster. Only used when `ami_type` = `BOTTLEROCKET_*` | `list(string)` | `[]` | no |
8586
| <a name="input_ami_id"></a> [ami\_id](#input\_ami\_id) | The AMI from which to launch the instance | `string` | `""` | no |
8687
| <a name="input_ami_type"></a> [ami\_type](#input\_ami\_type) | Type of Amazon Machine Image (AMI) associated with the node group. See the [AWS documentation](https://docs.aws.amazon.com/eks/latest/APIReference/API_Nodegroup.html#AmazonEKS-Type-Nodegroup-amiType) for valid values | `string` | `"AL2_x86_64"` | no |
8788
| <a name="input_autoscaling_group_tags"></a> [autoscaling\_group\_tags](#input\_autoscaling\_group\_tags) | A map of additional tags to add to the autoscaling group created. Tags are applied to the autoscaling group only and are NOT propagated to instances | `map(string)` | `{}` | no |

modules/self-managed-node-group/main.tf

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,12 @@ module "user_data" {
6565
ami_type = var.ami_type
6666
is_eks_managed_node_group = false
6767

68-
cluster_name = var.cluster_name
69-
cluster_endpoint = var.cluster_endpoint
70-
cluster_auth_base64 = var.cluster_auth_base64
71-
cluster_ip_family = var.cluster_ip_family
72-
cluster_service_cidr = var.cluster_service_cidr
68+
cluster_name = var.cluster_name
69+
cluster_endpoint = var.cluster_endpoint
70+
cluster_auth_base64 = var.cluster_auth_base64
71+
cluster_ip_family = var.cluster_ip_family
72+
cluster_service_cidr = var.cluster_service_cidr
73+
additional_cluster_dns_ips = var.additional_cluster_dns_ips
7374

7475
enable_bootstrap_user_data = true
7576
pre_bootstrap_user_data = var.pre_bootstrap_user_data

modules/self-managed-node-group/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ variable "cluster_ip_family" {
5050
default = "ipv4"
5151
}
5252

53+
variable "additional_cluster_dns_ips" {
54+
description = "Additional DNS IP addresses to use for the cluster. Only used when `ami_type` = `BOTTLEROCKET_*`"
55+
type = list(string)
56+
default = []
57+
}
58+
5359
variable "pre_bootstrap_user_data" {
5460
description = "User data that is injected into the user data script ahead of the EKS bootstrap script. Not used when `ami_type` = `BOTTLEROCKET_*`"
5561
type = string

0 commit comments

Comments
 (0)