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

feat: support load balancer choosing logic for multi-slb #4075

Merged
merged 1 commit into from Jun 14, 2023

Conversation

nilo19
Copy link
Contributor

@nilo19 nilo19 commented Jun 9, 2023

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:

  1. Add a new configuration option multipleStandardLoadBalancerConfigurations and a new service annotation service.beta.kubernetes.io/azure-load-balancer-configurations: lb1,lb2.
  2. Change the logic of 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 .
  3. Implement the multi-lb selection algorithm. It reads service annotation and lb configs to select the most eligible LB for the service. If the LB does not exist, it will be created. If the last service on the LB is removed or moved to another LB, the LB will be deleted.

Which issue(s) this PR fixes:

Fixes #
Related #4013

Special notes for your reviewer:

Does this PR introduce a user-facing change?

feat: support load balancer choosing logic for multi-slb

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. labels Jun 9, 2023
@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jun 9, 2023
@netlify
Copy link

netlify bot commented Jun 9, 2023

Deploy Preview for kubernetes-sigs-cloud-provide-azure canceled.

Name Link
🔨 Latest commit 9bee28d
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-sigs-cloud-provide-azure/deploys/64880961c1f2f60008ce0678

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jun 9, 2023
@@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add a UT?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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]
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

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 a warning here. We can't break the reconciliation just because there are unmanaged rules.

Comment on lines 1533 to 1537
klog.Errorf("reconcileLoadBalancer: invalid multiple standard load balancers configurations: %s", err.Error())
return nil, err
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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)
	}

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 original error here is returned by List and the message is not under my controller so I enrich the error message.

@MartinForReal
Copy link
Contributor

/retest

@nilo19 nilo19 force-pushed the feat/multi-slb/config branch 2 times, most recently from b8b9a54 to 02e18b5 Compare June 12, 2023 14:49
@lzhecheng
Copy link
Contributor

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jun 14, 2023
@k8s-ci-robot k8s-ci-robot merged commit 05aea59 into kubernetes-sigs:master Jun 14, 2023
21 checks passed
@nilo19 nilo19 deleted the feat/multi-slb/config branch June 15, 2023 06:53
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. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants