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: allow eks addons to use pod identity associations #244

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

nitrocode
Copy link
Member

@nitrocode nitrocode commented Nov 17, 2024

what

  • feat: allow eks addons to use pod identity associations

why

  • Option to use a pod identity association instead of an IRSA

references

Summary by CodeRabbit

  • New Features

    • Introduced support for pod identity associations in EKS addons, allowing IAM roles to be linked with Kubernetes service accounts.
    • Added a new optional field for specifying pod identity associations in the configuration.
  • Updates

    • Updated the required version for the AWS provider to ">= 5.75".
  • Deprecation

    • Marked the region variable as obsolete, indicating it is no longer needed for future configurations.

@nitrocode nitrocode requested review from a team as code owners November 17, 2024 00:27
Copy link

coderabbitai bot commented Nov 17, 2024

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes involve updates to the Terraform configuration files for an Amazon EKS cluster. The AWS provider version requirement is increased from ">= 5.74" to ">= 5.75". A new optional field for pod_identity_association is added to the addons variable in variables.tf, allowing for the specification of IAM roles associated with Kubernetes service accounts. Additionally, a dynamic block for pod_identity_association is introduced in the aws_eks_addon resource within main.tf, enhancing its functionality without altering existing resource definitions.

Changes

File Path Change Summary
examples/complete/versions.tf Updated AWS provider version from ">= 5.74" to ">= 5.75".
main.tf Added pod_identity_association attribute and a dynamic block for it in aws_eks_addon.
variables.tf Added optional pod_identity_association field in addons variable; marked region variable as obsolete.
versions.tf Updated AWS provider version constraint from ">= 5.74.0" to ">= 5.75.0".

Poem

In the land of code where the rabbits play,
New versions hop in, brightening the day.
With roles and pods now hand in hand,
Our EKS cluster takes a stand.
So let’s cheer for changes, both big and small,
In the world of Terraform, we’ll conquer all! 🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@mergify mergify bot added the triage Needs triage label Nov 17, 2024
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Reviewing files that changed from the base of the PR and between cf32252 and 2989569.

📒 Files selected for processing (4)
  • examples/complete/versions.tf (1 hunks)
  • main.tf (1 hunks)
  • variables.tf (1 hunks)
  • versions.tf (1 hunks)
🧰 Additional context used
🪛 GitHub Check: terraform-module / CI / Lint (.)
main.tf

[warning] 177-177:
[tflint] reported by reviewdog 🐶
Lookup with 2 arguments is deprecated

Raw Output:
main.tf:177:29: warning: Lookup with 2 arguments is deprecated ()


[warning] 178-178:
[tflint] reported by reviewdog 🐶
Lookup with 2 arguments is deprecated

Raw Output:
main.tf:178:29: warning: Lookup with 2 arguments is deprecated ()

🔇 Additional comments (3)
versions.tf (1)

7-7: Verify minimum version requirement for pod identity associations

The AWS provider version bump appears to be related to supporting pod identity associations in EKS addons.

Let's verify if this is the minimum required version:

examples/complete/versions.tf (1)

7-7: Verify minimum required version for pod identity associations feature.

The AWS provider version bump from 5.74 to 5.75 looks reasonable for a feature addition.

Let's verify if 5.75 is indeed the minimum required version for pod identity associations:

main.tf (1)

171-171: LGTM: Pod identity association attribute added correctly.

The attribute is added with proper null handling for backward compatibility.

