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
feat: support load balancer choosing logic for multi-slb #4075
feat: support load balancer choosing logic for multi-slb #4075
Conversation
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: nilo19 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 |
✅ Deploy Preview for kubernetes-sigs-cloud-provide-azure canceled.
|
f565268
to
915b5ea
Compare
@@ -142,3 +142,17 @@ func expectAttributeInSvcAnnotationBeEqualTo(annotations map[string]string, key | |||
} | |||
return false | |||
} | |||
|
|||
// getLoadBalancerConfigurationsNames parse the annotation and return the names of the load balancer configurations. | |||
func GetLoadBalancerConfigurationsNames(service *v1.Service) []string { |
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.
Add a UT?
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.
It has been covered in other tests.
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.
I see, the TestGetEligibleLoadBalancers
. However, a UT for this function is more straightforward and raises coverage.
Anyway, it's up to you and I don't have strong opinion on this.
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.
Thanks for the suggestions. All lines have been covered.
existingLB.LoadBalancingRules != nil { | ||
for _, rule := range *existingLB.LoadBalancingRules { | ||
ruleName := pointer.StringDeref(rule.Name, "") | ||
rulePrefix := strings.Split(ruleName, "-")[0] |
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.
How about return error if slice of strings.Split(ruleName, "-")
is empty?
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.
It is not possible to be empty for managed rules. For unmanaged rules, I don't think we need to block this if the user adds a rule to the LB.
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.
Defensive programming.
For managed rules, I do believe these should not be empty but it is possible there's something wrong when calling API.
For unmanaged rules, CCM may panic and lose logs. So I think a check here will save our effort if cx needs us debug.
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.
Added a warning here. We can't break the reconciliation just because there are unmanaged rules.
pkg/provider/azure_loadbalancer.go
Outdated
klog.Errorf("reconcileLoadBalancer: invalid multiple standard load balancers configurations: %s", err.Error()) | ||
return nil, err |
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.
How about:
errMsg := fmt.Errorf("reconcileLoadBalancer: invalid multiple standard load balancers configurations: %s", err.Error())
klog.Error(errMsg)
return nil, errMsg
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.
May I know the reason why this is better? To me, this makes the error message longer without adding critical information. However, I think the error log message needs to be changed because there are multiple error possibilities not just invalid configs.
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.
I put the comment because I saw the following change in this PR and I think they should be of the same code style, right?
svcs, err := az.KubeClient.CoreV1().Services("").List(context.Background(), metav1.ListOptions{})
if err != nil {
klog.Errorf("reconcileMultipleStandardLoadBalancerConfigurations: failed to list all load balancer services: %w", err)
return fmt.Errorf("failed to list all load balancer services: %w", err)
}
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 original error here is returned by List and the message is not under my controller so I enrich the error message.
/retest |
b8b9a54
to
02e18b5
Compare
02e18b5
to
9bee28d
Compare
/lgtm |
What type of PR is this?
/kind feature
What this PR does / why we need it:
Support load balancer choosing logic for multi-slb feature. Major changes:
multipleStandardLoadBalancerConfigurations
and a new service annotationservice.beta.kubernetes.io/azure-load-balancer-configurations: lb1,lb2
.ListManagedLoadBalancers
. The current LB filtering logic is only useful for basic LB clusters. Add a new logic for multi-slb. For single-slb, managed LBs only be<clustername>
and .Which issue(s) this PR fixes:
Fixes #
Related #4013
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: