Skip to content

Commit

Permalink
Update loadbalancer annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
mondragonfx committed Mar 5, 2025
1 parent 2fce7e8 commit 8a86646
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 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 @@ -76,6 +79,8 @@ const (

annoVultrNodeCount = "service.beta.kubernetes.io/vultr-loadbalancer-node-count"

annoVultrLBGlobalRegions = "service.beta.kubernetes.io/vultr-loadbalancer-global-regions"

// annoVultrLBSSLLastUpdatedTime is used to keep track of when a SVC is updated due to the SSL secret being updated
annoVultrLBSSLLastUpdatedTime = "service.beta.kubernetes.io/vultr-loadbalancer-ssl-last-updated"

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 All @@ -438,6 +448,11 @@ func (l *loadbalancers) buildLoadBalancerRequest(service *v1.Service, nodes []*v
return nil, err
}

globalRegions, err := getGlobalRegions(service)
if err != nil {
return nil, err
}

nodeC := 1

if count, ok := service.Annotations[annoVultrNodeCount]; ok {
Expand All @@ -461,10 +476,14 @@ 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
GlobalRegions: globalRegions, // need to check
Nodes: nodeC, // need to check
}, nil
}
Expand Down Expand Up @@ -901,6 +920,61 @@ 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 600, nil

Check failure on line 954 in vultr/loadbalancers.go

View workflow job for this annotation

GitHub Actions / Golangci-Lint

Magic number: 600, in <return> detected (mnd)
}

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

func getGlobalRegions(service *v1.Service) ([]string, error) {

Check failure on line 964 in vultr/loadbalancers.go

View workflow job for this annotation

GitHub Actions / Golangci-Lint

getGlobalRegions - result 1 (error) is always nil (unparam)
regions, ok := service.Annotations[annoVultrLBGlobalRegions]
if !ok || regions == "" {
return nil, nil
}

regionList := strings.Split(regions, ",")
for v := range regionList {
regionList[v] = strings.TrimSpace(regionList[v])
}

return regionList, nil
}

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

0 comments on commit 8a86646

Please sign in to comment.