Skip to content

Commit fcb4256

Browse files
tculpbryantbiggs
andauthored
docs: Re-add 'Tags for the ASG to support cluster-autoscaler scale up from 0' example (#2494)
Co-authored-by: Bryant Biggs <[email protected]>
1 parent 703a76b commit fcb4256

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

examples/eks_managed_node_group/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Note that this example may create resources which cost money. Run `terraform des
5353

5454
| Name | Type |
5555
|------|------|
56+
| [aws_autoscaling_group_tag.cluster_autoscaler_label_tags](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/autoscaling_group_tag) | resource |
5657
| [aws_iam_policy.node_additional](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
5758
| [aws_security_group.remote_access](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group) | resource |
5859
| [aws_ami.eks_default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami) | data source |

examples/eks_managed_node_group/main.tf

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,3 +462,52 @@ data "aws_ami" "eks_default_bottlerocket" {
462462
values = ["bottlerocket-aws-k8s-${local.cluster_version}-x86_64-*"]
463463
}
464464
}
465+
466+
################################################################################
467+
# Tags for the ASG to support cluster-autoscaler scale up from 0
468+
################################################################################
469+
470+
locals {
471+
472+
# We need to lookup K8s taint effect from the AWS API value
473+
taint_effects = {
474+
NO_SCHEDULE = "NoSchedule"
475+
NO_EXECUTE = "NoExecute"
476+
PREFER_NO_SCHEDULE = "PreferNoSchedule"
477+
}
478+
479+
cluster_autoscaler_label_tags = merge([
480+
for name, group in module.eks.eks_managed_node_groups : {
481+
for label_name, label_value in coalesce(group.node_group_labels, {}) : "${name}|label|${label_name}" => {
482+
autoscaling_group = group.node_group_autoscaling_group_names[0],
483+
key = "k8s.io/cluster-autoscaler/node-template/label/${label_name}",
484+
value = label_value,
485+
}
486+
}
487+
]...)
488+
489+
cluster_autoscaler_taint_tags = merge([
490+
for name, group in module.eks.eks_managed_node_groups : {
491+
for taint in coalesce(group.node_group_taints, []) : "${name}|taint|${taint.key}" => {
492+
autoscaling_group = group.node_group_autoscaling_group_names[0],
493+
key = "k8s.io/cluster-autoscaler/node-template/taint/${taint.key}"
494+
value = "${taint.value}:${local.taint_effects[taint.effect]}"
495+
}
496+
}
497+
]...)
498+
499+
cluster_autoscaler_asg_tags = merge(local.cluster_autoscaler_label_tags, local.cluster_autoscaler_taint_tags)
500+
}
501+
502+
resource "aws_autoscaling_group_tag" "cluster_autoscaler_label_tags" {
503+
for_each = local.cluster_autoscaler_asg_tags
504+
505+
autoscaling_group_name = each.value.autoscaling_group
506+
507+
tag {
508+
key = each.value.key
509+
value = each.value.value
510+
511+
propagate_at_launch = false
512+
}
513+
}

0 commit comments

Comments
 (0)