-
Notifications
You must be signed in to change notification settings - Fork 14
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
fix problem with updating nsm crd resources #527
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ import ( | |
"github.com/networkservicemesh/sdk/pkg/networkservice/ipam/point2pointipam" | ||
"github.com/networkservicemesh/sdk/pkg/networkservice/ipam/strictipam" | ||
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/checks/checkresponse" | ||
"github.com/networkservicemesh/sdk/pkg/networkservice/utils/count" | ||
registryserver "github.com/networkservicemesh/sdk/pkg/registry" | ||
registryclient "github.com/networkservicemesh/sdk/pkg/registry/chains/client" | ||
"github.com/networkservicemesh/sdk/pkg/registry/core/adapters" | ||
|
@@ -400,7 +401,84 @@ func TestNSMGR_InterdomainUseCase(t *testing.T) { | |
_, err = nsc.Close(ctx, conn) | ||
require.NoError(t, err) | ||
} | ||
func TestNSMGR_HealRegistry(t *testing.T) { | ||
t.Cleanup(func() { goleak.VerifyNone(t) }) | ||
|
||
const timeout = time.Second * 5 | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), timeout) | ||
defer cancel() | ||
clientSet := fake.NewSimpleClientset() | ||
|
||
domain := sandbox.NewBuilder(ctx, t). | ||
SetNodesCount(1). | ||
SetRegistrySupplier(supplyK8sRegistryWithClientSet(clientSet)). | ||
SetNSMgrProxySupplier(nil). | ||
SetRegistryProxySupplier(nil). | ||
Build() | ||
|
||
nsRegistryClient := domain.NewNSRegistryClient(ctx, sandbox.GenerateTestToken) | ||
|
||
nsReg, err := nsRegistryClient.Register(ctx, defaultRegistryService(t.Name())) | ||
require.NoError(t, err) | ||
|
||
nseReg := defaultRegistryEndpoint(nsReg.Name) | ||
|
||
counter := new(count.Server) | ||
domain.Nodes[0].NewEndpoint(ctx, nseReg, sandbox.GenerateTestToken, counter) | ||
|
||
request := defaultRequest(nsReg.Name) | ||
|
||
nsc := domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken) | ||
|
||
conn, err := nsc.Request(ctx, request.Clone()) | ||
require.NoError(t, err) | ||
|
||
// 1. Restart Registry | ||
domain.Registry.Restart() | ||
|
||
// 2. Check refresh | ||
request.Connection = conn | ||
_, err = nsc.Request(ctx, request.Clone()) | ||
require.NoError(t, err) | ||
|
||
// 3. Check new client request | ||
nsc = domain.Nodes[0].NewClient(ctx, sandbox.GenerateTestToken) | ||
|
||
_, err = nsc.Request(ctx, request.Clone()) | ||
require.NoError(t, err) | ||
|
||
require.Eventually(t, func() bool { | ||
return counter.Requests() >= 3 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In which case the Request count >3 is acceptable? (the =3 is evident) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the client is using |
||
}, timeout, time.Second/10) | ||
} | ||
|
||
func defaultRegistryService(name string) *registry.NetworkService { | ||
return ®istry.NetworkService{ | ||
Name: name, | ||
} | ||
} | ||
|
||
func defaultRegistryEndpoint(nsName string) *registry.NetworkServiceEndpoint { | ||
return ®istry.NetworkServiceEndpoint{ | ||
Name: "final-endpoint", | ||
NetworkServiceNames: []string{nsName}, | ||
} | ||
} | ||
|
||
func defaultRequest(nsName string) *networkservice.NetworkServiceRequest { | ||
return &networkservice.NetworkServiceRequest{ | ||
MechanismPreferences: []*networkservice.Mechanism{ | ||
{Cls: cls.LOCAL, Type: kernelmech.MECHANISM}, | ||
}, | ||
Connection: &networkservice.Connection{ | ||
Id: uuid.NewString(), | ||
NetworkService: nsName, | ||
Context: &networkservice.ConnectionContext{}, | ||
Labels: make(map[string]string), | ||
}, | ||
} | ||
} | ||
func TestNSMGR_FloatingInterdomainUseCase(t *testing.T) { | ||
t.Cleanup(func() { goleak.VerifyNone(t, ignoreKLogDaemon) }) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -131,7 +131,7 @@ func (n *etcdNSRegistryServer) sendEvent(resp *registry.NetworkServiceResponse) | |
|
||
func (n *etcdNSRegistryServer) Register(ctx context.Context, request *registry.NetworkService) (*registry.NetworkService, error) { | ||
meta := metav1.ObjectMeta{ | ||
GenerateName: "nse-", | ||
GenerateName: "netsvc-", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this change cause compatibility issues during upgrade? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe it's can't produce compatibility issues, it's related to case when applied network service via NSM api without a name. |
||
Name: request.GetName(), | ||
Namespace: n.ns, | ||
} | ||
|
@@ -144,17 +144,18 @@ func (n *etcdNSRegistryServer) Register(ctx context.Context, request *registry.N | |
metav1.CreateOptions{}, | ||
) | ||
|
||
err = errors.Wrapf(err, "failed to create a nse %s in a namespace %s", request.Name, n.ns) | ||
err = errors.Wrapf(err, "failed to create a netsvc %s in a namespace %s", request.Name, n.ns) | ||
|
||
if apierrors.IsAlreadyExists(err) { | ||
nse, nseErr := n.client.NetworkservicemeshV1().NetworkServices(n.ns).Get(ctx, request.GetName(), metav1.GetOptions{}) | ||
netsvc, nseErr := n.client.NetworkservicemeshV1().NetworkServices(n.ns).Get(ctx, request.GetName(), metav1.GetOptions{}) | ||
if nseErr != nil { | ||
err = errors.Wrapf(err, "failed to get a nse %s in a namespace %s, reason: %v", request.Name, n.ns, nseErr.Error()) | ||
err = errors.Wrapf(err, "failed to get a netsvc %s in a namespace %s, reason: %v", request.Name, n.ns, nseErr.Error()) | ||
} | ||
if nse != nil { | ||
_, err = n.client.NetworkservicemeshV1().NetworkServices(n.ns).Update(ctx, nse, metav1.UpdateOptions{}) | ||
if netsvc != nil { | ||
netsvc.Spec = *(*v1.NetworkServiceSpec)(request) | ||
_, err = n.client.NetworkservicemeshV1().NetworkServices(n.ns).Update(ctx, netsvc, metav1.UpdateOptions{}) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "failed to update a pod %s in a namespace %s", nse.Name, n.ns) | ||
return nil, errors.Wrapf(err, "failed to update a pod %s in a namespace %s", netsvc.Name, n.ns) | ||
} | ||
return next.NetworkServiceRegistryServer(ctx).Register(ctx, request) | ||
} | ||
|
@@ -173,14 +174,14 @@ func (n *etcdNSRegistryServer) Find(query *registry.NetworkServiceQuery, s regis | |
} | ||
for i := 0; i < len(items.Items); i++ { | ||
crd := &items.Items[i] | ||
nse := (*registry.NetworkService)(&crd.Spec) | ||
if nse.Name == "" { | ||
nse.Name = items.Items[i].Name | ||
netsvc := (*registry.NetworkService)(&crd.Spec) | ||
if netsvc.Name == "" { | ||
netsvc.Name = items.Items[i].Name | ||
} | ||
if matchutils.MatchNetworkServices(query.NetworkService, nse) { | ||
err := s.Send(®istry.NetworkServiceResponse{NetworkService: nse}) | ||
if matchutils.MatchNetworkServices(query.NetworkService, netsvc) { | ||
err := s.Send(®istry.NetworkServiceResponse{NetworkService: netsvc}) | ||
if err != nil { | ||
return errors.Wrapf(err, "NetworkServiceRegistry find server failed to send a response %s", nse.String()) | ||
return errors.Wrapf(err, "NetworkServiceRegistry find server failed to send a response %s", netsvc.String()) | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I right in understanding that here we test an NSC restart, reconnect with same connection ID?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I can see by default it will generate a new connection id. See at https://github.com/networkservicemesh/sdk/blob/main/pkg/networkservice/chains/client/client.go#L43 -> https://github.com/networkservicemesh/sdk/blob/main/pkg/networkservice/chains/client/client.go#L55