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

Fetch VPC ID from runtime using VPC tags provided via controller flags #3656

Merged

Conversation

jeswinkoshyninan
Copy link
Contributor

@jeswinkoshyninan jeswinkoshyninan commented Apr 22, 2024

Issue

This PR will address the issue raised: #3644

Description

This PR introduces a new runtime argument, aws-vpc-tags which is used to identify VPCs from the list of tags from which we can infer the VPC ID. There is also an optional argument called aws-vpc-name-tag-key incase if the "Name" will not be key-name for the VPC name in tag.

This is useful for cases where access to AWS metadata is blocked and the VPC ID is not known at deploy time, options to infer the VPC ID are limited

Manual Tests Details


Dev Build

➜  ~ kubectl get deploy aws-load-balancer-controller  -n aws-lb-controller -o=jsonpath="{.spec.template.spec.containers[0].args}" 
["--cluster-name=j119106042","--ingress-class=alb","--aws-vpc-tags=Name=j119106042"]%                                                                                                                                                                ➜  ~ 

When I have added the log to display the vpc_id, it got properly fetched the VPC(hidden) based on the given flag --aws-vpc-tags=Name="". 

➜  ~ kubectl logs aws-load-balancer-controller-566f9f556b-dhlbr -n aws-lb-controller 
{"level":"info","ts":"2024-05-09T20:12:03Z","msg":"version","GitVersion":"","GitCommit":"","BuildDate":""}
VPC ID:  vpc-XXXXXXXXXXXX
{"level":"info","ts":"2024-05-09

Current Build

➜  ~ kubectl logs aws-load-balancer-controller-6776c547-7mfj4  -n aws-lb-controller 
{"level":"info","ts":"2024-05-14T10:29:47Z","msg":"version","GitVersion":"","GitCommit":"","BuildDate":""}
{"level":"info","ts":"2024-05-14T10:29:47Z","logger":"controller-runtime.metrics","msg":"Metrics server is starting to listen","addr":":8080"}
{"level":"info","ts":"2024-05-14T10:29:47Z","logger":"setup","msg":"adding health check for controller"}
{"level":"info","ts":"2024-05-14T10:29:47Z","logger":"setup","msg":"adding readiness check for webhook"}
{"level":"info","ts":"2024-05-14T10:29:47Z","logger":"controller-runtime.webhook","msg":"Registering webhook","path":"/mutate-v1-pod"}
{"level":"info","ts":"2024-05-14T10:29:47Z","logger":"controller-runtime.webhook","msg":"Registering webhook","path":"/mutate-v1-service"}
{"level":"info","ts":"2024-05-14T10:29:47Z","logger":"controller-runtime.webhook","msg":"Registering webhook","path":"/validate-elbv2-k8s-aws-v1beta1-ingressclassparams"}
{"level":"info","ts":"2024-05-14T10:29:47Z","logger":"controller-runtime.webhook","msg":"Registering webhook","path":"/mutate-elbv2-k8s-aws-v1beta1-targetgroupbinding"}
{"level":"info","ts":"2024-05-14T10:29:47Z","logger":"controller-runtime.webhook","msg":"Registering webhook","path":"/validate-elbv2-k8s-aws-v1beta1-targetgroupbinding"}
{"level":"info","ts":"2024-05-14T10:29:47Z","logger":"controller-runtime.webhook","msg":"Registering webhook","path":"/validate-networking-v1-ingress"}
{"level":"info","ts":"2024-05-14T10:29:47Z","logger":"setup","msg":"starting podInfo repo"}
{"level":"info","ts":"2024-05-14T10:29:49Z","logger":"controller-runtime.webhook.webhooks","msg":"Starting webhook server"}
{"level":"info","ts":"2024-05-14T10:29:49Z","msg":"Starting server","kind":"health probe","addr":"0.0.0.0:61779"}
{"level":"info","ts":"2024-05-14T10:29:49Z","msg":"Starting server","path":"/metrics","kind":"metrics","addr":"0.0.0.0:8080"}
{"level":"info","ts":"2024-05-14T10:29:49Z","logger":"controller-runtime.certwatcher","msg":"Updated current TLS certificate"}
{"level":"info","ts":"2024-05-14T10:29:49Z","logger":"controller-runtime.certwatcher","msg":"Starting certificate watcher"}
{"level":"info","ts":"2024-05-14T10:29:49Z","logger":"controller-runtime.webhook","msg":"Serving webhook server","host":"","port":9443}

Checklist

  • Added tests that cover your change (if possible)
  • Added/modified documentation as required (such as the README.md, or the docs directory)
  • Manually tested
  • Made sure the title of the PR is a good description that can go into the release notes

BONUS POINTS checklist: complete for good vibes and maybe prizes?! 🤯

  • Backfilled missing tests for code in same general area 🎉
  • Refactored something and made the world a better place 🌟

Copy link

linux-foundation-easycla bot commented Apr 22, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Apr 22, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @jeswinkoshyninan!

It looks like this is your first PR to kubernetes-sigs/aws-load-balancer-controller 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/aws-load-balancer-controller has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Apr 22, 2024
@k8s-ci-robot
Copy link
Contributor

Hi @jeswinkoshyninan. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 22, 2024
@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Apr 22, 2024
@jeswinkoshyninan jeswinkoshyninan changed the title Fetch VPC ID from runtime using VPC flags Fetch VPC ID from runtime using VPC tags provided via controller flags Apr 22, 2024
@jeswinkoshyninan
Copy link
Contributor Author

@oliviassss @johngmyers can you please take look into this same ?

@shraddhabang
Copy link
Collaborator

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 24, 2024
@jeswinkoshyninan
Copy link
Contributor Author

Thank you @shraddhabang , seems like test looks good to us. Can we merge this change?

@jeswinkoshyninan
Copy link
Contributor Author

@shraddhabang @johngmyers @oliviassss tagging again incase if we lost the track of this PR, seems like the tests looks good and okay to merge ?

@oliviassss
Copy link
Collaborator

@jeswinkoshyninan thanks for the contribution, this change looks good to me overall, just a few questions:

  1. iiuc, we are supporting filtering the vpc by tags, it does not have to be "Name". So can we change the flag aws-vpc-name-tag-key to aws-vpc-tag-key to make it more general, and by default it's Name.
  2. I think maybe we need a validation that, if users use both flag --aws-vpc-id and --aws-vpc-tags, the controller should error out. since it should be either specify a vpc-id, or filter by vpc tag.

@jeswinkoshyninan
Copy link
Contributor Author

@oliviassss thank you for the comments
Regarding your first point, I have made the changes and the second point, currently if VPCID is set, then that will be returned instead of fetching VPCID using tags. In this case, is this required to add a condition since this will not cause any problems. Please let me know your thoughts ?

@oliviassss
Copy link
Collaborator

oliviassss commented May 13, 2024

yeah it's not causing any problem, since it's just return the vpc id if specified. But I think we should call out for this behavior:

  1. in docs/deploy/configurations.md, add a call out that --aws-vpc-id will take precedence if both --aws-vpc-id and --aws-vpc-tag are specified.
  2. maybe add a debug log line in the func getVpcID(), if cfg.VpcID != nil, we can log out that vpc-id is specified, and the controller just used it. It should be V(1) log, so only visible when users enable debug log level.

@jeswinkoshyninan
Copy link
Contributor Author

jeswinkoshyninan commented May 13, 2024

@oliviassss make sense, have pushed the changes, please take a look.

| aws-max-retries | int | 10 | Maximum retries for AWS APIs |
| aws-region | string | [instance metadata](#instance-metadata) | AWS Region for the kubernetes cluster |
| aws-vpc-id | string | [instance metadata](#instance-metadata) | AWS VPC ID for the Kubernetes cluster |
| aws-vpc-tags | stringMap | | Tags for the Kubernetes cluster VPC
Copy link
Collaborator

@oliviassss oliviassss May 13, 2024

Choose a reason for hiding this comment

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

Maybe also add a callout here:

Note that if both flags --aws-vpc-id and --aws-vpc-tags are specified, the controller uses the value in --aws-vpc-id to fetch the VPC info and ignores the other flag.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Another question, does it accept multiple key:value pairs for the tags filter?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, it is a string Map. It will accept multiple values.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the details here as well.

@@ -37,7 +37,7 @@ You can set the IMDSv2 as follows:
aws ec2 modify-instance-metadata-options --http-put-response-hop-limit 2 --http-tokens required --region <region> --instance-id <instance-id>
```

Instead of depending on IMDSv2, you can specify the AWS Region and the VPC via the controller flags `--aws-region` and `--aws-vpc-id`.
Instead of depending on IMDSv2, you can specify the AWS Region via the controller flag `--aws-region`, and the AWS VPC via controller flag `--aws-vpc-id` or by specifying vpc tags via the flag `--aws-vpc-tags` and an optional flag `--aws-vpc-tag-key` if you have a different key for the tag other than "Name". Note that if you specify flags `--aws-vpc-id` and `--aws-vpc-tags`, then value given to `--aws-vpc-id` will be taken by controller.
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: reword a bit

Note that if both flags --aws-vpc-id and --aws-vpc-tags are specified, the controller uses the value in --aws-vpc-id to fetch the VPC info and ignores the other flag.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

refactor the sentence. thanks

@oliviassss
Copy link
Collaborator

/ok-to-test
can you also add the manual testing you've done in the PR description? thanks

@jeswinkoshyninan
Copy link
Contributor Author

@oliviassss PR desc updated with the manual test details.

@oliviassss
Copy link
Collaborator

/lgtm
/assign @M00nF1sh

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 14, 2024
@oliviassss oliviassss added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label May 14, 2024
@jeswinkoshyninan
Copy link
Contributor Author

@oliviassss just for transparency, seems like when enabling debug logs, the logs which we set to message user "vpcid is specified" is not working when I am testing. This will not affect the functionality. But just letting you know that I am checking.

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 14, 2024
@jeswinkoshyninan
Copy link
Contributor Author

jeswinkoshyninan commented May 14, 2024

@oliviassss identified the problem with logger and fixed. I can see the logs what we set.

➜  .kube kubectl logs aws-load-balancer-controller-796b7c7f76-wrvdx -n aws-lb-controller -f
{"level":"info","ts":"2024-05-14T21:41:20Z","msg":"version","GitVersion":"","GitCommit":"","BuildDate":""}
{"level":"debug","ts":"2024-05-14T21:41:20Z","msg":"vpcid is specified using flag --aws-vpc-id, controller will use the value","vpc: ":"vpc-XXXXXXXXX"}

@oliviassss
Copy link
Collaborator

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 20, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jeswinkoshyninan, oliviassss

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 20, 2024
@k8s-ci-robot k8s-ci-robot merged commit ea748d0 into kubernetes-sigs:main May 20, 2024
5 checks passed
@oliviassss
Copy link
Collaborator

@jeswinkoshyninan, discussed internally that we will ship this commit in next minor release, which should be v2.9.0, for a feature like this. Thanks for your patience.

@jeswinkoshyninan
Copy link
Contributor Author

@oliviassss thank you for the updates, please let me know once we confirm the release v2.9.0.

}

if cfg.VpcTags != nil {
return inferVPCIDFromTags(ec2Service, cfg.VpcNameTagKey, cfg.VpcTags[cfg.VpcNameTagKey])
Copy link
Contributor

Choose a reason for hiding this comment

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

@jeswinkoshyninan I don't really get this part: why does this allow to pass a map with an arbitrary number of items for --aws-vpc-tags if we only ever pass a single key-value pair (the one with the key specified in aws-vpc-tag-key) as the tag filter? Shouldn't it rather just convert the map from --aws-vpc-tags into a list of tag filters, one for each item?

Choose a reason for hiding this comment

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

Related to #3889

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants