Skip to content

Commit

Permalink
Support adding tags to nodebalancers
Browse files Browse the repository at this point in the history
  • Loading branch information
tchinmai7 committed Nov 6, 2023
1 parent aec305f commit be7c010
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions cloud/linode/fake_linode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ func (f *fakeAPI) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Region: nbco.Region,
IPv4: &ip,
Hostname: &hostname,
Tags: nbco.Tags,
}

if nbco.ClientConnThrottle != nil {
Expand Down
11 changes: 11 additions & 0 deletions cloud/linode/loadbalancers.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const (
annLinodeNodeBalancerID = "service.beta.kubernetes.io/linode-loadbalancer-nodebalancer-id"

annLinodeHostnameOnlyIngress = "service.beta.kubernetes.io/linode-loadbalancer-hostname-only-ingress"
annLinodeLoadBalancerTags = "service.beta.kubernetes.io/linode-loadbalancer-tags"
)

type lbNotFoundError struct {
Expand Down Expand Up @@ -480,15 +481,25 @@ func (l *loadbalancers) getNodeBalancerByID(ctx context.Context, service *v1.Ser
return nb, nil
}

func (l *loadbalancers) getLoadbalancerTags(ctx context.Context, service *v1.Service) []string {
tagStr, ok := getServiceAnnotation(service, annLinodeLoadBalancerTags)
if ok {
return strings.Split(tagStr, ",")
}
return []string{}
}

func (l *loadbalancers) createNodeBalancer(ctx context.Context, clusterName string, service *v1.Service, configs []*linodego.NodeBalancerConfigCreateOptions) (lb *linodego.NodeBalancer, err error) {
connThrottle := getConnectionThrottle(service)

label := l.GetLoadBalancerName(ctx, clusterName, service)
tags := l.getLoadbalancerTags(ctx, service)
createOpts := linodego.NodeBalancerCreateOptions{
Label: &label,
Region: l.zone,
ClientConnThrottle: &connThrottle,
Configs: configs,
Tags: tags,
}
return l.client.CreateNodeBalancer(ctx, createOpts)
}
Expand Down
10 changes: 9 additions & 1 deletion cloud/linode/loadbalancers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ func testCreateNodeBalancer(t *testing.T, client *linodego.Client, _ *fakeAPI) {
Name: randString(10),
UID: "foobar123",
Annotations: map[string]string{
annLinodeThrottle: "15",
annLinodeThrottle: "15",
annLinodeLoadBalancerTags: "fake,test,yolo",
},
},
Spec: v1.ServiceSpec{
Expand Down Expand Up @@ -264,6 +265,13 @@ func testCreateNodeBalancer(t *testing.T, client *linodego.Client, _ *fakeAPI) {
t.Logf("actual: %v", nb.ClientConnThrottle)
}

expectedTags := []string{"fake", "test", "yolo"}
if !reflect.DeepEqual(nb.Tags, expectedTags) {
t.Error("unexpected Tags")
t.Logf("expected: %v", expectedTags)
t.Logf("actual: %v", nb.Tags)
}

defer func() { _ = lb.EnsureLoadBalancerDeleted(context.TODO(), "linodelb", svc) }()
}

Expand Down

0 comments on commit be7c010

Please sign in to comment.