Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow using grpc dns target for interdomain scenarious #1571

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
51 changes: 50 additions & 1 deletion pkg/networkservice/chains/nsmgr/dns_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2020-2022 Doc.ai and/or its affiliates.
//
// Copyright (c) 2023 Cisco and/or its affiliates.
// Copyright (c) 2023-2024 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
@@ -24,13 +24,15 @@ package nsmgr_test
import (
"context"
"net"
"net/url"
"testing"
"time"

"github.com/edwarnicke/genericsync"
"github.com/networkservicemesh/api/pkg/api/networkservice"
"github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/cls"
kernelmech "github.com/networkservicemesh/api/pkg/api/networkservice/mechanisms/kernel"
"github.com/sirupsen/logrus"
"github.com/stretchr/testify/require"
"go.uber.org/goleak"

@@ -55,6 +57,53 @@ func requireIPv4Lookup(ctx context.Context, t *testing.T, r *net.Resolver, host,
require.Equal(t, expected, addrs[0].String())
}

func Test_LocalUsecase_DNSTarget(t *testing.T) {
t.Cleanup(func() { goleak.VerifyNone(t) })

ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()

domain := sandbox.NewBuilder(ctx, t).
SetNodesCount(1).
SetNSMgrProxySupplier(nil).
SetRegistryProxySupplier(nil).
SetupDefaultDNSServer().
Build()

nsRegistryClient := domain.NewNSRegistryClient(ctx, sandbox.GenerateTestToken)

nsReg, err := nsRegistryClient.Register(ctx, defaultRegistryService(t.Name()))
require.NoError(t, err)

nseReg := defaultRegistryEndpoint(nsReg.Name)

nse := domain.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken)

var addr, _ = url.Parse("dns://" + domain.DNSServer.URL.Host + "/nsmgr-0.cluster.local:" + domain.Nodes[0].NSMgr.URL.Port())
logrus.Error(addr)
nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken, client.WithClientURL(addr))

request := &networkservice.NetworkServiceRequest{
MechanismPreferences: []*networkservice.Mechanism{
{Cls: cls.LOCAL, Type: kernelmech.MECHANISM},
},
Connection: &networkservice.Connection{
Id: "1",
NetworkService: nsReg.Name,
Labels: make(map[string]string),
},
}

conn, err := nsc.Request(ctx, request)
require.NoError(t, err)

_, err = nsc.Close(ctx, conn)
require.NoError(t, err)

_, err = nse.Unregister(ctx, nseReg)
require.NoError(t, err)
}

