Skip to content

Commit

Permalink
apply review comments
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 24, 2024
1 parent 7cceff0 commit 9d47fa1
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 13 deletions.
7 changes: 0 additions & 7 deletions pkg/registry/etcd/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@ func nseVersionFromContext(ctx context.Context) (string, bool) {
return version, ok
}

func max(a, b time.Duration) time.Duration {
if a > b {
return a
}
return b
}

func min(a, b time.Duration) time.Duration {
if a > b {
return b
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/etcd/ns_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (n *etcdNSRegistryServer) watchRemoteStorage() {
sleepTime = min(sleepTime, maxSleepTime)
continue
}
sleepTime = max(sleepTime, minSleepTime)
sleepTime = minSleepTime

isWatcherFine := true
for isWatcherFine {
Expand Down
7 changes: 3 additions & 4 deletions pkg/registry/etcd/nse_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (n *etcdNSERegistryServer) watchRemoteStorage() {
sleepTime = min(sleepTime, maxSleepTime)
continue
}
sleepTime = max(sleepTime, minSleepTime)
sleepTime = minSleepTime

isWatcherFine := true
for isWatcherFine {
Expand All @@ -110,15 +110,13 @@ func (n *etcdNSERegistryServer) watchRemoteStorage() {
if item.Name == "" {
item.Name = model.GetName()
}
if v, ok := n.versions.Load(item.Name); ok && v == model.ResourceVersion {
continue
}
resp := &registry.NetworkServiceEndpointResponse{
NetworkServiceEndpoint: item,
Deleted: deleted,
}
n.sendEvent(resp)
if !deleted && item.ExpirationTime != nil && item.ExpirationTime.AsTime().Local().Before(time.Now()) {
n.versions.Delete(item.GetName())
n.deleteExecutor.AsyncExec(func() {
_ = n.client.NetworkservicemeshV1().NetworkServiceEndpoints(n.ns).Delete(n.chainContext, item.GetName(), metav1.DeleteOptions{
Preconditions: &metav1.Preconditions{
Expand Down Expand Up @@ -252,6 +250,7 @@ func (n *etcdNSERegistryServer) Unregister(ctx context.Context, request *registr
if err != nil {
return nil, errors.Wrapf(err, "failed to delete a NetworkServiceEndpoints %s in a namespace %s", request.Name, n.ns)
}
n.versions.Delete(request.GetName())
}
return resp, nil
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/registry/etcd/nse_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,13 @@ func Test_K8sNSERegistry_FindWatch(t *testing.T) {
require.NoError(t, err)
require.Equal(t, "nse-1", nseResp.NetworkServiceEndpoint.Name)

// NSE reregisteration. We shouldn't get any updates
_, err = s.Register(ctx, nse.Clone())
require.NoError(t, err)

nseResp, err = stream.Recv()
require.NoError(t, err)
require.Equal(t, "nse-1", nseResp.NetworkServiceEndpoint.Name)

// Update NSE again - add labels
updatedNSE := nse.Clone()
updatedNSE.NetworkServiceLabels = map[string]*registry.NetworkServiceLabels{"label": {}}
Expand Down

0 comments on commit 9d47fa1

Please sign in to comment.