Skip to content

Commit 24aaf82

Browse files
committed
feat: Add support for ami AL2023
1 parent fcec146 commit 24aaf82

File tree

5 files changed

+58
-4
lines changed

5 files changed

+58
-4
lines changed

node_group_advanced.tf

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ resource "aws_iam_instance_profile" "quortex" {
6969
data "aws_ami" "eks_worker_image" {
7070
filter {
7171
name = "name"
72-
values = ["amazon-eks-node-al2023-x86_64-standard-${local.kubernetes_worker_nodes_version}-v*"]
72+
values = var.ami_al2023 ? ["amazon-eks-node-al2023-x86_64-standard-${local.kubernetes_worker_nodes_version}-v*"] : ["amazon-eks-node-${local.kubernetes_worker_nodes_version}-v*"]
7373
}
7474
most_recent = true
7575
owners = ["self", "amazon"]
@@ -91,12 +91,41 @@ resource "aws_launch_template" "quortex_launch_tpl" {
9191

9292
update_default_version = true
9393

94-
user_data = base64encode(
94+
user_data = var.ami_al2023 ? base64encode(
9595
templatefile(
96-
"${path.module}/userdata.sh.tpl",
96+
"${path.module}/templates/al2023_user_data.tpl",
97+
{
98+
cluster_name = aws_eks_cluster.quortex.name
99+
cluster_endpoint = aws_eks_cluster.quortex.endpoint
100+
cluster_auth_base64 = aws_eks_cluster.quortex.certificate_authority[0].data
101+
cluster_service_cidr = aws_eks_cluster.quortex.kubernetes_network_config[0].service_ipv4_cidr
102+
discard_unpacked_layers = var.discard_unpacked_layers
103+
# define the k8s node taints (passed to --kubelet-extra-args)
104+
node_taints = length(each.value.taints) == 0 ? "" : join(",", [for k, v in lookup(each.value, "taints", {}) : "${k}=${v}"])
105+
# define the k8s node labels (passed to --kubelet-extra-args)
106+
node_labels = join(
107+
",",
108+
[
109+
for k, v in
110+
merge(
111+
# Built-in labels
112+
{
113+
"eks.amazonaws.com/nodegroup-image" = local.ami_id_worker,
114+
"eks.amazonaws.com/nodegroup" = each.key,
115+
"nodegroup" = each.key
116+
},
117+
# User-specified labels
118+
lookup(each.value, "labels", {}),
119+
)
120+
: "${k}=${v}"]
121+
)
122+
}
123+
)) : base64encode(
124+
templatefile(
125+
"${path.module}/templates/al2_user_data.tpl",
97126
{
98127
warm_pool = lookup(each.value, "warm_pool_enabled", false)
99-
script = templatefile("${path.module}/cluster_connect.sh.tpl",
128+
script = templatefile("${path.module}/templates/cluster_connect.sh.tpl",
100129
{
101130
cluster_name = aws_eks_cluster.quortex.name
102131
base64_cluster_ca = aws_eks_cluster.quortex.certificate_authority[0].data

templates/al2023_user_data.tpl

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
apiVersion: node.eks.aws/v1alpha1
3+
kind: NodeConfig
4+
spec:
5+
cluster:
6+
name: ${cluster_name}
7+
apiServerEndpoint: ${cluster_endpoint}
8+
certificateAuthority: ${cluster_auth_base64}
9+
cidr: ${cluster_service_cidr}
10+
kubelet:
11+
flags:
12+
- --node-labels=${node_labels}
13+
- --register-with-taints=${node_taints}
14+
%{ if discard_unpacked_layers == false }
15+
containerd:
16+
config: |
17+
[plugins."io.containerd.grpc.v1.cri".containerd]
18+
discard_unpacked_layers = false
19+
%{ endif }

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,12 @@ variable "discard_unpacked_layers" {
216216
description = "Set to false to keep unpacked layers on the node after the image is pulled. By default, EKS will clean up the unpacked layers to save disk space."
217217
}
218218

219+
variable "ami_al2023" {
220+
description = "Whether to use Amazon Linux 2023 AMI for worker nodes (only applies to advanced_node_groups)."
221+
type = bool
222+
default = false
223+
}
224+
219225
variable "node_use_max_pods_allowed" {
220226
type = bool
221227
default = false

0 commit comments

Comments
 (0)