@@ -103,6 +103,9 @@ const (
103103 // (for instance "80,443")
104104 serviceAnnotationLoadBalancerProxyProtocolV2 = "service.beta.kubernetes.io/scw-loadbalancer-proxy-protocol-v2"
105105
106+ // serviceAnnotationLoadBalancerType is the load balancer offer type
107+ serviceAnnotationLoadBalancerType = "service.beta.kubernetes.io/scw-loadbalancer-type"
108+
106109 // serviceAnnotationLoadBalancerTimeoutServer is the maximum server connection inactivity time
107110 // The default value is "10m". The duration are go's time.Duration (ex: "1s", "2m", "4h", ...)
108111 serviceAnnotationLoadBalancerTimeoutServer = "service.beta.kubernetes.io/scw-loadbalancer-timeout-server"
@@ -138,6 +141,7 @@ type LoadBalancerAPI interface {
138141 GetLb (req * scwlb.GetLbRequest , opts ... scw.RequestOption ) (* scwlb.Lb , error )
139142 CreateLb (req * scwlb.CreateLbRequest , opts ... scw.RequestOption ) (* scwlb.Lb , error )
140143 DeleteLb (req * scwlb.DeleteLbRequest , opts ... scw.RequestOption ) error
144+ MigrateLb (req * scwlb.MigrateLbRequest , opts ... scw.RequestOption ) (* scwlb.Lb , error )
141145 ListIPs (req * scwlb.ListIPsRequest , opts ... scw.RequestOption ) (* scwlb.ListIPsResponse , error )
142146 ListBackends (req * scwlb.ListBackendsRequest , opts ... scw.RequestOption ) (* scwlb.ListBackendsResponse , error )
143147 CreateBackend (req * scwlb.CreateBackendRequest , opts ... scw.RequestOption ) (* scwlb.Backend , error )
@@ -467,6 +471,7 @@ func (l *loadbalancers) createLoadBalancer(ctx context.Context, clusterName stri
467471 Description : "kubernetes service " + service .Name ,
468472 Tags : tags ,
469473 IPID : ipID ,
474+ Type : getLoadBalancerType (service ),
470475 }
471476
472477 lb , err := l .api .CreateLb (& request )
@@ -729,6 +734,22 @@ func (l *loadbalancers) updateLoadBalancer(ctx context.Context, loadbalancer *sc
729734 }
730735 }
731736
737+ loadBalancerType := getLoadBalancerType (service )
738+ if loadBalancerType != "" && strings .ToLower (loadbalancer .Type ) != strings .ToLower (loadBalancerType ) {
739+ _ , err := l .api .MigrateLb (& scwlb.MigrateLbRequest {
740+ LbID : loadbalancer .ID ,
741+ Type : loadBalancerType ,
742+ })
743+ if err != nil {
744+ klog .Errorf ("error updating lb: %v" , err )
745+ var respErr * scw.ResponseError
746+ if xerrors .As (err , & respErr ) {
747+ return fmt .Errorf ("Unable to migrate loadbalancer %s error %d with message %s" , loadbalancer .ID , respErr .StatusCode , respErr .Message )
748+ }
749+ return err
750+ }
751+ }
752+
732753 return nil
733754}
734755
@@ -1128,6 +1149,10 @@ func isPortInRange(r string, p int32) (bool, error) {
11281149 return false , nil
11291150}
11301151
1152+ func getLoadBalancerType (service * v1.Service ) string {
1153+ return service .Annotations [serviceAnnotationLoadBalancerType ]
1154+ }
1155+
11311156func getProxyProtocol (service * v1.Service , nodePort int32 ) (scwlb.ProxyProtocol , error ) {
11321157 proxyProtocolV1 := service .Annotations [serviceAnnotationLoadBalancerProxyProtocolV1 ]
11331158 proxyProtocolV2 := service .Annotations [serviceAnnotationLoadBalancerProxyProtocolV2 ]
0 commit comments