Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Tingaikin <denis.tingajkin@xored.com>
  • Loading branch information
denis-tingaikin committed Sep 4, 2022
1 parent 72783c8 commit 3236153
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
24 changes: 17 additions & 7 deletions pkg/registry/etcd/ns_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"errors"
"io"
"sync"
"time"

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

Expand Down Expand Up @@ -84,6 +86,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 +172,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
24 changes: 18 additions & 6 deletions pkg/registry/etcd/nse_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"errors"
"io"
"sync"
"time"

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

Expand Down Expand Up @@ -86,6 +88,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 +123,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

0 comments on commit 3236153

Please sign in to comment.