Skip to content

Commit

Permalink
resolve issue deployments-k8s#9888 (#1531)
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Tingaikin <[email protected]>
  • Loading branch information
denis-tingaikin committed Dec 12, 2023
1 parent 530e439 commit 915497b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
20 changes: 15 additions & 5 deletions pkg/networkservice/chains/nsmgr/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import (
"github.com/networkservicemesh/sdk/pkg/networkservice/common/mechanismtranslation"
"github.com/networkservicemesh/sdk/pkg/networkservice/common/passthrough"
"github.com/networkservicemesh/sdk/pkg/networkservice/core/chain"
"github.com/networkservicemesh/sdk/pkg/networkservice/ipam/point2pointipam"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/count"
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/inject/injecterror"
registryclient "github.com/networkservicemesh/sdk/pkg/registry/chains/client"
Expand Down Expand Up @@ -205,7 +206,7 @@ func (s *nsmgrSuite) Test_ReselectEndpointWhenNetSvcHasChanged() {
nsReg, err := s.nsRegistryClient.Register(ctx, defaultRegistryService(t.Name()))
require.NoError(t, err)

var deployNSE = func(name, ns string, labels map[string]string) {
var deployNSE = func(name, ns string, labels map[string]string, ipNet *net.IPNet) {
nseReg := defaultRegistryEndpoint(ns)
nseReg.Name = name

Expand Down Expand Up @@ -238,12 +239,16 @@ func (s *nsmgrSuite) Test_ReselectEndpointWhenNetSvcHasChanged() {
}()

serv := grpc.NewServer()
endpoint.NewServer(ctx, sandbox.GenerateTestToken).Register(serv)
endpoint.NewServer(ctx, sandbox.GenerateTestToken, endpoint.WithAdditionalFunctionality(
point2pointipam.NewServer(ipNet),
)).Register(serv)
_ = serv.Serve(netListener)
}()
}

deployNSE("nse-1", nsReg.Name, map[string]string{})
_, ipNet1, _ := net.ParseCIDR("100.100.100.100/30")
_, ipNet2, _ := net.ParseCIDR("200.200.200.200/30")
deployNSE("nse-1", nsReg.Name, map[string]string{}, ipNet1)
// 3. Create client and request endpoint
nsc := s.domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken)

Expand All @@ -253,6 +258,8 @@ func (s *nsmgrSuite) Test_ReselectEndpointWhenNetSvcHasChanged() {
require.Equal(t, 4, len(conn.Path.PathSegments))
require.Equal(t, "nse-1", conn.GetNetworkServiceEndpointName())
require.NoError(t, ctx.Err())
require.Equal(t, "100.100.100.101/32", conn.Context.GetIpContext().GetSrcIpAddrs()[0])
require.Equal(t, "100.100.100.100/32", conn.Context.GetIpContext().GetDstIpAddrs()[0])

// update netsvc
nsReg.Matches = append(nsReg.Matches, &registry.Match{
Expand All @@ -270,7 +277,7 @@ func (s *nsmgrSuite) Test_ReselectEndpointWhenNetSvcHasChanged() {
// deploye nse-2 that matches with updated svc
deployNSE("nse-2", nsReg.Name, map[string]string{
"experimental": "true",
})
}, ipNet2)
// simulate idle
time.Sleep(time.Second / 2)
// in some moment nsc refresh connection
Expand All @@ -279,8 +286,11 @@ func (s *nsmgrSuite) Test_ReselectEndpointWhenNetSvcHasChanged() {
require.NotNil(t, conn)
require.Equal(t, 4, len(conn.Path.PathSegments))
require.Equal(t, "nse-2", conn.GetNetworkServiceEndpointName())

require.NotEmpty(t, conn.Context.GetIpContext().GetSrcIpAddrs())
require.NotEmpty(t, conn.Context.GetIpContext().GetDstIpAddrs())
require.NoError(t, ctx.Err())
require.Equal(t, "200.200.200.201/32", conn.Context.GetIpContext().GetSrcIpAddrs()[0])
require.Equal(t, "200.200.200.200/32", conn.Context.GetIpContext().GetDstIpAddrs()[0])

// Close
_, err = nsc.Close(ctx, conn)
Expand Down
1 change: 1 addition & 0 deletions pkg/networkservice/common/begin/event_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ func (f *eventFactoryClient) Request(opts ...Option) <-chan error {
if request.GetConnection() != nil {
request.GetConnection().Mechanism = nil
request.GetConnection().NetworkServiceEndpointName = ""
request.GetConnection().Context = nil
request.GetConnection().State = networkservice.State_RESELECT_REQUESTED
}
cancel()
Expand Down

0 comments on commit 915497b

Please sign in to comment.