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

Update loadbalancer annotations #291

Merged
merged 4 commits into from
Mar 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions vultr/loadbalancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ const (
annoVultrAlgorithm = "service.beta.kubernetes.io/vultr-loadbalancer-algorithm"
annoVultrSSLRedirect = "service.beta.kubernetes.io/vultr-loadbalancer-ssl-redirect"
annoVultrProxyProtocol = "service.beta.kubernetes.io/vultr-loadbalancer-proxy-protocol"
annoVultrLBHTTP2 = "service.beta.kubernetes.io/vultr-loadbalancer-http2"
annoVultrLBHTTP3 = "service.beta.kubernetes.io/vultr-loadbalancer-http3"
annoVultrLBTimeout = "service.beta.kubernetes.io/vultr-loadbalancer-timeout"

annoVultrStickySessionEnabled = "service.beta.kubernetes.io/vultr-loadbalancer-sticky-session-enabled"
annoVultrStickySessionCookieName = "service.beta.kubernetes.io/vultr-loadbalancer-sticky-session-cookie-name"
Expand All @@ -92,6 +95,8 @@ const (
healthCheckUnhealthy = 5
healthCheckHealthy = 5

defaultLBTimeout = 600

lbStatusActive = "active"
)

Expand Down Expand Up @@ -418,6 +423,11 @@ func (l *loadbalancers) buildLoadBalancerRequest(service *v1.Service, nodes []*v
return nil, err
}

timeout, err := getTimeout(service)
if err != nil {
return nil, err
}

var ssl *govultr.SSL
if secretName, ok := service.Annotations[annoVultrLBSSL]; ok {
ssl, err = l.GetSSL(service, secretName)
Expand Down Expand Up @@ -461,9 +471,12 @@ func (l *loadbalancers) buildLoadBalancerRequest(service *v1.Service, nodes []*v
ForwardingRules: rules, // all always be set
SSL: ssl, // will always be set
SSLRedirect: govultr.BoolToBoolPtr(getSSLRedirect(service)), // need to check
HTTP2: govultr.BoolToBoolPtr(getHTTP2(service)), // need to check
HTTP3: govultr.BoolToBoolPtr(getHTTP3(service)), // need to check
ProxyProtocol: govultr.BoolToBoolPtr(getProxyProtocol(service)), // need to check
BalancingAlgorithm: getAlgorithm(service), // will always be set
FirewallRules: firewallRules, // need to check
Timeout: timeout, // need to check
VPC: govultr.StringToStringPtr(vpc), // need to check
Nodes: nodeC, // need to check
}, nil
Expand Down Expand Up @@ -901,6 +914,47 @@ func getProxyProtocol(service *v1.Service) bool {
return pass
}

func getHTTP2(service *v1.Service) bool {
http2, ok := service.Annotations[annoVultrLBHTTP2]
if !ok {
return false
}

protocolHTTP2, err := strconv.ParseBool(http2)
if err != nil {
return false
}

return protocolHTTP2
}

func getHTTP3(service *v1.Service) bool {
http3, ok := service.Annotations[annoVultrLBHTTP3]
if !ok {
return false
}

protocolHTTP3, err := strconv.ParseBool(http3)
if err != nil {
return false
}

return protocolHTTP3
}

func getTimeout(service *v1.Service) (int, error) {
lbtimeout, ok := service.Annotations[annoVultrLBTimeout]
if !ok {
return defaultLBTimeout, nil
}

timeout, err := strconv.Atoi(lbtimeout)
if err != nil {
return 0, fmt.Errorf("invalid timeout value: %v", err)
}
return timeout, nil
}

func buildFirewallRules(service *v1.Service) ([]govultr.LBFirewallRule, error) {
lbFWRules := []govultr.LBFirewallRule{}
fwRules := getFirewallRules(service)
Expand Down
Loading