Skip to content

Commit

Permalink
Merge pull request #18 from RADAR-base/ng-name
Browse files Browse the repository at this point in the history
Enrich node group names with the cluster name
  • Loading branch information
baixiac authored May 30, 2024
2 parents 1d1ff0b + 54f862d commit 5283eee
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
4 changes: 2 additions & 2 deletions cluster/eks.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ module "ebs_csi_irsa" {

locals {
dmz_node_group = {
dmz = {
"dmz-${var.eks_cluster_name}" = {
desired_size = var.dmz_node_size["desired"]
min_size = var.dmz_node_size["min"]
max_size = var.dmz_node_size["max"]
Expand Down Expand Up @@ -70,7 +70,7 @@ locals {
}

worker_node_group = {
worker = {
"worker-${var.eks_cluster_name}" = {
desired_size = var.worker_node_size["desired"]
min_size = var.worker_node_size["min"]
max_size = var.worker_node_size["max"]
Expand Down
4 changes: 2 additions & 2 deletions cluster/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ output "radar_base_eks_cluser_endpoint" {
}

output "radar_base_eks_dmz_node_group_name" {
value = var.create_dmz_node_group ? element(split(":", module.eks.eks_managed_node_groups.dmz.node_group_id), 1) : null
value = var.create_dmz_node_group ? element(split(":", module.eks.eks_managed_node_groups["dmz-${var.eks_cluster_name}"].node_group_id), 1) : null
}

output "radar_base_eks_worker_node_group_name" {
value = element(split(":", module.eks.eks_managed_node_groups.worker.node_group_id), 1)
value = element(split(":", module.eks.eks_managed_node_groups["worker-${var.eks_cluster_name}"].node_group_id), 1)
}

output "radar_base_vpc_public_subnets" {
Expand Down
22 changes: 11 additions & 11 deletions config/data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,15 @@ data "aws_eks_cluster_auth" "main" {
name = var.eks_cluster_name
}

data "aws_autoscaling_groups" "main" {
filter {
name = "tag:eks:cluster-name"
values = [var.eks_cluster_name]
}
data "aws_eks_node_groups" "main" {
cluster_name = var.eks_cluster_name
}

data "aws_eks_node_group" "worker" {
cluster_name = var.eks_cluster_name
node_group_name = join("-", [
element(split("-", [for asg in data.aws_autoscaling_groups.main.names : asg if startswith(asg, "eks-worker-")][0]), 1),
element(split("-", [for asg in data.aws_autoscaling_groups.main.names : asg if startswith(asg, "eks-worker-")][0]), 2),
]) # This is really hacky and there's gonna be a better way of extracting this.
data "aws_eks_node_group" "main" {
for_each = data.aws_eks_node_groups.main.names

cluster_name = var.eks_cluster_name
node_group_name = each.value
}

locals {
Expand All @@ -83,4 +79,8 @@ locals {
"s3",
]

worker_node_group = [
for name in keys(data.aws_eks_node_group.main) : data.aws_eks_node_group.main[name] if startswith(name, "worker-${var.eks_cluster_name}-")
][0] # There is only one worker node group so be this

}
2 changes: 1 addition & 1 deletion config/karpenter.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module "karpenter" {
irsa_namespace_service_accounts = ["karpenter:karpenter"]

create_iam_role = false
iam_role_arn = data.aws_eks_node_group.worker.node_role_arn
iam_role_arn = local.worker_node_group.node_role_arn

tags = merge(tomap({ "Name" : "${var.eks_cluster_name}-karpenter" }), var.common_tags)
}
Expand Down

0 comments on commit 5283eee

Please sign in to comment.