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

Target groups can now also be specified by Name #2655

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

Conversation

marcosdiez
Copy link
Contributor

@marcosdiez marcosdiez commented May 23, 2022

Issue

Partially solves #2373

Description

On TargetGroupBinding one can now choose a target group by it's name, using the targetGroupName field.

Example

---
apiVersion: elbv2.k8s.aws/v1beta1
kind: TargetGroupBinding
metadata:
  name: mdiezalbtest2
  namespace: default
spec:
  ipAddressType: ipv4
  serviceRef:
    name: mdiezalbtest
    port: 8080
  targetGroupName: mdiezalbtest-tg

Implementation detail:

All I did was to make the field targetGroupName valid, make targetGroupARN non mandatory and intercept MutateCreate and checkRequiredFields, so that if targetGroupARN is empty and targetGroupName is provided, AWS is queried for the ARN.

As a future PR, I could from time to time check if a new target group with targetGroupName was created and later bind it.

One can currently test this using the following container: marcosdiez/aws-alb-ingress-controller:20220524-1006

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 🌟

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 23, 2022
@k8s-ci-robot
Copy link
Contributor

Hi @marcosdiez. 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/M Denotes a PR that changes 30-99 lines, ignoring generated files. label May 23, 2022
@codecov-commenter
Copy link

codecov-commenter commented May 23, 2022

Codecov Report

Base: 54.07% // Head: 54.07% // Decreases project coverage by -0.00% ⚠️

Coverage data is based on head (0efe885) compared to base (a92e689).
Patch coverage: 55.55% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2655      +/-   ##
==========================================
- Coverage   54.07%   54.07%   -0.01%     
==========================================
  Files         144      144              
  Lines        8301     8335      +34     
