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

fix: multiple k8s-registries lead to NSE flapping #385

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
26 changes: 19 additions & 7 deletions pkg/registry/etcd/ns_server.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) 2020-2021 Doc.ai and/or its affiliates.
//
// Copyright (c) 2022 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -20,6 +22,7 @@ import (
"context"
"errors"
"io"
"sync"
"time"

"github.com/golang/protobuf/ptypes/empty"
Expand All @@ -39,6 +42,7 @@ import (
type etcdNSRegistryServer struct {
chainContext context.Context
client versioned.Interface
versions sync.Map
ns string
}

Expand Down Expand Up @@ -84,6 +88,8 @@ func (n *etcdNSRegistryServer) Register(ctx context.Context, request *registry.N
apiResp.Spec.DeepCopyInto((*v1.NetworkServiceSpec)(request))
request.Name = apiResp.Name

n.versions.Store(apiResp.Spec.Name, apiResp.ResourceVersion)

return (*registry.NetworkService)(&apiResp.Spec), nil
}

Expand Down Expand Up @@ -168,13 +174,19 @@ func (n *etcdNSRegistryServer) Unregister(ctx context.Context, request *registry
if err != nil {
return nil, err
}
err = n.client.NetworkservicemeshV1().NetworkServices(n.ns).Delete(
ctx,
request.Name,
metav1.DeleteOptions{},
)
if err != nil {
return nil, err
if v, ok := n.versions.Load(request.Name); ok {
version := v.(string)
err = n.client.NetworkservicemeshV1().NetworkServices(n.ns).Delete(
ctx,
request.Name,
metav1.DeleteOptions{
Preconditions: &metav1.Preconditions{
ResourceVersion: &version,
},
})
if err != nil {
return nil, err
}
}
return resp, nil
}
Expand Down
26 changes: 20 additions & 6 deletions pkg/registry/etcd/nse_server.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
// Copyright (c) 2020-2021 Doc.ai and/or its affiliates.
//
// Copyright (c) 2022 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -20,6 +22,7 @@ import (
"context"
"errors"
"io"
"sync"
"time"

"github.com/golang/protobuf/ptypes/empty"
Expand All @@ -39,6 +42,7 @@ import (
type etcdNSERegistryServer struct {
chainContext context.Context
client versioned.Interface
versions sync.Map
ns string
}

Expand Down Expand Up @@ -86,6 +90,8 @@ func (n *etcdNSERegistryServer) Register(ctx context.Context, request *registry.
return nil, err
}

n.versions.Store(apiResp.Spec.Name, apiResp.ResourceVersion)

return (*registry.NetworkServiceEndpoint)(&apiResp.Spec), nil
}

Expand Down Expand Up @@ -119,12 +125,20 @@ func (n *etcdNSERegistryServer) Unregister(ctx context.Context, request *registr
if err != nil {
return nil, err
}
err = n.client.NetworkservicemeshV1().NetworkServiceEndpoints(n.ns).Delete(
ctx,
request.Name,
metav1.DeleteOptions{})
if err != nil {
return nil, err

if v, ok := n.versions.Load(request.Name); ok {
version := v.(string)
err = n.client.NetworkservicemeshV1().NetworkServiceEndpoints(n.ns).Delete(
ctx,
request.Name,
metav1.DeleteOptions{
Preconditions: &metav1.Preconditions{
ResourceVersion: &version,
},
})
if err != nil {
return nil, err
}
}
return resp, nil
}
Expand Down