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 c20c735
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 18 deletions.
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,7 @@ issues:
- goheader
- dupl
- revive
# It's ok to have dupl code in tests files
- path: ".*.test.go"
linters:
- dupl
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
5 changes: 2 additions & 3 deletions pkg/registry/etcd/ns_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func Test_K8sNSRegistry_FindWatch(t *testing.T) {
}, time.Second, time.Millisecond*100)
}

func Test_NSHightloadWatch_ShouldNotFail(t *testing.T) {
func Test_NSHighloadWatch_ShouldNotFail(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
defer cancel()

Expand Down Expand Up @@ -194,9 +194,8 @@ func Test_NSHightloadWatch_ShouldNotFail(t *testing.T) {
Name: uuid.NewString(),
},
}, metav1.CreateOptions{})
time.Sleep(time.Millisecond * 10)
}
}()
doneWg.Wait()
require.Equal(t, updateCount, actual.Load()/clinetCount)
require.InDelta(t, updateCount, actual.Load()/clinetCount, 20)
}
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
9 changes: 6 additions & 3 deletions 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 All @@ -149,7 +152,7 @@ func Test_K8sNSERegistry_FindWatch(t *testing.T) {
require.Equal(t, 1, len(nseResp.GetNetworkServiceEndpoint().NetworkServiceLabels))
}

func Test_NSEHightloadWatch_ShouldNotFail(t *testing.T) {
func Test_NSEHighloadWatch_ShouldNotFail(t *testing.T) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*3)
defer cancel()

Expand Down Expand Up @@ -191,7 +194,7 @@ func Test_NSEHightloadWatch_ShouldNotFail(t *testing.T) {
}
}()
doneWg.Wait()
require.Equal(t, updateCount, actual.Load()/clinetCount)
require.InDelta(t, updateCount, actual.Load()/clinetCount, 20)
}

func Test_K8sNSERegistry_Find_ExpiredNSE(t *testing.T) {
Expand Down

0 comments on commit c20c735

Please sign in to comment.