Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add irsa_tag_values variable #2584

Merged
merged 2 commits into from
May 17, 2023

Conversation

tongueroo
Copy link
Contributor

Description

Describe your changes in detail

Add irsa_tag_values variable for more control over the generated IAM policy.

Motivation and Context

Why is this change required? What problem does it solve?

This allows karpenter to be used in a setup where the EKS cluster and VPC subnets do not have matching karpenter.sh/discovery tags. An example is using an existing VPC and launching multiple EKS clusters for testing with the same VPC.

Currently, the KarpenterIRSA-* IAM role creates an IAM policy that contains a IAM permission that restricts ec2:RunInstances, ec2:TerminateInstances, ec2:DeleteLaunchTemplates to restrict based on karpenter.sh/discovery": "${CLUSTER_NAME}", something like this:

        {
            "Action": [
                "ec2:TerminateInstances",
                "ec2:DeleteLaunchTemplate"
            ],
            "Condition": {
                "StringEquals": {
                    "ec2:ResourceTag/karpenter.sh/discovery": "${CLUSTER_NAME}"
                }
            },
            "Effect": "Allow",
            "Resource": "*",
            "Sid": ""
        },
        {
            "Action": "ec2:RunInstances",
            "Condition": {
                "StringEquals": {
                    "ec2:ResourceTag/karpenter.sh/discovery": "${CLUSTER_NAME}"
                }
            },
            "Effect": "Allow",
            "Resource": "arn:aws:ec2:*:11111111111:launch-template/*",
            "Sid": ""
        },

Source:

statement {
actions = [
"ec2:TerminateInstances",
"ec2:DeleteLaunchTemplate",
]
resources = ["*"]
condition {
test = "StringEquals"
variable = "ec2:ResourceTag/${var.irsa_tag_key}"
values = [var.cluster_name]
}
}
statement {
actions = ["ec2:RunInstances"]
resources = [
"arn:${local.partition}:ec2:*:${local.account_id}:launch-template/*",
]
condition {
test = "StringEquals"
variable = "ec2:ResourceTag/${var.irsa_tag_key}"
values = [var.cluster_name]
}
}

So we cannot use an existing VPC with an existing subnet tag. IE: We cannot use VPC with subnet tags karpenter.sh/discovery=my-subnet-tag with multiple EKS clusters. Karpenter isn't permitted to successfully launch new nodes, due to the IAM permission assumption.

If it fixes an open issue, please link to the issue here.

Searched and did not find related issues.

Breaking Changes

Does this break backwards compatibility with the current major version?

Nope

How Has This Been Tested?

  • I have updated at least one of the examples/* to demonstrate and validate my change(s)
  • I have tested and validated these changes using one or more of the provided examples/* projects

Ran the examples/karpenter and confirmed it works as a regression test.

Please describe how you tested your changes

Tested with an existing VPC with existing subnet tags, deployed EKS cluster, and deployed karpenter. Something like this:

module "karpenter" {
  source = "/path/to/modules/eks/modules/karpenter"

  cluster_name           = module.eks.cluster_name
  irsa_oidc_provider_arn = module.eks.oidc_provider_arn

  # Set new variable
  irsa_tag_values = ["my-subnet-tag"]
}

Scaled up a deployment to trigger Karpenter to add nodes. Confirmed that the nodes register successfully.

  • I have executed pre-commit run -a on my pull request
Click to see pre-commit run -a results:
$ pre-commit run -a
Terraform fmt............................................................Passed
Terraform validate.......................................................Passed
Terraform docs...........................................................Passed
Terraform validate with tflint...........................................Passed
check for merge conflicts................................................Passed
fix end of files.........................................................Passed

@tongueroo tongueroo changed the title add irsa_tag_values variable feat: add irsa_tag_values variable Apr 20, 2023
@tongueroo tongueroo changed the title feat: add irsa_tag_values variable feat: Add irsa_tag_values variable Apr 20, 2023
@bryantbiggs bryantbiggs merged commit aa3bdf1 into terraform-aws-modules:master May 17, 2023
18 checks passed
antonbabenko pushed a commit that referenced this pull request May 17, 2023
## [19.14.0](v19.13.1...v19.14.0) (2023-05-17)

### Features

* Add irsa_tag_values variable ([#2584](#2584)) ([aa3bdf1](aa3bdf1))
@antonbabenko
Copy link
Member

This PR is included in version 19.14.0 🎉

@github-actions
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants