From f3831c9af01e7b777376c6aa7a53d811524a8693 Mon Sep 17 00:00:00 2001 From: ck319 Date: Wed, 1 Mar 2023 19:03:18 -0600 Subject: [PATCH 1/4] do not refresh endpoints if pod cache is empty --- npm/pkg/dataplane/dataplane.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/npm/pkg/dataplane/dataplane.go b/npm/pkg/dataplane/dataplane.go index 995b6a11ce..6e9e8bd3ad 100644 --- a/npm/pkg/dataplane/dataplane.go +++ b/npm/pkg/dataplane/dataplane.go @@ -216,6 +216,11 @@ func (dp *DataPlane) ApplyDataPlane() error { // NOTE: ideally we won't refresh Pod Endpoints if the updatePodCache is empty if dp.shouldUpdatePod() { + // do not refresh endpoints if the updatePodCache is empty + if len(dp.updatePodCache.cache) == 0 { + return nil + } + err := dp.refreshPodEndpoints() if err != nil { metrics.SendErrorLogAndMetric(util.DaemonDataplaneID, "[DataPlane] failed to refresh endpoints while updating pods. err: [%s]", err.Error()) From e0d20894a3e17615f0d8e9b99751d7561aaf3a83 Mon Sep 17 00:00:00 2001 From: Cristina Kovacs Date: Thu, 2 Mar 2023 10:11:50 -0600 Subject: [PATCH 2/4] moved cache lock up --- npm/pkg/dataplane/dataplane.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/npm/pkg/dataplane/dataplane.go b/npm/pkg/dataplane/dataplane.go index 6e9e8bd3ad..831275cf16 100644 --- a/npm/pkg/dataplane/dataplane.go +++ b/npm/pkg/dataplane/dataplane.go @@ -216,6 +216,11 @@ func (dp *DataPlane) ApplyDataPlane() error { // NOTE: ideally we won't refresh Pod Endpoints if the updatePodCache is empty if dp.shouldUpdatePod() { + // lock updatePodCache while driving goal state to kernel + // prevents another ApplyDataplane call from updating the same pods + dp.updatePodCache.Lock() + defer dp.updatePodCache.Unlock() + // do not refresh endpoints if the updatePodCache is empty if len(dp.updatePodCache.cache) == 0 { return nil @@ -228,11 +233,6 @@ func (dp *DataPlane) ApplyDataPlane() error { return nil } - // lock updatePodCache while driving goal state to kernel - // prevents another ApplyDataplane call from updating the same pods - dp.updatePodCache.Lock() - defer dp.updatePodCache.Unlock() - for podKey, pod := range dp.updatePodCache.cache { err := dp.updatePod(pod) if err != nil { From a9c6e0127411d6722369bfa113134c60f9abde1f Mon Sep 17 00:00:00 2001 From: Cristina Kovacs Date: Thu, 2 Mar 2023 15:48:58 -0600 Subject: [PATCH 3/4] reposition cache lock --- npm/pkg/dataplane/dataplane.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/npm/pkg/dataplane/dataplane.go b/npm/pkg/dataplane/dataplane.go index 831275cf16..509e37be96 100644 --- a/npm/pkg/dataplane/dataplane.go +++ b/npm/pkg/dataplane/dataplane.go @@ -216,15 +216,13 @@ func (dp *DataPlane) ApplyDataPlane() error { // NOTE: ideally we won't refresh Pod Endpoints if the updatePodCache is empty if dp.shouldUpdatePod() { - // lock updatePodCache while driving goal state to kernel - // prevents another ApplyDataplane call from updating the same pods - dp.updatePodCache.Lock() - defer dp.updatePodCache.Unlock() - // do not refresh endpoints if the updatePodCache is empty - if len(dp.updatePodCache.cache) == 0 { + dp.updatePodCache.Lock() + if len(dp.updatePodCache.cache) != 0 { + dp.updatePodCache.Unlock() return nil } + dp.updatePodCache.Unlock() err := dp.refreshPodEndpoints() if err != nil { @@ -233,6 +231,11 @@ func (dp *DataPlane) ApplyDataPlane() error { return nil } + // lock updatePodCache while driving goal state to kernel + // prevents another ApplyDataplane call from updating the same pods + dp.updatePodCache.Lock() + defer dp.updatePodCache.Unlock() + for podKey, pod := range dp.updatePodCache.cache { err := dp.updatePod(pod) if err != nil { From 5e6e5b14e84b598ab664ad29be2ab3598a98f542 Mon Sep 17 00:00:00 2001 From: ck319 Date: Fri, 3 Mar 2023 16:54:54 -0600 Subject: [PATCH 4/4] fixed incorrect logic --- npm/pkg/dataplane/dataplane.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/npm/pkg/dataplane/dataplane.go b/npm/pkg/dataplane/dataplane.go index 509e37be96..55a60e340a 100644 --- a/npm/pkg/dataplane/dataplane.go +++ b/npm/pkg/dataplane/dataplane.go @@ -218,7 +218,7 @@ func (dp *DataPlane) ApplyDataPlane() error { if dp.shouldUpdatePod() { // do not refresh endpoints if the updatePodCache is empty dp.updatePodCache.Lock() - if len(dp.updatePodCache.cache) != 0 { + if len(dp.updatePodCache.cache) == 0 { dp.updatePodCache.Unlock() return nil }