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

Set up pod identity association in E2E tests #329

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

junpengdev
Copy link
Contributor

Issue #, if available:
This is part 2 of setting up E2E tests for pod identity. Part 1 PR

Description of changes:
This PR covers pod identity association setup.

(Since this PR already contains enough changes, I will create another PR to actually deploy pods and verify EKS Pod Identity volume is correctly attached.)

I followed this public document to set up pod identity association.

In summary, the following is required in order to set up pod identity association.

  1. Create IAM role with trust relationship for Pod Identity role. The role should also be able to access some AWS resource.
  2. Create a service account dedicated for Pod Identity
  3. Associate the IAM role to the service account

The creation of service account and pod identity association can only be done after the EKS cluster is provisioned successfully. We can put this into either

  1. the creation of Pod Identity add-on, or
  2. during the add-on e2e tests.

Here I choose to put it into creation of pod identity add-on. The reason for it is we don't need to check or set up this association in every OS/auth provider combination. It should be a one-time setup for the whole EKS cluster.


The creation of IAM role of pod identity can be put into

  1. nodeadm-stack.ts to provision one IAM role for all kube/CNI combination
  2. setup-cfn.yaml to provision one IAM role for all OS/Auth provider under one kube/CNI combination
  3. during e2e test to check or provision one IAM role for each OS/Auth provider

Option 3 is not applicable for two reasons.

  • pod identity association is now done during creation of the add-on, which requires IAM ARN to complete the process
  • it's very inefficient to check/provision the IAM role for each OS/Auth provider

Option 1 and 2 are both working but I choose option 2 because it makes more sense as the role is tied to one cluster, which the lifecycle is managed by CloudFormation.


Testing (if applicable):

  1. Run e2e test locally
  2. Deploy the change to personal dev stack in CodePipeline

Documentation added/planned (if applicable):

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@junpengdev junpengdev requested review from g-gaston and jaxesn January 29, 2025 23:19
podIdentityAddon := Addon{
Name: podIdentityAgent,
Cluster: v.Cluster,
podIdentityAddon := PodIdentityAddon{
Copy link
Member

Choose a reason for hiding this comment

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

can this just be a Addon instead?
it seems like we don't need the pod identity struct since we only want to wait until it's active?

Comment on lines +41 to +42
var err error
if err = podIdentityAddon.WaitUtilActive(timeoutCtx, v.EKSClient, v.Logger); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

curious why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is to ensure the add-on is in Active state.

return fmt.Errorf("creating kubernetes client: %w", err)
}

podIdentityAddon := addon.PodIdentityAddon{
Copy link
Member

Choose a reason for hiding this comment

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

could we have a constructor for this?

I'm not against creating this "service" objects with a struct directly, but in this case it seems like to do so we have to reveal a lot of the internal details: the fact that wraps an Addon, the name of the add-on, the configuration... It appears that those details could be hidden in a constructor so they remain internal to the addon package.

}

err = podIdentityAddon.Create(ctx, c.eks, c.logger)
if err != nil && !errors.IsType(err, &types.ResourceInUseException{}) {
Copy link
Member

Choose a reason for hiding this comment

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

aren't you handling that error now in the Create method itself? it does seem like it's a good thing to hide if the intent is to make the create operation idempotent


func NewServiceAccount(ctx context.Context, logger logr.Logger, k8s *kubernetes.Clientset, namespace, name string) error {
if _, err := k8s.CoreV1().ServiceAccounts(namespace).Get(ctx, name, metav1.GetOptions{}); err == nil {
logger.Info("Service account has already been created", "namespace", namespace, name)
Copy link
Member

Choose a reason for hiding this comment

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

super nit

Suggested change
logger.Info("Service account has already been created", "namespace", namespace, name)
logger.Info("Service account already exists", "namespace", namespace, "name", name)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants