From b1d0fde370ae409ff028c557c6a60ff69491e499 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Tyczy=C5=84ski?= Date: Wed, 3 Nov 2021 15:02:51 +0100 Subject: [PATCH] P&F fix watch tracker bug --- .../apiserver/pkg/util/flowcontrol/watch_tracker.go | 2 +- .../apiserver/pkg/util/flowcontrol/watch_tracker_test.go | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/staging/src/k8s.io/apiserver/pkg/util/flowcontrol/watch_tracker.go b/staging/src/k8s.io/apiserver/pkg/util/flowcontrol/watch_tracker.go index 5c64c702c1b..e4ebb21459b 100644 --- a/staging/src/k8s.io/apiserver/pkg/util/flowcontrol/watch_tracker.go +++ b/staging/src/k8s.io/apiserver/pkg/util/flowcontrol/watch_tracker.go @@ -175,7 +175,7 @@ func (w *watchTracker) updateIndexLocked(identifier *watchIdentifier, index *ind // This seem to be true in almost all production clusters, which makes // it a reasonable first step simplification to unblock progres on it. if index.value == unsetValue || index.value == "" { - w.watchCount[*identifier]++ + w.watchCount[*identifier] += incr } } } diff --git a/staging/src/k8s.io/apiserver/pkg/util/flowcontrol/watch_tracker_test.go b/staging/src/k8s.io/apiserver/pkg/util/flowcontrol/watch_tracker_test.go index 0c5ba72544c..ba95ecbbec5 100644 --- a/staging/src/k8s.io/apiserver/pkg/util/flowcontrol/watch_tracker_test.go +++ b/staging/src/k8s.io/apiserver/pkg/util/flowcontrol/watch_tracker_test.go @@ -91,6 +91,11 @@ func TestRegisterWatch(t *testing.T) { request: httpRequest("GET", "/apis/group/v1/namespaces/foo/pods", "watch=true&fieldSelector=metadata.name=mypod"), expected: newWatchIdentifier("group", "pods", "foo", "mypod"), }, + { + name: "watch indexed object", + request: httpRequest("GET", "/apis/group/v1/namespaces/foo/pods", "watch=true&fieldSelector=spec.nodeName="), + expected: newWatchIdentifier("group", "pods", "foo", ""), + }, } requestInfoFactory := &request.RequestInfoFactory{ @@ -101,6 +106,7 @@ func TestRegisterWatch(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.name, func(t *testing.T) { watchTracker := &watchTracker{ + indexes: getBuiltinIndexes(), watchCount: make(map[watchIdentifier]int), } @@ -265,7 +271,7 @@ func TestGetInterestedWatchCountWithIndex(t *testing.T) { httpRequest("GET", "api/v1/pods", "watch=true"), httpRequest("GET", "api/v1/namespaces/foo/pods", "watch=true"), httpRequest("GET", "api/v1/namespaces/foo/pods", "watch=true&fieldSelector=metadata.name=mypod"), - httpRequest("GET", "api/v1/namespaces/foo/pods", "watch=true&fieldSelector=spec.nodeName"), + httpRequest("GET", "api/v1/namespaces/foo/pods", "watch=true&fieldSelector=spec.nodeName="), // The watches below will be ignored due to index. httpRequest("GET", "api/v1/namespaces/foo/pods", "watch=true&fieldSelector=spec.nodeName=node1"), httpRequest("GET", "api/v1/namespaces/foo/pods", "watch=true&fieldSelector=spec.nodeName=node2"),