aws-load-balancer-controller icon indicating copy to clipboard operation
aws-load-balancer-controller copied to clipboard

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

Open jeswinkoshyninan opened this issue 1 year ago • 18 comments

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?! :exploding_head:

  • [ ] Backfilled missing tests for code in same general area :tada:
  • [ ] Refactored something and made the world a better place :star2:

jeswinkoshyninan avatar Apr 22 '24 09:04 jeswinkoshyninan

CLA Signed

The committers listed above are authorized under a signed CLA.

  • :white_check_mark: login: jeswinkoshyninan (9d1952597e2b5f53c8ab06fd1783d5cf50192350, 3a0ebcef99c41ed68b20f34d6e570d239d1d86c2, 663315e134c028f6b02b08876a133f314d166970, 69a5d42c2b3acc70788f342216f178d1b4e4427e, 22b2e6b9708057bad6c4ab287c86f6b066df143e, 7b3f80d98ad99f71e388d92ef47e77317b5db4cc, 443d102b64df6a00d9ff48286d093447ebb37127, 8a0147826cc45be2f824dcdbf630ff95ff85408f, e20e081f95c06b7cf7f393a0b7df5afc4f2375c9, 8ae3e3c10ffc5a9c6a22d105ee9bcfdf96838e20)

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. :smiley:

k8s-ci-robot avatar Apr 22 '24 09:04 k8s-ci-robot

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 avatar Apr 22 '24 09:04 k8s-ci-robot

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

jeswinkoshyninan avatar Apr 24 '24 15:04 jeswinkoshyninan

/ok-to-test

shraddhabang avatar Apr 24 '24 22:04 shraddhabang

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

jeswinkoshyninan avatar Apr 25 '24 06:04 jeswinkoshyninan

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

jeswinkoshyninan avatar May 01 '24 22:05 jeswinkoshyninan

@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.

oliviassss avatar May 13 '24 22:05 oliviassss

@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 ?

jeswinkoshyninan avatar May 13 '24 23:05 jeswinkoshyninan

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.

oliviassss avatar May 13 '24 23:05 oliviassss

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

jeswinkoshyninan avatar May 13 '24 23:05 jeswinkoshyninan

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

oliviassss avatar May 13 '24 23:05 oliviassss

@oliviassss PR desc updated with the manual test details.

jeswinkoshyninan avatar May 14 '24 00:05 jeswinkoshyninan

/lgtm /assign @M00nF1sh

oliviassss avatar May 14 '24 18:05 oliviassss

@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.

jeswinkoshyninan avatar May 14 '24 20:05 jeswinkoshyninan

New changes are detected. LGTM label has been removed.

k8s-ci-robot avatar May 14 '24 21:05 k8s-ci-robot

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: jeswinkoshyninan Once this PR has been reviewed and has the lgtm label, please ask for approval from m00nf1sh. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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 avatar May 14 '24 21:05 k8s-ci-robot

@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"}

jeswinkoshyninan avatar May 14 '24 21:05 jeswinkoshyninan

/lgtm /approve

oliviassss avatar May 20 '24 20:05 oliviassss

[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 avatar May 20 '24 20:05 k8s-ci-robot

@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.

oliviassss avatar May 28 '24 20:05 oliviassss

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

jeswinkoshyninan avatar May 29 '24 10:05 jeswinkoshyninan