- Notifications
You must be signed in to change notification settings - Fork 1.6k
Add TG protocol into TGB #4282
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
Add TG protocol into TGB #4282
Conversation
| [APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: zac-nixon 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 |
138547f to 9e79346 Compare | "sigs.k8s.io/aws-load-balancer-controller/pkg/gateway/routeutils" | ||
| "sigs.k8s.io/aws-load-balancer-controller/pkg/model/core" | ||
| elbv2model "sigs.k8s.io/aws-load-balancer-controller/pkg/model/elbv2" | ||
| "sigs.k8s.io/aws-load-balancer-controller/pkg/model/elbv2/k8s" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's make this consistent: sigs.k8s.io/aws-load-balancer-controller/pkg/model/elbv2/k8s i saw it was used as elbv2model, k8s2 and k8s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good. i was getting confused about the various names assigned. :)
| func (m *targetGroupBindingMutator) getVpcIDFromAWS(ctx context.Context, tgb *elbv2api.TargetGroupBinding) (string, error) { | ||
| targetGroup, err := getTargetGroupFromAWS(ctx, m.elbv2Client, tgb) | ||
| func (m *targetGroupBindingMutator) getVpcIDFromAWS(tgCache func() tgCacheObject) (string, error) { | ||
| obj := tgCache() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like for all getXXXFromAWS functions, we are doing
obj := tgCache() targetGroup := obj.tg err := obj.error if err != nil { return "", err } then maybe instead of pass in tgCache func() tgCacheObject, can we check error right after
targetGroupCache := sync.OnceValue(func() tgCacheObject { targetGroup, err := getTargetGroupFromAWS(ctx, m.elbv2Client, tgb) return tgCacheObject{ tg: targetGroup, error: err, } }) and then pass targerGroup: tgCache().tg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the idea was that we only want to call at most one time. in the current setup we only call getTargetGroupFromAWS when we need to, which means we need to have each invocation be prepared to handle an error. it sounds like your suggestion would be to just call getTargetGroupFromAWS and pass the value around?
lmk if i misunderstood.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for functions getVpcIDFromAWS, getTargetGroupIPAddressTypeFromAWS, obtainSDKTargetGroupProtocolFromAWS etc, this part of code is in all of them
obj := tgCache() targetGroup := obj.tg err := obj.error if err != nil { return "", err } because we passed targetGroupCache in m.defaultingIPAddressType(tgb, targetGroupCache), i am thinking if we can check cache error before calling all those m.defaultXXXX functions and just pass m.defaultingIPAddressType(tgb, targetGroupCache.tg)
in this way, we only need to check err once and remove duplicated codes, let me know if this applies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah ok. i did understand what you were saying. I don't think we can do that, if we want to maintain the minimum amount of calls.
We only want to fetch the Target Group if we need to, so in this case we need each function to handle the error. For example, we might not need to fetch the TG prior to validating the TG VPC, if that call fails we need to have error handling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh i see your point now, thanks
9e79346 to b61ebc6 Compare | /lgtm |
| /approved |
| /lgtm |
| /retest |
Description
Adds TG protocol in TGB for an upcoming project. Also refactors the webhook logic to only look up TG once per invocation, previously we would re-fetch the TG from ELB for every validation.
Scenarios tested:
Deploy new LBC, don't update TGB CRD.
Deploy old LBC, update TGB CRD.
Deploy new LBC, update TGB CRD.
Checklist
README.md, or thedocsdirectory)BONUS POINTS checklist: complete for good vibes and maybe prizes?! 🤯