==========================================
+ Hits         4489     4507      +18     
- Misses       3484     3492       +8     
- Partials      328      336       +8     
Impacted Files Coverage Δ
webhooks/elbv2/targetgroupbinding_mutator.go 66.23% <44.44%> (-6.65%) ⬇️
webhooks/elbv2/targetgroupbinding_validator.go 73.00% <66.66%> (-2.00%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels May 23, 2022
@marcosdiez
Copy link
Contributor Author

Hello @M00nF1sh ! Could you please take a look at this PR ?

@mdiez-modus
Copy link

@M00nF1sh don't forget me!

@marcosdiez
Copy link
Contributor Author

@kishorj could you please take a look at this PR ?

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 12, 2023
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 12, 2023
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Apr 12, 2023
@marcosdiez
Copy link
Contributor Author

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Apr 12, 2023
@ivankatliarchuk
Copy link

Would it be possible to review this MR?

@ivankatliarchuk
Copy link

@kishorj when you have a capacity, would you be able to review this MR and share your feedback please?

Copy link
Contributor

@johngmyers johngmyers left a comment

Choose a reason for hiding this comment

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

I think there needs to be some backstop check for an empty ARN in the main controller, in case the mutating webhook was somehow bypassed.


## Sample YAML
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this deletion intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi! This line wasn't really deleted. It changed to ## Sample YAMLs (plural) and moved about 10 lines above :)

Comment on lines 85 to 103
} else if tgb.Spec.TargetGroupName != "" {
tgObj, err := v.getTargetGroupsByNameFromAWS(ctx, tgb.Spec.TargetGroupName)
if err != nil {
return errors.Errorf("Can't locate TargetGroup with name %s", tgb.Spec.TargetGroupName)
}
tgb.Spec.TargetGroupARN = *tgObj.TargetGroupArn
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the purpose of this code? The validator can't mutate.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The purpose of this code is to guarantee that the either the ARN of the TargetGroup exists or it's possible to infer the ARN by the name of the TargetGroup (since it's unique).

And even though the validator can't mutate, I added tgb.Spec.TargetGroupARN = *tgObj.TargetGroupArn to guarantee the object is in a consistent state though the rest of the process.

The whole code of aws-load-balancer-controller was written assuming there is an ARN. By changing the object here I guarantee as early as possible that that assumption is true.

Copy link
Contributor

Choose a reason for hiding this comment

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

A comment to that effect would be helpful.

Choose a reason for hiding this comment

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

Done

@ivankatliarchuk
Copy link

ivankatliarchuk commented Aug 26, 2023

Hi, @marcosdiez do you have the capacity to add suggested changes and update MR?

@@ -37,6 +37,12 @@ func (m *targetGroupBindingMutator) Prototype(_ admission.Request) (runtime.Obje

func (m *targetGroupBindingMutator) MutateCreate(ctx context.Context, obj runtime.Object) (runtime.Object, error) {
tgb := obj.(*elbv2api.TargetGroupBinding)
if tgb.Spec.TargetGroupARN == "" && tgb.Spec.TargetGroupName == "" {
return nil, errors.Errorf("You must provide either TargetGroupARN or TargetGroupName")
Copy link
Contributor

Choose a reason for hiding this comment

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

Error messages should not start with upper case.

Suggested change
return nil, errors.Errorf("You must provide either TargetGroupARN or TargetGroupName")
return nil, errors.Errorf("must provide either TargetGroupARN or TargetGroupName")

Choose a reason for hiding this comment

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

Done

IPAddressType: &targetGroupIPAddressTypeIPv4,
},
},
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Add tests for likely error cases.

} else if tgb.Spec.TargetGroupName != "" {
tgObj, err := v.getTargetGroupsByNameFromAWS(ctx, tgb.Spec.TargetGroupName)
if err != nil {
return errors.Errorf("Can't locate TargetGroup with name %s", tgb.Spec.TargetGroupName)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return errors.Errorf("Can't locate TargetGroup with name %s", tgb.Spec.TargetGroupName)
return fmt.Errorf("searching TargetGroup with name %s: %w", tgb.Spec.TargetGroupName, err)

Choose a reason for hiding this comment

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

Done

return nil, err
}
if len(tgList) != 1 {
return nil, errors.Errorf("expecting a single targetGroup with name [%s] but got %v", tgName, len(tgList))
Copy link
Contributor

Choose a reason for hiding this comment

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

The caller also includes the desired tgName, so consider removing that from this message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If one needs to read logs, one is usually not having a good day. More info means more helpful logs. I believe we should keep that. It's not sensitive at all.

Copy link
Contributor

Choose a reason for hiding this comment

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

Duplicating the same information in a single log line is not more helpful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, why am I duplicating the same information in a single log line ? tgName != len(tgList)

Comment on lines 85 to 103
} else if tgb.Spec.TargetGroupName != "" {
tgObj, err := v.getTargetGroupsByNameFromAWS(ctx, tgb.Spec.TargetGroupName)
if err != nil {
return errors.Errorf("Can't locate TargetGroup with name %s", tgb.Spec.TargetGroupName)
}
tgb.Spec.TargetGroupARN = *tgObj.TargetGroupArn
Copy link
Contributor

Choose a reason for hiding this comment

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

A comment to that effect would be helpful.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 2, 2023
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Oct 2, 2023
@lukaspj
Copy link

lukaspj commented Jan 14, 2024

Hi,
What is missing on this end?

We would very much like not having to depend on the full Target Group ARN because it is not deterministic so it requires a certain amount of handover from our Terraform-based IaC to the in-cluster reconciliation.

If this was implemented, we can make assumptions on how to identify the Target Group, helping us to decouple the two reconciliation engines.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: marcosdiez
Once this PR has been reviewed and has the lgtm label, please assign johngmyers for approval. 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 k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 7, 2024
@ivankatliarchuk
Copy link

Any chance to release it as experimental feature. Buy that time the community could provide feedback. And for sure we could fix the bugs if any. This mr is already 2 years old.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 23, 2024
@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

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-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jun 21, 2024
@marcosdiez
Copy link
Contributor Author

/remove-lifecycle stale

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jun 21, 2024
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Sep 19, 2024
@stavvy-cgill
Copy link

stavvy-cgill commented Sep 30, 2024

Any update on this MR? It would make it significantly easier to integrate our GitOps with our IaC. Would love to see it officially supported rather than needing suboptimal workarounds to achieve the same end.

@fatmcgav
Copy link

I've refreshed this PR in #3903... 🤞 that will gain some traction...

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle rotten
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Nov 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants