Skip to content

Commit 23c29ec

Browse files
author
Rahul Sharma
committed
add support for different nodebalancer types
1 parent 1b9f2e7 commit 23c29ec

File tree

10 files changed

+131
-8
lines changed

10 files changed

+131
-8
lines changed

cloud/annotations/annotations.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const (
2323

2424
AnnLinodeLoadBalancerPreserve = "service.beta.kubernetes.io/linode-loadbalancer-preserve"
2525
AnnLinodeNodeBalancerID = "service.beta.kubernetes.io/linode-loadbalancer-nodebalancer-id"
26+
AnnLinodeNodeBalancerType = "service.beta.kubernetes.io/linode-loadbalancer-nodebalancer-type"
2627

2728
AnnLinodeHostnameOnlyIngress = "service.beta.kubernetes.io/linode-loadbalancer-hostname-only-ingress"
2829
AnnLinodeLoadBalancerTags = "service.beta.kubernetes.io/linode-loadbalancer-tags"

cloud/linode/cloud.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ var Options struct {
4646
IpHolderSuffix string
4747
LinodeExternalNetwork *net.IPNet
4848
NodeBalancerTags []string
49+
DefaultNBType string
4950
GlobalStopChannel chan<- struct{}
5051
}
5152

cloud/linode/loadbalancers.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,17 +627,29 @@ func (l *loadbalancers) GetLoadBalancerTags(_ context.Context, clusterName strin
627627
return tags
628628
}
629629

630+
// GetLinodeNBType returns the NodeBalancer type for the service.
631+
func (l *loadbalancers) GetLinodeNBType(service *v1.Service) linodego.NodeBalancerPlanType {
632+
typeStr, ok := service.GetAnnotations()[annotations.AnnLinodeNodeBalancerType]
633+
if ok && linodego.NodeBalancerPlanType(typeStr) == linodego.NBTypePremium {
634+
return linodego.NBTypePremium
635+
}
636+
637+
return linodego.NodeBalancerPlanType(Options.DefaultNBType)
638+
}
639+
630640
func (l *loadbalancers) createNodeBalancer(ctx context.Context, clusterName string, service *v1.Service, configs []*linodego.NodeBalancerConfigCreateOptions) (lb *linodego.NodeBalancer, err error) {
631641
connThrottle := getConnectionThrottle(service)
632642

633643
label := l.GetLoadBalancerName(ctx, clusterName, service)
634644
tags := l.GetLoadBalancerTags(ctx, clusterName, service)
645+
nbType := l.GetLinodeNBType(service)
635646
createOpts := linodego.NodeBalancerCreateOptions{
636647
Label: &label,
637648
Region: l.zone,
638649
ClientConnThrottle: &connThrottle,
639650
Configs: configs,
640651
Tags: tags,
652+
Type: nbType,
641653
}
642654

643655
fwid, ok := service.GetAnnotations()[annotations.AnnLinodeCloudFirewallID]

cloud/linode/loadbalancers_test.go

Lines changed: 102 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ import (
1717
"strings"
1818
"testing"
1919

20+
ciliumclient "github.com/cilium/cilium/pkg/k8s/client/clientset/versioned/typed/cilium.io/v2alpha1"
21+
"github.com/linode/linode-cloud-controller-manager/cloud/annotations"
22+
"github.com/linode/linode-cloud-controller-manager/cloud/linode/client"
23+
"github.com/linode/linode-cloud-controller-manager/cloud/linode/firewall"
2024
"github.com/linode/linodego"
2125
v1 "k8s.io/api/core/v1"
2226
"k8s.io/apimachinery/pkg/api/errors"
@@ -25,9 +29,6 @@ import (
2529
"k8s.io/apimachinery/pkg/types"
2630
"k8s.io/client-go/kubernetes"
2731
"k8s.io/client-go/kubernetes/fake"
28-
29-
"github.com/linode/linode-cloud-controller-manager/cloud/annotations"
30-
"github.com/linode/linode-cloud-controller-manager/cloud/linode/firewall"
3132
)
3233

3334
const testCert string = `-----BEGIN CERTIFICATE-----
@@ -3588,3 +3589,101 @@ func Test_LoadbalNodeNameCoercion(t *testing.T) {
35883589
}
35893590
}
35903591
}
3592+
3593+
func Test_loadbalancers_GetLinodeNBType(t *testing.T) {
3594+
type fields struct {
3595+
client client.Client
3596+
zone string
3597+
kubeClient kubernetes.Interface
3598+
ciliumClient ciliumclient.CiliumV2alpha1Interface
3599+
loadBalancerType string
3600+
}
3601+
type args struct {
3602+
service *v1.Service
3603+
}
3604+
tests := []struct {
3605+
name string
3606+
fields fields
3607+
args args
3608+
defaultNB linodego.NodeBalancerPlanType
3609+
want linodego.NodeBalancerPlanType
3610+
}{
3611+
{
3612+
name: "No annotation in service and common as default",
3613+
fields: fields{
3614+
client: nil,
3615+
zone: "",
3616+
kubeClient: nil,
3617+
ciliumClient: nil,
3618+
loadBalancerType: "nodebalancer",
3619+
},
3620+
args: args{
3621+
service: &v1.Service{
3622+
ObjectMeta: metav1.ObjectMeta{
3623+
Name: "test",
3624+
Annotations: map[string]string{},
3625+
},
3626+
},
3627+
},
3628+
defaultNB: linodego.NBTypeCommon,
3629+
want: linodego.NBTypeCommon,
3630+
},
3631+
{
3632+
name: "No annotation in service and premium as default",
3633+
fields: fields{
3634+
client: nil,
3635+
zone: "",
3636+
kubeClient: nil,
3637+
ciliumClient: nil,
3638+
loadBalancerType: "nodebalancer",
3639+
},
3640+
args: args{
3641+
service: &v1.Service{
3642+
ObjectMeta: metav1.ObjectMeta{
3643+
Name: "test",
3644+
Annotations: map[string]string{},
3645+
},
3646+
},
3647+
},
3648+
defaultNB: linodego.NBTypePremium,
3649+
want: linodego.NBTypePremium,
3650+
},
3651+
{
3652+
name: "Nodebalancer type annotation in service",
3653+
fields: fields{
3654+
client: nil,
3655+
zone: "",
3656+
kubeClient: nil,
3657+
ciliumClient: nil,
3658+
loadBalancerType: "nodebalancer",
3659+
},
3660+
args: args{
3661+
service: &v1.Service{
3662+
ObjectMeta: metav1.ObjectMeta{
3663+
Name: "test",
3664+
Annotations: map[string]string{
3665+
annotations.AnnLinodeNodeBalancerType: string(linodego.NBTypePremium),
3666+
},
3667+
},
3668+
},
3669+
},
3670+
defaultNB: linodego.NBTypeCommon,
3671+
want: linodego.NBTypePremium,
3672+
},
3673+
}
3674+
for _, tt := range tests {
3675+
t.Run(tt.name, func(t *testing.T) {
3676+
l := &loadbalancers{
3677+
client: tt.fields.client,
3678+
zone: tt.fields.zone,
3679+
kubeClient: tt.fields.kubeClient,
3680+
ciliumClient: tt.fields.ciliumClient,
3681+
loadBalancerType: tt.fields.loadBalancerType,
3682+
}
3683+
Options.DefaultNBType = string(tt.defaultNB)
3684+
if got := l.GetLinodeNBType(tt.args.service); !reflect.DeepEqual(got, tt.want) {
3685+
t.Errorf("loadbalancers.GetLinodeNBType() = %v, want %v", got, tt.want)
3686+
}
3687+
})
3688+
}
3689+
}

deploy/chart/templates/daemonset.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ spec:
7474
{{- if .Values.allowUnauthorizedMetrics }}
7575
- --authorization-always-allow-paths="/metrics"
7676
{{- end }}
77+
{{- if .Values.defaultNBType }}
78+
- --default-nodebalancer-type={{ .Values.defaultNBType }}
79+
{{- end }}
7780
volumeMounts:
7881
- mountPath: /etc/kubernetes
7982
name: k8s

deploy/chart/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ tolerations:
6060
# Enable Linode token health checker
6161
# tokenHealthChecker: true
6262

63+
# Default NodeBalancer type to create (default is "common")
64+
# defaultNBType: "common"
65+
6366
# This section adds the ability to pass environment variables to adjust CCM defaults
6467
# https://github.com/linode/linode-cloud-controller-manager/blob/master/cloud/linode/loadbalancers.go
6568
# LINODE_HOSTNAME_ONLY_INGRESS type bool is supported

docs/configuration/annotations.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ For implementation details, see:
3232
| `tags` | string | | A comma separated list of tags to be applied to the NodeBalancer instance |
3333
| `firewall-id` | string | | An existing Cloud Firewall ID to be attached to the NodeBalancer instance. See [Firewall Setup](firewall.md) |
3434
| `firewall-acl` | string | | The Firewall rules to be applied to the NodeBalancer. See [Firewall Configuration](#firewall-configuration) |
35+
| `nodebalancer-type` | string | | The type of NodeBalancer to create (options: common, premium) |
3536

3637
### Port Specific Configuration
3738

go.mod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ require (
6060
github.com/go-openapi/strfmt v0.23.0 // indirect
6161
github.com/go-openapi/swag v0.23.0 // indirect
6262
github.com/go-openapi/validate v0.24.0 // indirect
63-
github.com/go-resty/resty/v2 v2.16.3 // indirect
63+
github.com/go-resty/resty/v2 v2.16.5 // indirect
6464
github.com/gogo/protobuf v1.3.2 // indirect
6565
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
6666
github.com/golang/protobuf v1.5.4 // indirect
@@ -166,3 +166,5 @@ require (
166166
sigs.k8s.io/structured-merge-diff/v4 v4.5.0 // indirect
167167
sigs.k8s.io/yaml v1.4.0 // indirect
168168
)
169+
170+
replace github.com/linode/linodego => github.com/eljohnson92/linodego v0.0.0-20250131225039-9e9e422ab627

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
6161
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
6262
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
6363
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
64+
github.com/eljohnson92/linodego v0.0.0-20250131225039-9e9e422ab627 h1:2aCpoTzIKx2h8OTUrswjOL2hII14ppgswt+YqCJR3qU=
65+
github.com/eljohnson92/linodego v0.0.0-20250131225039-9e9e422ab627/go.mod h1:reAU6qPdS59pmxEB4cmaCr0ew19rw9ygz1I05D9Mkyc=
6466
github.com/emicklei/go-restful/v3 v3.12.1 h1:PJMDIM/ak7btuL8Ex0iYET9hxM3CI2sjZtzpL63nKAU=
6567
github.com/emicklei/go-restful/v3 v3.12.1/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
6668
github.com/envoyproxy/protoc-gen-validate v1.1.0 h1:tntQDh69XqOCOZsDz0lVJQez/2L6Uu2PdjCQwWCJ3bM=
@@ -108,8 +110,8 @@ github.com/go-openapi/validate v0.24.0 h1:LdfDKwNbpB6Vn40xhTdNZAnfLECL81w+VX3Bum
108110
github.com/go-openapi/validate v0.24.0/go.mod h1:iyeX1sEufmv3nPbBdX3ieNviWnOZaJ1+zquzJEf2BAQ=
109111
github.com/go-quicktest/qt v1.101.0 h1:O1K29Txy5P2OK0dGo59b7b0LR6wKfIhttaAhHUyn7eI=
110112
github.com/go-quicktest/qt v1.101.0/go.mod h1:14Bz/f7NwaXPtdYEgzsx46kqSxVwTbzVZsDC26tQJow=
111-
github.com/go-resty/resty/v2 v2.16.3 h1:zacNT7lt4b8M/io2Ahj6yPypL7bqx9n1iprfQuodV+E=
112-
github.com/go-resty/resty/v2 v2.16.3/go.mod h1:hkJtXbA2iKHzJheXYvQ8snQES5ZLGKMwQ07xAwp/fiA=
113+
github.com/go-resty/resty/v2 v2.16.5 h1:hBKqmWrr7uRc3euHVqmh1HTHcKn99Smr7o5spptdhTM=
114+
github.com/go-resty/resty/v2 v2.16.5/go.mod h1:hkJtXbA2iKHzJheXYvQ8snQES5ZLGKMwQ07xAwp/fiA=
113115
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
114116
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
115117
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
@@ -199,8 +201,6 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
199201
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
200202
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
201203
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
202-
github.com/linode/linodego v1.47.0 h1:6MFNCyzWbr8Rhl4r7d5DwZLwxvFIsM4ARH6W0KS/R0U=
203-
github.com/linode/linodego v1.47.0/go.mod h1:vyklQRzZUWhFVBZdYx4dcYJU/gG9yKB9VUcUs6ub0Lk=
204204
github.com/mackerelio/go-osstat v0.2.5 h1:+MqTbZUhoIt4m8qzkVoXUJg1EuifwlAJSk4Yl2GXh+o=
205205
github.com/mackerelio/go-osstat v0.2.5/go.mod h1:atxwWF+POUZcdtR1wnsUcQxTytoHG4uhl2AKKzrOajY=
206206
github.com/magiconair/properties v1.8.9 h1:nWcCbLq1N2v/cpNsy5WvQ37Fb+YElfq20WJ/a8RkpQM=

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ func main() {
8787
command.Flags().StringVar(&linode.Options.LoadBalancerType, "load-balancer-type", "nodebalancer", "configures which type of load-balancing to use for LoadBalancer Services (options: nodebalancer, cilium-bgp)")
8888
command.Flags().StringVar(&linode.Options.BGPNodeSelector, "bgp-node-selector", "", "node selector to use to perform shared IP fail-over with BGP (e.g. cilium-bgp-peering=true")
8989
command.Flags().StringVar(&linode.Options.IpHolderSuffix, "ip-holder-suffix", "", "suffix to append to the ip holder name when using shared IP fail-over with BGP (e.g. ip-holder-suffix=my-cluster-name")
90+
command.Flags().StringVar(&linode.Options.DefaultNBType, "default-nodebalancer-type", "common", "default type of NodeBalancer to create (options: common, premium)")
9091
command.Flags().StringSliceVar(&linode.Options.NodeBalancerTags, "nodebalancer-tags", []string{}, "Linode tags to apply to all NodeBalancers")
9192

9293
// Set static flags

0 commit comments

Comments
 (0)