Skip to content

k8s: StateDB reflector's TransformMany to return objects to delete #39330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

joamaki
Copy link
Contributor

@joamaki joamaki commented May 5, 2025

This fixes the issue #38621 by changing the TransformMany in the StateDB reflector to also return the objects that should be deleted.

Additionally adding a script test suite to pkg/dynamicconfig to verify that the issue has been solved and lsolving a flaky test that I encountered.

@joamaki joamaki requested review from ovidiutirla and jshr-w May 5, 2025 10:34
@maintainer-s-little-helper maintainer-s-little-helper bot added the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label May 5, 2025
@joamaki joamaki added the release-note/misc This PR makes changes that have no direct user impact. label May 5, 2025
@maintainer-s-little-helper maintainer-s-little-helper bot removed the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label May 5, 2025
@joamaki joamaki added the backport/author The backport will be carried out by the author of the PR. label May 5, 2025
@joamaki
Copy link
Contributor Author

joamaki commented May 5, 2025

Marking with backport/author and wil partially backport this to v1.17 (not quite sure if the script tests are backportable yet).

@joamaki joamaki added the needs-backport/1.17 This PR / issue needs backporting to the v1.17 branch label May 6, 2025
@joamaki
Copy link
Contributor Author

joamaki commented May 6, 2025

/test

@joamaki joamaki force-pushed the pr/joamaki/k8s-statedb-reflector-fix-transformmany branch from e779c2a to 21e49a2 Compare May 8, 2025 10:12
@joamaki joamaki marked this pull request as ready for review May 8, 2025 10:13
@joamaki joamaki requested review from a team as code owners May 8, 2025 10:13
@joamaki joamaki requested a review from marseel May 8, 2025 10:13
@joamaki joamaki force-pushed the pr/joamaki/k8s-statedb-reflector-fix-transformmany branch from 21e49a2 to 9e950b5 Compare May 8, 2025 12:17
@joamaki
Copy link
Contributor Author

joamaki commented May 9, 2025

/test

@joamaki joamaki force-pushed the pr/joamaki/k8s-statedb-reflector-fix-transformmany branch from 9e950b5 to 8167498 Compare May 9, 2025 11:11
@joamaki
Copy link
Contributor Author

joamaki commented May 12, 2025

/test

Copy link
Contributor

@marseel marseel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks!

joamaki added 4 commits May 12, 2025 12:13
Use the DecodeKubernetesObject as fallback in  DecodeObject. This way
we can decode core objects that don't have a slim counterpart without
having to separately use DecodeKubernetestObject.

Signed-off-by: Jussi Maki <jussi@isovalent.com>
TransformMany only worked for cases where an object had a static
mapping from 1 to many objects that did not change over the lifetime
of the object. This was not how it was used by pkg/dynamicconfig where
the mapping changed depending on the contents of the object.

To support this use-case change TransformMany to return a set of objects
to insert and set of objects to delete.

Fixes: cilium#38621
Fixes: 3ae0b14 ("k8s: Support multiple objects to be returned by reflector transform")
Signed-off-by: Jussi Maki <jussi@isovalent.com>
Add a script test suite with test cases to verify that the
previous commit fixes the issue of removed keys actually
being deleted from the table.

Issue: cilium#39303
Signed-off-by: Jussi Maki <jussi@isovalent.com>
The test case uses multiple reflectors for ConfigMap which is
problematic as the k8s fake client uses a single channel for events
and thus with multiple watchers events get lost:

  $ go test -c
  $ stress -count 1000 ./dynamicconfig.test -test.run TestDynamicConfigMap
  /tmp/go-stress-20250508T120956-1349213616
  --- FAIL: TestDynamicConfigMap (2.02s)
  --- FAIL: TestDynamicConfigMap/default (2.01s)
  logger.go:256: time=2025-05-08T12:09:57.194+02:00 level=INFO source=/home/jussi/go/src/github.com/cilium/cilium/vendor/github.com/cilium/hive/hive.go:357 msg="Starting hive"
  logger.go:256: time=2025-05-08T12:09:57.194+02:00 level=INFO source=/home/jussi/go/src/github.com/cilium/cilium/vendor/github.com/cilium/hive/hive.go:361 msg="Started hive" duration=59.227µs
  logger.go:256: time=2025-05-08T12:09:57.198+02:00 level=WARN source=/home/jussi/go/src/github.com/cilium/cilium/pkg/k8s/client/fake.go:501 msg="Multiple watches for resource intercepted. This highlights a potential cause for flakes" module=k8s-fake-client resource=v1.configmaps
  table_test.go:189: waiting for confing table: timeout reached while waiting for condition

Fix the test by not starting the Hive until after the ConfigMap
objects have been created. This way no Watch events are created
and we get all the objects with the initial List().

  $ ,stress -count 10000 ./dynamicconfig.test -test.run TestDynamicConfigMap
  33s: 10000 runs total, 0 failures

Signed-off-by: Jussi Maki <jussi@isovalent.com>
@joamaki joamaki force-pushed the pr/joamaki/k8s-statedb-reflector-fix-transformmany branch from 8167498 to 44d86cd Compare May 12, 2025 10:13
@joamaki
Copy link
Contributor Author

joamaki commented May 12, 2025

/test

@joamaki joamaki enabled auto-merge May 12, 2025 16:57
@joamaki joamaki added this pull request to the merge queue May 12, 2025
Merged via the queue into cilium:main with commit f9f7358 May 12, 2025
66 checks passed
@joamaki joamaki deleted the pr/joamaki/k8s-statedb-reflector-fix-transformmany branch May 12, 2025 18:16
@julianwiedmann julianwiedmann added backport-done/1.17 The backport for Cilium 1.17.x for this PR is done. and removed needs-backport/1.17 This PR / issue needs backporting to the v1.17 branch labels May 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/author The backport will be carried out by the author of the PR. backport-done/1.17 The backport for Cilium 1.17.x for this PR is done. release-note/misc This PR makes changes that have no direct user impact.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants