Skip to content

Commit

Permalink
apply comments
Browse files Browse the repository at this point in the history
Signed-off-by: Nikita Skrynnik <nikita.skrynnik@xored.com>
  • Loading branch information
NikitaSkrynnik committed Mar 3, 2022
1 parent c83bf8e commit 1613d1a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 33 deletions.
23 changes: 1 addition & 22 deletions pkg/networkservice/chains/nsmgr/heal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ func testForwarderShouldBeSelectedCorrectlyOnNSMgrRestart(t *testing.T, nodeNum,
NetworkServiceNames: []string{"my-ns"},
}

nseEntry := domain.Nodes[nodeNum].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken)
domain.Nodes[nodeNum].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken)

nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken)

Expand Down Expand Up @@ -536,26 +536,5 @@ func testForwarderShouldBeSelectedCorrectlyOnNSMgrRestart(t *testing.T, nodeNum,
},
},
}, sandbox.GenerateTestToken)

_, err = domain.Nodes[nodeNum].NSMgr.NetworkServiceEndpointRegistryServer().Register(ctx, &registry.NetworkServiceEndpoint{
Name: expectedForwarderName,
Url: domain.Nodes[nodeNum].Forwarders[expectedForwarderName].URL.String(),
NetworkServiceNames: []string{"forwarder"},
NetworkServiceLabels: map[string]*registry.NetworkServiceLabels{
"forwarder": {
Labels: map[string]string{
"p2p": "true",
},
},
},
})
require.NoError(t, err)

_, err = domain.Nodes[nodeNum].NSMgr.NetworkServiceEndpointRegistryServer().Register(ctx, &registry.NetworkServiceEndpoint{
Name: nseReg.Name,
Url: nseEntry.URL.String(),
NetworkServiceNames: nseReg.NetworkServiceNames,
})
require.NoError(t, err)
}
}
19 changes: 8 additions & 11 deletions pkg/networkservice/common/discoverforwarder/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ func (d *discoverForwarderServer) Request(ctx context.Context, request *networks
var forwarderName = loadForwarderName(ctx)
var logger = log.FromContext(ctx).WithField("discoverForwarderServer", "request")

if forwarderName == "" {
segments := request.Connection.GetPath().GetPathSegments()
if pathIndex := int(request.Connection.GetPath().Index); len(segments) > pathIndex+1 {
forwarderName = segments[pathIndex+1].Name
}
}

if forwarderName == "" {
ns, err := d.discoverNetworkService(ctx, request.GetConnection().GetNetworkService(), request.GetConnection().GetPayload())
if err != nil {
Expand All @@ -93,17 +100,6 @@ func (d *discoverForwarderServer) Request(ctx context.Context, request *networks
return nil, errors.New("no candidates found")
}

segments := request.Connection.GetPath().GetPathSegments()
if pathIndex := int(request.Connection.GetPath().Index); len(segments) > pathIndex+1 {
datapathForwarder := segments[pathIndex+1].Name
for i, candidate := range nses {
if candidate.Name == datapathForwarder {
nses[0], nses[i] = nses[i], nses[0]
break
}
}
}

var candidatesErr = errors.New("all forwarders have failed")

// TODO: Should we consider about load balancing?
Expand All @@ -128,6 +124,7 @@ func (d *discoverForwarderServer) Request(ctx context.Context, request *networks

return nil, candidatesErr
}

stream, err := d.nseClient.Find(ctx, &registry.NetworkServiceEndpointQuery{
NetworkServiceEndpoint: &registry.NetworkServiceEndpoint{
Name: forwarderName,
Expand Down

0 comments on commit 1613d1a

Please sign in to comment.