Skip to content

Commit

Permalink
use shared_cluster param for update lb
Browse files Browse the repository at this point in the history
  • Loading branch information
olegy89 committed Oct 21, 2024
1 parent dd76710 commit 6281021
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21

require (
github.com/onsi/gomega v1.27.6
github.com/serverscom/serverscom-go-client v1.0.6
github.com/serverscom/serverscom-go-client v1.0.7
github.com/spf13/pflag v1.0.5
go.uber.org/mock v0.4.0
k8s.io/api v0.28.12
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/serverscom/serverscom-go-client v1.0.6 h1:3i3l3K+fo6r83e8I8NbzYvBia2AJ1XRVRRmyFafS5bw=
github.com/serverscom/serverscom-go-client v1.0.6/go.mod h1:X4/JkqDMjEFAqp0hqdRTmcMXc6V2xCitj+kmNyne3/U=
github.com/serverscom/serverscom-go-client v1.0.7 h1:3+Gld2eueCNtUOaHn9DmQ9ABowUpAkAMbZlKxeMFVOg=
github.com/serverscom/serverscom-go-client v1.0.7/go.mod h1:X4/JkqDMjEFAqp0hqdRTmcMXc6V2xCitj+kmNyne3/U=
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/soheilhy/cmux v0.1.5 h1:jjzc5WVemNEDTLwv9tlmemhC73tI08BNOIGwBOo10Js=
Expand Down
14 changes: 8 additions & 6 deletions serverscom/loadbalancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ func (l *loadBalancers) EnsureLoadBalancer(ctx context.Context, clusterName stri
return nil, err
}

// empty value for cluster id still returns nil
lbClusterID := l.extractLBClusterID(service)

if loadBalancer == nil {
Expand Down Expand Up @@ -99,6 +100,9 @@ func (l *loadBalancers) EnsureLoadBalancer(ctx context.Context, clusterName stri
input.UpstreamZones = upstreamZones
input.Name = &name
input.ClusterID = lbClusterID
if lbClusterID == nil {
*input.SharedCluster = true
}

loadBalancer, err = l.client.LoadBalancers.UpdateL4LoadBalancer(ctx, loadBalancer.ID, input)
if err != nil {
Expand Down Expand Up @@ -291,12 +295,10 @@ func (l *loadBalancers) buildResult(service *v1.Service, loadBalancer *cli.L4Loa
return &v1.LoadBalancerStatus{Ingress: ingresses}
}

func (l *loadBalancers) extractLBClusterID(service *v1.Service) string {
var clusterID string

if id, ok := service.Annotations[loadBalancerClusterAnnotation]; ok {
clusterID = id
func (l *loadBalancers) extractLBClusterID(service *v1.Service) *string {
if id, ok := service.Annotations[loadBalancerClusterAnnotation]; ok && id != "" {
return &id
}

return clusterID
return nil
}

0 comments on commit 6281021

Please sign in to comment.