From f784f4a1fcb21f9fe77ce7e9875b82a5f19597b6 Mon Sep 17 00:00:00 2001 From: Piotr Rygielski <114479+vikin91@users.noreply.github.com> Date: Tue, 24 Mar 2026 15:27:33 +0100 Subject: [PATCH] ROX-33757: Fix moving to history in clusterentities store (#19565) (cherry picked from commit a6eb641506bb2049b898fc1cacbede62cafd8b85) --- .../common/clusterentities/store_endpoints.go | 13 +++---- .../clusterentities/store_endpoints_test.go | 38 +++++++++++++++++++ 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/sensor/common/clusterentities/store_endpoints.go b/sensor/common/clusterentities/store_endpoints.go index 00ecf7e36aa9f..802dd56d082b1 100644 --- a/sensor/common/clusterentities/store_endpoints.go +++ b/sensor/common/clusterentities/store_endpoints.go @@ -121,11 +121,7 @@ func (e *endpointsStore) purgeNoLock(deploymentID string) { // so let's make a temporary copy. endpointsSet := e.reverseEndpointMap[deploymentID] for ep := range endpointsSet { - if e.historyEnabled() { - e.moveToHistory(deploymentID, ep) - } else { - e.deleteFromCurrent(deploymentID, ep) - } + e.moveToHistory(deploymentID, ep) } } @@ -216,9 +212,12 @@ func (e *endpointsStore) removeFromHistoryIfExpired(deploymentID string, ep net. return false } -// moveToHistory is a convenience function that removes data from the current map and adds it to history +// moveToHistory is a convenience function that removes data from the current map and adds it to history. +// If history is disabled, it just deletes the data from the current map. func (e *endpointsStore) moveToHistory(deploymentID string, ep net.NumericEndpoint) { - e.addToHistory(deploymentID, ep) + if e.historyEnabled() { + e.addToHistory(deploymentID, ep) + } e.deleteFromCurrent(deploymentID, ep) } diff --git a/sensor/common/clusterentities/store_endpoints_test.go b/sensor/common/clusterentities/store_endpoints_test.go index dcf43fe36308f..ea523b4b028c2 100644 --- a/sensor/common/clusterentities/store_endpoints_test.go +++ b/sensor/common/clusterentities/store_endpoints_test.go @@ -248,6 +248,44 @@ func (s *ClusterEntitiesStoreTestSuite) TestMemoryAboutPastEndpoints() { }, }, }, + "IP changing owner with memory disabled should not retain previous deployment in history": { + numTicksToRemember: 0, + entityUpdates: map[int][]eUpdate{ + 0: { + { + deploymentID: "depl1", + containerID: "pod1", + ipAddr: "10.0.0.1", + port: 80, + portName: "http", + incremental: true, + }, + }, + 2: { + { + deploymentID: "depl2", + containerID: "pod2", + ipAddr: "10.0.0.1", + port: 80, + portName: "http", + incremental: false, // overwrite + }, + }, + }, + operationAfterTick: map[int]operation{}, + lookupResultsAfterTick: map[int][]expectation{ + 0: {expectDeployment80("10.0.0.1", "depl1", "http", theMap)}, + 1: {expectDeployment80("10.0.0.1", "depl1", "http", theMap)}, + 2: { + expectDeployment80("10.0.0.1", "depl1", "http", nowhere), + expectDeployment80("10.0.0.1", "depl2", "http", theMap), + }, + 3: { + expectDeployment80("10.0.0.1", "depl1", "http", nowhere), + expectDeployment80("10.0.0.1", "depl2", "http", theMap), + }, + }, + }, } for name, tCase := range cases { s.Run(name, func() {