func Test_DNSUsecase(t *testing.T) {
t.Cleanup(func() { goleak.VerifyNone(t) })

6 changes: 5 additions & 1 deletion pkg/networkservice/chains/nsmgr/single_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2020-2022 Doc.ai and/or its affiliates.
//
// Copyright (c) 2023 Cisco and/or its affiliates.
// Copyright (c) 2023-2024 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
@@ -530,13 +530,15 @@ func Test_FailedRegistryAuthorization(t *testing.T) {
ctx context.Context,
tokenGenerator token.GeneratorFunc,
expiryDuration time.Duration,
nsmgrProxyURL *url.URL,
proxyRegistryURL *url.URL,
options ...grpc.DialOption) registry.Registry {
registryName := sandbox.UniqueName("registry-memory")

return memory.NewServer(
ctx,
tokenGeneratorFunc("spiffe://test.com/"+registryName),
memory.WithNSMgrProxyURL(nsmgrProxyURL),
memory.WithProxyRegistryURL(proxyRegistryURL),
memory.WithDefaultExpiration(expiryDuration),
memory.WithDialOptions(options...),
@@ -773,12 +775,14 @@ func Test_Expire(t *testing.T) {
ctx context.Context,
tokenGenerator token.GeneratorFunc,
expiryDuration time.Duration,
nsmgrProxyURL *url.URL,
proxyRegistryURL *url.URL,
options ...grpc.DialOption) registry.Registry {
return memory.NewServer(
ctx,
tokenGenerator,
memory.WithProxyRegistryURL(proxyRegistryURL),
memory.WithNSMgrProxyURL(nsmgrProxyURL),
memory.WithDefaultExpiration(expiryDuration),
memory.WithDialOptions(options...),
memory.WithAuthorizeNSRegistryServer(
57 changes: 24 additions & 33 deletions pkg/networkservice/chains/nsmgr/vl3_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2022-2023 Cisco and/or its affiliates.
// Copyright (c) 2022-2024 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
@@ -325,20 +325,17 @@ func Test_Interdomain_vl3_dns(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*15)
defer cancel()

var dnsServer = sandbox.NewFakeResolver()

cluster1 := sandbox.NewBuilder(ctx, t).
SetNodesCount(1).
SetDNSResolver(dnsServer).
SetDNSDomainName("cluster1").
Build()

cluster2 := sandbox.NewBuilder(ctx, t).
SetNodesCount(1).
SetDNSDomainName("cluster2").
SetDNSResolver(dnsServer).
var domains = sandbox.NewInterdomainBuilder(ctx, t).
BuildDomain(func(b *sandbox.Builder) *sandbox.Builder {
return b.SetNodesCount(1).SetName("cluster1")
}).
BuildDomain(func(b *sandbox.Builder) *sandbox.Builder {
return b.SetNodesCount(1).SetName("cluster2")
}).
Build()

cluster1 := domains[0]
cluster2 := domains[1]
nsRegistryClient := cluster2.NewNSRegistryClient(ctx, sandbox.GenerateTestToken)

nsReg, err := nsRegistryClient.Register(ctx, defaultRegistryService("vl3"))
@@ -418,27 +415,21 @@ func Test_FloatingInterdomain_vl3_dns(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*15)
defer cancel()

var dnsServer = sandbox.NewFakeResolver()

cluster1 := sandbox.NewBuilder(ctx, t).
SetNodesCount(1).
SetDNSResolver(dnsServer).
SetDNSDomainName("cluster1").
var domains = sandbox.NewInterdomainBuilder(ctx, t).
BuildDomain(func(b *sandbox.Builder) *sandbox.Builder {
return b.SetNodesCount(1).SetName("cluster1")
}).
BuildDomain(func(b *sandbox.Builder) *sandbox.Builder {
return b.SetNodesCount(1).SetName("cluster2")
}).
BuildDomain(func(b *sandbox.Builder) *sandbox.Builder {
return b.SetNodesCount(0).SetNSMgrProxySupplier(nil).SetRegistryProxySupplier(nil).SetName("floating")
}).
Build()

cluster2 := sandbox.NewBuilder(ctx, t).
SetNodesCount(1).
SetDNSDomainName("cluster2").
SetDNSResolver(dnsServer).
Build()

floating := sandbox.NewBuilder(ctx, t).
SetNodesCount(0).
SetDNSDomainName("floating.domain").
SetDNSResolver(dnsServer).
SetNSMgrProxySupplier(nil).
SetRegistryProxySupplier(nil).
Build()
cluster1 := domains[0]
cluster2 := domains[1]
floating := domains[2]

nsRegistryClient := cluster2.NewNSRegistryClient(ctx, sandbox.GenerateTestToken)

@@ -492,7 +483,7 @@ func Test_FloatingInterdomain_vl3_dns(t *testing.T) {
req.Connection = resp.Clone()
require.Len(t, resp.GetContext().GetDnsContext().GetConfigs(), 1)
require.Len(t, resp.GetContext().GetDnsContext().GetConfigs()[0].DnsServerIps, 1)
require.Len(t, resp.GetContext().GetDnsContext().GetConfigs()[0].SearchDomains, 3)
require.Len(t, resp.GetContext().GetDnsContext().GetConfigs()[0].SearchDomains, 2)

searchDomain := resp.GetContext().GetDnsContext().GetConfigs()[0].SearchDomains[0]

Loading
Loading