Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions controller/api/destination/endpoint_translator.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package destination

import (
"context"
"fmt"
"strconv"
"strings"
Expand All @@ -13,8 +12,7 @@ import (
"github.com/linkerd/linkerd2/pkg/k8s"
logging "github.com/sirupsen/logrus"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
coreinformers "k8s.io/client-go/informers/core/v1"
)

const (
Expand All @@ -39,13 +37,12 @@ type endpointTranslator struct {
}

func newEndpointTranslator(
ctx context.Context,
controllerNS string,
identityTrustDomain string,
enableH2Upgrade bool,
service string,
srcNodeName string,
k8sClient kubernetes.Interface,
nodes coreinformers.NodeInformer,
stream pb.Destination_GetServer,
log *logging.Entry,
) *endpointTranslator {
Expand All @@ -54,7 +51,7 @@ func newEndpointTranslator(
"service": service,
})

nodeTopologyLabels, err := getK8sNodeTopology(ctx, k8sClient, srcNodeName)
nodeTopologyLabels, err := getK8sNodeTopology(nodes, srcNodeName)
if err != nil {
log.Errorf("Failed to get node topology for node %s: %s", srcNodeName, err)
}
Expand Down Expand Up @@ -371,9 +368,9 @@ func toWeightedAddr(address watcher.Address, opaquePorts map[uint32]struct{}, en
}, nil
}

func getK8sNodeTopology(ctx context.Context, k8sClient kubernetes.Interface, srcNode string) (map[string]string, error) {
func getK8sNodeTopology(nodes coreinformers.NodeInformer, srcNode string) (map[string]string, error) {
nodeTopology := make(map[string]string)
node, err := k8sClient.CoreV1().Nodes().Get(ctx, srcNode, metav1.GetOptions{})
node, err := nodes.Lister().Get(srcNode)
if err != nil {
return nodeTopology, err
}
Expand Down
4 changes: 1 addition & 3 deletions controller/api/destination/endpoint_translator_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package destination

import (
"context"
"fmt"
"reflect"
"sort"
Expand Down Expand Up @@ -142,13 +141,12 @@ metadata:

mockGetServer := &mockDestinationGetServer{updatesReceived: []*pb.Update{}}
translator := newEndpointTranslator(
context.Background(),
"linkerd",
"trust.domain",
true,
"service-name.service-ns",
"test-123",
k8sAPI.Client,
k8sAPI.Node(),
mockGetServer,
logging.WithField("test", t.Name()),
)
Expand Down
6 changes: 4 additions & 2 deletions controller/api/destination/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/peer"
"google.golang.org/grpc/status"
coreinformers "k8s.io/client-go/informers/core/v1"
)

type (
Expand All @@ -25,6 +26,7 @@ type (
profiles *watcher.ProfileWatcher
trafficSplits *watcher.TrafficSplitWatcher
ips *watcher.IPWatcher
nodes coreinformers.NodeInformer

enableH2Upgrade bool
controllerNS string
Expand Down Expand Up @@ -73,6 +75,7 @@ func NewServer(
profiles,
trafficSplits,
ips,
k8sAPI.Node(),
enableH2Upgrade,
controllerNS,
identityTrustDomain,
Expand Down Expand Up @@ -103,13 +106,12 @@ func (s *server) Get(dest *pb.GetDestination, stream pb.Destination_GetServer) e
}

translator := newEndpointTranslator(
stream.Context(),
s.controllerNS,
s.identityTrustDomain,
s.enableH2Upgrade,
dest.GetPath(),
token.NodeName,
s.k8sAPI.Client,
s.nodes,
stream,
log,
)
Expand Down
1 change: 1 addition & 0 deletions controller/api/destination/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ spec:
profiles,
trafficSplits,
ips,
k8sAPI.Node(),
true,
"linkerd",
"trust.domain",
Expand Down
4 changes: 2 additions & 2 deletions controller/cmd/destination/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ func Main(args []string) {
ctx,
*kubeConfigPath,
true,
k8s.Endpoint, k8s.ES, k8s.Pod, k8s.RS, k8s.Svc, k8s.SP, k8s.TS, k8s.Job, k8s.NS,
k8s.Endpoint, k8s.ES, k8s.Pod, k8s.RS, k8s.Svc, k8s.SP, k8s.TS, k8s.Job, k8s.NS, k8s.Node,
)
} else {
k8sAPI, err = k8s.InitializeAPI(
ctx,
*kubeConfigPath,
true,
k8s.Endpoint, k8s.Pod, k8s.RS, k8s.Svc, k8s.SP, k8s.TS, k8s.Job, k8s.NS,
k8s.Endpoint, k8s.Pod, k8s.RS, k8s.Svc, k8s.SP, k8s.TS, k8s.Job, k8s.NS, k8s.Node,
)
}
if err != nil {
Expand Down