Comment on lines +173 to +180
dynamic "pod_identity_association" {
for_each = try(lookup(each.value, "pod_identity_association", null), null) != null ? [true] : []

content {
role_arn = try(lookup(each.value.pod_identity_association, "role_arn"), null)
service_account = try(lookup(each.value.pod_identity_association, "service_account"), null)
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Refactor to address deprecated lookup usage and simplify conditions.

The implementation works but can be improved:

  1. The lookup function with two arguments is deprecated.
  2. The condition and value access can be simplified.

Apply this diff to improve the code:

   dynamic "pod_identity_association" {
-    for_each = try(lookup(each.value, "pod_identity_association", null), null) != null ? [true] : []
+    for_each = try(each.value.pod_identity_association, null) != null ? [true] : []

     content {
-      role_arn        = try(lookup(each.value.pod_identity_association, "role_arn"), null)
-      service_account = try(lookup(each.value.pod_identity_association, "service_account"), null)
+      role_arn        = try(each.value.pod_identity_association.role_arn, null)
+      service_account = try(each.value.pod_identity_association.service_account, null)
     }
   }

The changes:

  • Remove deprecated two-argument lookup usage
  • Simplify attribute access using dot notation
  • Keep the try function for safe access to potentially undefined values
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
dynamic "pod_identity_association" {
for_each = try(lookup(each.value, "pod_identity_association", null), null) != null ? [true] : []
content {
role_arn = try(lookup(each.value.pod_identity_association, "role_arn"), null)
service_account = try(lookup(each.value.pod_identity_association, "service_account"), null)
}
}
dynamic "pod_identity_association" {
for_each = try(each.value.pod_identity_association, null) != null ? [true] : []
content {
role_arn = try(each.value.pod_identity_association.role_arn, null)
service_account = try(each.value.pod_identity_association.service_account, null)
}
}
🧰 Tools
🪛 GitHub Check: terraform-module / CI / Lint (.)

[warning] 177-177:
[tflint] reported by reviewdog 🐶
Lookup with 2 arguments is deprecated

Raw Output:
main.tf:177:29: warning: Lookup with 2 arguments is deprecated ()


[warning] 178-178:
[tflint] reported by reviewdog 🐶
Lookup with 2 arguments is deprecated

Raw Output:
main.tf:178:29: warning: Lookup with 2 arguments is deprecated ()

Comment on lines +171 to +180
pod_identity_association = lookup(each.value, "pod_identity_association", null)

dynamic "pod_identity_association" {
for_each = try(lookup(each.value, "pod_identity_association", null), null) != null ? [true] : []

content {
role_arn = try(lookup(each.value.pod_identity_association, "role_arn"), null)
service_account = try(lookup(each.value.pod_identity_association, "service_account"), null)
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Based on the results, I can now generate the final response:

Documentation needed for pod identity association feature

The implementation is functionally correct with proper AWS provider version (>= 5.75.0) support, but requires documentation updates:

  • The pod identity association feature is not documented in the README.md
  • The feature should be documented with:
    • Description of the feature and its purpose
    • Example usage showing the pod_identity_association configuration
    • Any prerequisites or limitations
🔗 Analysis chain

Implementation aligns with PR objectives.

The changes successfully add support for pod identity associations in EKS addons while maintaining backward compatibility. This provides users with an alternative to IRSA as intended.

A few points to verify:

  1. Ensure the AWS provider version (>= 5.75) supports this feature
  2. Consider documenting the new feature in the module's README

Let me check the README content to ensure we have proper documentation for this feature.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify AWS provider version and documentation

# Check if README exists and contains pod identity documentation
fd -t f "README.md" -x grep -l "pod_identity_association"

# Check provider version constraints
fd -t f "versions.tf" -x grep -A 5 "aws"

Length of output: 606


Script:

#!/bin/bash
# Get full content of README.md to check for documentation
fd -t f "README.md" -x cat {}

# Also check for any existing examples that might need updates
fd -t f -e tf "examples" -x grep -l "addon"

Length of output: 54903

🧰 Tools
🪛 GitHub Check: terraform-module / CI / Lint (.)

[warning] 177-177:
[tflint] reported by reviewdog 🐶
Lookup with 2 arguments is deprecated

Raw Output:
main.tf:177:29: warning: Lookup with 2 arguments is deprecated ()


[warning] 178-178:
[tflint] reported by reviewdog 🐶
Lookup with 2 arguments is deprecated

Raw Output:
main.tf:178:29: warning: Lookup with 2 arguments is deprecated ()

Comment on lines +177 to +180
pod_identity_association = optional(object({
role_arn = string
service_account = string
}))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

LGTM! Consider adding validation and improving documentation.

The implementation of pod_identity_association is well-structured and maintains backward compatibility. A few suggestions for enhancement:

  1. Add validation for the role_arn format to ensure it's a valid IAM role ARN
  2. Enhance the variable description to include details about pod identity associations

Consider adding these enhancements:

 pod_identity_association = optional(object({
   role_arn        = string
   service_account = string
-}))
+}), {
+  validation {
+    condition     = can(regex("^arn:aws:iam::[0-9]{12}:role/.+", var.role_arn))
+    error_message = "The role_arn value must be a valid IAM role ARN."
+  }
+})

Update the description field to include:

 description = <<-EOT
   Manages [`aws_eks_addon`](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/eks_addon) resources.
   Note: `resolve_conflicts` is deprecated. If `resolve_conflicts` is set and
   `resolve_conflicts_on_create` or `resolve_conflicts_on_update` is not set,
   `resolve_conflicts` will be used instead. If `resolve_conflicts_on_create` is
   not set and `resolve_conflicts` is `PRESERVE`, `resolve_conflicts_on_create`
   will be set to `NONE`.
+
+  The `pod_identity_association` block allows you to configure pod identity associations
+  for EKS addons as an alternative to IAM Roles for Service Accounts (IRSA).
+  This enables more flexible identity management for pods running EKS addons.
 EOT

Committable suggestion skipped: line range outside the PR's diff.

@z0rc
Copy link
Contributor

z0rc commented Nov 26, 2024

hashicorp/terraform-provider-aws#30645

Linked issue can block migration of existing addons from IRSA to Pod Identity. I support this PR, but migration path, that it opens, might not be usable by end users as of now. Either documentation is needed or wait for until mentioned issue is resolved.

@nitrocode nitrocode marked this pull request as draft November 26, 2024 16:05
@nitrocode
Copy link
Member Author

I changed it to a draft for now.

I figured if the new optional argument defaulted to null then it wouldn't cause issues with existing addons, so new addons would be able to take advantage.

versions.tf Outdated Show resolved Hide resolved
examples/complete/versions.tf Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage Needs triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants