Skip to content

Feat: Add support for stickyness policy - #88

Open
vishesh92 wants to merge 1 commit into
mainfrom
feat-add-stickyness-policy
Open

Feat: Add support for stickyness policy#88
vishesh92 wants to merge 1 commit into
mainfrom
feat-add-stickyness-policy

Conversation

@vishesh92

@vishesh92 vishesh92 commented Dec 2, 2025

Copy link
Copy Markdown
Member

This needs changes in this PR: apache/cloudstack-go#133

Fixes #75

@vishesh92
vishesh92 marked this pull request as draft December 2, 2025 09:17
@vishesh92 vishesh92 added this to the 1.2.0 milestone Dec 4, 2025
@vishesh92
vishesh92 force-pushed the feat-add-stickyness-policy branch from f25a1e7 to 207f378 Compare December 12, 2025 07:33
@codecov-commenter

codecov-commenter commented Dec 12, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 80.85106% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 52.58%. Comparing base (151452f) to head (63947d8).

Files with missing lines Patch % Lines
cloudstack_loadbalancer.go 80.85% 17 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #88      +/-   ##
==========================================
+ Coverage   50.05%   52.58%   +2.53%     
==========================================
  Files           4        4              
  Lines         975     1065      +90     
==========================================
+ Hits          488      560      +72     
- Misses        473      490      +17     
- Partials       14       15       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@vishesh92 vishesh92 modified the milestones: 1.2.0, 1.3.0 Dec 16, 2025
Copilot AI lite review requested due to automatic review settings August 20, 2026 09:26
@vishesh92
vishesh92 force-pushed the feat-add-stickyness-policy branch from 207f378 to 6b74579 Compare August 20, 2026 09:26
@vishesh92
vishesh92 marked this pull request as ready for review August 20, 2026 09:26

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds support for configuring CloudStack Load Balancer stickiness policy via Kubernetes Service annotations (fixing the request in #75), and updates module dependencies to use a CloudStack Go SDK version that supports the required stickiness-policy API parameters.

Changes:

  • Introduces Service annotations for stickiness method name + params and reconciles stickiness policies during EnsureLoadBalancer.
  • Extends load balancer discovery to also fetch existing stickiness policies for rules.
  • Bumps github.com/apache/cloudstack-go/v2 to v2.19.1 and updates Go module dependencies accordingly.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 4 comments.

File Description
cloudstack_loadbalancer.go Adds stickiness annotations, policy reconciliation logic, and stickiness policy listing/CRUD.
go.mod Bumps CloudStack Go SDK to v2.19.1 and adjusts dependency classification.
go.sum Updates checksums for the bumped CloudStack Go SDK version.
Suppressed comments (2)

cloudstack_loadbalancer.go:833

  • CreateLBStickinessPolicy response is assumed to contain at least one Stickinesspolicy entry; if the API returns an empty slice this will panic. Add a defensive check and return an explicit error (and drop the commented-out return).
	return &cloudstack.LBStickinessPolicyStickinesspolicy{
		Methodname: stickynessPolicy.Stickinesspolicy[0].Methodname,
		Params:     stickynessPolicy.Stickinesspolicy[0].Params,
		Id:         stickynessPolicy.Stickinesspolicy[0].Id,
		Name:       stickynessPolicy.Stickinesspolicy[0].Name,

cloudstack_loadbalancer.go:1282

  • parseStickynessParams trims the full key=value token but not the key/value themselves, so annotations like "cookie = abc" will produce a key of "cookie " and won’t match expected params. Trim both sides when populating the map.
		if len(parts) == 2 {
			params[parts[0]] = parts[1]
		}

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread cloudstack_loadbalancer.go Outdated
Comment on lines +501 to +503
if len(lbStickinessPolicies.LBStickinessPolicies) > 0 {
lb.stickynessPolicies[lbRule.Id] = &lbStickinessPolicies.LBStickinessPolicies[0].Stickinesspolicy[0]
}
Comment thread cloudstack_loadbalancer.go Outdated
Comment on lines +726 to +731
for key, value := range stickynessPolicy.Params {
if stickynessMethodParams[key] != value {
klog.V(4).Infof("sticky policy param %v does not match: %v", key, value)
return stickynessPolicy, true, nil
}
}
Comment thread cloudstack_loadbalancer.go Outdated
Comment on lines +60 to +61
ServiceAnnotationLoadBalancerStickynessMethodName = "service.beta.kubernetes.io/cloudstack-load-balancer-stickyness-method-name"
ServiceAnnotationLoadBalancerStickynessParam = "service.beta.kubernetes.io/cloudstack-load-balancer-stickyness-method-param"
Comment thread cloudstack_loadbalancer.go Outdated
Comment on lines +691 to +695
func (lb *loadBalancer) checkStickynessPolicy(lbRule *cloudstack.LoadBalancerRule, service *corev1.Service) (*cloudstack.LBStickinessPolicyStickinesspolicy, bool, error) {
stickynessPolicy := lb.stickynessPolicies[lbRule.Id]
stickynessMethodName := getStringFromServiceAnnotation(service, ServiceAnnotationLoadBalancerStickynessMethodName, "")
stickynessMethodParam := getStringFromServiceAnnotation(service, ServiceAnnotationLoadBalancerStickynessParam, "")
stickynessMethodParams := parseStickynessParams(stickynessMethodParam)
@vishesh92
vishesh92 force-pushed the feat-add-stickyness-policy branch from 6b74579 to 95d6b1d Compare August 27, 2026 13:15
Copilot AI review requested due to automatic review settings August 27, 2026 13:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings August 31, 2026 06:15
@vishesh92
vishesh92 force-pushed the feat-add-stickyness-policy branch from 95d6b1d to 63947d8 Compare August 31, 2026 06:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Setting Load Balancer stickiness method with annotation

3 participants