diff --git a/cloud/linode/loadbalancers.go b/cloud/linode/loadbalancers.go index fbec795b..8de8bbc8 100644 --- a/cloud/linode/loadbalancers.go +++ b/cloud/linode/loadbalancers.go @@ -239,7 +239,7 @@ func (l *loadbalancers) EnsureLoadBalancer(ctx context.Context, clusterName stri klog.Infof("created new NodeBalancer (%d) for service (%s)", nb.ID, serviceNn) case nil: - if err = l.updateNodeBalancer(ctx, service, nodes, nb); err != nil { + if err = l.updateNodeBalancer(ctx, clusterName, service, nodes, nb); err != nil { sentry.CaptureError(ctx, err) return nil, err } @@ -263,7 +263,7 @@ func (l *loadbalancers) EnsureLoadBalancer(ctx context.Context, clusterName stri } //nolint:funlen -func (l *loadbalancers) updateNodeBalancer(ctx context.Context, service *v1.Service, nodes []*v1.Node, nb *linodego.NodeBalancer) (err error) { +func (l *loadbalancers) updateNodeBalancer(ctx context.Context, clusterName string, service *v1.Service, nodes []*v1.Node, nb *linodego.NodeBalancer) (err error) { if len(nodes) == 0 { return fmt.Errorf("%w: service %s", errNoNodesAvailable, getServiceNn(service)) } @@ -280,7 +280,7 @@ func (l *loadbalancers) updateNodeBalancer(ctx context.Context, service *v1.Serv } } - tags := l.getLoadBalancerTags(ctx, service) + tags := l.getLoadBalancerTags(ctx, clusterName, service) if !reflect.DeepEqual(nb.Tags, tags) { update := nb.GetUpdateOptions() update.Tags = &tags @@ -392,7 +392,7 @@ func (l *loadbalancers) UpdateLoadBalancer(ctx context.Context, clusterName stri } } - return l.updateNodeBalancer(ctx, serviceWithStatus, nodes, nb) + return l.updateNodeBalancer(ctx, clusterName, serviceWithStatus, nodes, nb) } // Delete any NodeBalancer configs for ports that no longer exist on the Service @@ -505,19 +505,20 @@ func (l *loadbalancers) getNodeBalancerByID(ctx context.Context, service *v1.Ser return nb, nil } -func (l *loadbalancers) getLoadBalancerTags(_ context.Context, service *v1.Service) []string { +func (l *loadbalancers) getLoadBalancerTags(_ context.Context, clusterName string, service *v1.Service) []string { + tags := []string{clusterName} tagStr, ok := getServiceAnnotation(service, annLinodeLoadBalancerTags) if ok { - return strings.Split(tagStr, ",") + return append(tags, strings.Split(tagStr, ",")...) } - return []string{} + return tags } 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) + tags := l.getLoadBalancerTags(ctx, clusterName, service) createOpts := linodego.NodeBalancerCreateOptions{ Label: &label, Region: l.zone, diff --git a/cloud/linode/loadbalancers_test.go b/cloud/linode/loadbalancers_test.go index b2250ffa..684f0353 100644 --- a/cloud/linode/loadbalancers_test.go +++ b/cloud/linode/loadbalancers_test.go @@ -282,7 +282,7 @@ func testCreateNodeBalancer(t *testing.T, client *linodego.Client, _ *fakeAPI, f t.Logf("actual: %v", nb.ClientConnThrottle) } - expectedTags := []string{"fake", "test", "yolo"} + expectedTags := []string{"linodelb", "fake", "test", "yolo"} if !reflect.DeepEqual(nb.Tags, expectedTags) { t.Error("unexpected Tags") t.Logf("expected: %v", expectedTags) @@ -500,10 +500,11 @@ func testUpdateLoadBalancerAddTags(t *testing.T, client *linodego.Client, _ *fak lb := &loadbalancers{client, "us-west", nil} fakeClientset := fake.NewSimpleClientset() lb.kubeClient = fakeClientset + clusterName := "linodelb" - defer lb.EnsureLoadBalancerDeleted(context.TODO(), "linodelb", svc) + defer lb.EnsureLoadBalancerDeleted(context.TODO(), clusterName, svc) - lbStatus, err := lb.EnsureLoadBalancer(context.TODO(), "linodelb", svc, nodes) + lbStatus, err := lb.EnsureLoadBalancer(context.TODO(), clusterName, svc, nodes) if err != nil { t.Errorf("EnsureLoadBalancer returned an error: %s", err) } @@ -515,7 +516,7 @@ func testUpdateLoadBalancerAddTags(t *testing.T, client *linodego.Client, _ *fak annLinodeLoadBalancerTags: testTags, }) - err = lb.UpdateLoadBalancer(context.TODO(), "linodelb", svc, nodes) + err = lb.UpdateLoadBalancer(context.TODO(), clusterName, svc, nodes) if err != nil { t.Fatalf("UpdateLoadBalancer returned an error while updated annotations: %s", err) } @@ -525,7 +526,7 @@ func testUpdateLoadBalancerAddTags(t *testing.T, client *linodego.Client, _ *fak t.Fatalf("failed to get NodeBalancer by status: %v", err) } - expectedTags := strings.Split(testTags, ",") + expectedTags := append([]string{clusterName}, strings.Split(testTags, ",")...) observedTags := nb.Tags if !reflect.DeepEqual(expectedTags, observedTags) {