@@ -120,9 +120,13 @@ const (
120120
121121 // annDOSizeSlug is the annotation specifying the size of the LB.
122122 // Options are `lb-small`, `lb-medium`, and `lb-large`.
123- // Defaults to `lb-small`.
123+ // Defaults to `lb-small`. Only one of annDOSizeSlug and annDOSizeUnit can be specified.
124124 annDOSizeSlug = "service.beta.kubernetes.io/do-loadbalancer-size-slug"
125125
126+ // annDOSizeUnit is the annotation specifying the size of the LB.
127+ // Options are numbers greater than or equal to `1`. Only one of annDOSizeUnit and annDOSizeSlug can be specified.
128+ annDOSizeUnit = "service.beta.kubernetes.io/do-loadbalancer-size-unit"
129+
126130 // annDOStickySessionsType is the annotation specifying which sticky session type
127131 // DO loadbalancer should use. Options are none and cookies. Defaults
128132 // to none.
@@ -665,6 +669,15 @@ func (l *loadBalancers) buildLoadBalancerRequest(ctx context.Context, service *v
665669 return nil , err
666670 }
667671
672+ sizeUnit , err := getSizeUnit (service )
673+ if err != nil {
674+ return nil , err
675+ }
676+
677+ if sizeSlug != "" && sizeUnit > 0 {
678+ return nil , fmt .Errorf ("only one of LB size slug and size unit can be provided" )
679+ }
680+
668681 redirectHTTPToHTTPS , err := getRedirectHTTPToHTTPS (service )
669682 if err != nil {
670683 return nil , err
@@ -690,6 +703,7 @@ func (l *loadBalancers) buildLoadBalancerRequest(ctx context.Context, service *v
690703 DropletIDs : dropletIDs ,
691704 Region : l .region ,
692705 SizeSlug : sizeSlug ,
706+ SizeUnit : sizeUnit ,
693707 ForwardingRules : forwardingRules ,
694708 HealthCheck : healthCheck ,
695709 StickySessions : stickySessions ,
@@ -1095,19 +1109,39 @@ func getAlgorithm(service *v1.Service) string {
10951109 }
10961110}
10971111
1112+ // getSizeSlug returns the load balancer size as a slug
10981113func getSizeSlug (service * v1.Service ) (string , error ) {
1099- sizeSlug , ok := service .Annotations [annDOSizeSlug ]
1114+ sizeSlug , _ := service .Annotations [annDOSizeSlug ]
11001115
1101- if ! ok || sizeSlug == "" {
1102- sizeSlug = "lb-small"
1116+ if sizeSlug != "" {
1117+ switch sizeSlug {
1118+ case "lb-small" , "lb-medium" , "lb-large" :
1119+ default :
1120+ return "" , fmt .Errorf ("invalid LB size slug provided: %s" , sizeSlug )
1121+ }
11031122 }
11041123
1105- switch sizeSlug {
1106- case "lb-small" , "lb-medium" , "lb-large" :
1107- return sizeSlug , nil
1108- default :
1109- return "" , fmt .Errorf ("invalid LB size slug provided: %s" , sizeSlug )
1124+ return sizeSlug , nil
1125+ }
1126+
1127+ // getSizeUnit returns the load balancer size as a number
1128+ func getSizeUnit (service * v1.Service ) (uint32 , error ) {
1129+ sizeUnitStr , ok := service .Annotations [annDOSizeUnit ]
1130+
1131+ if ! ok || sizeUnitStr == "" {
1132+ return uint32 (0 ), nil
11101133 }
1134+
1135+ sizeUnit , err := strconv .Atoi (sizeUnitStr )
1136+ if err != nil {
1137+ return 0 , fmt .Errorf ("invalid LB size unit %q provided: %s" , sizeUnitStr , err )
1138+ }
1139+
1140+ if sizeUnit < 0 {
1141+ return 0 , fmt .Errorf ("LB size unit must be non-negative. %d provided" , sizeUnit )
1142+ }
1143+
1144+ return uint32 (sizeUnit ), nil
11111145}
11121146
11131147// getStickySessionsType returns the sticky session type to use for
0 commit comments