Skip to content

fix: skip source namespace in replicate-to-matching#422

Merged
elenz97 merged 1 commit into
mittwald:masterfrom
mcastellini:fix/self-replication-matching-loop
Jul 7, 2026
Merged

fix: skip source namespace in replicate-to-matching#422
elenz97 merged 1 commit into
mittwald:masterfrom
mcastellini:fix/self-replication-matching-loop

Conversation

@mcastellini

Copy link
Copy Markdown
Contributor

Problem

When a replicate-to-matching label selector also matches the source object's own namespace, the replicator copies the resource onto itself. That write updates the source object, which re-triggers the informer and produces an unbounded reconciliation loop — continuous writes that hammer the kube-apiserver. (In our case the looping objects were TLS secrets watched by an ingress controller, which rebuilt and revalidated its entire data plane on every write and pinned its CPU.)

The replicate-to (namespace pattern) strategy already guards against this in getNamespacesToReplicate:

if namespace.Name == myNs {
    // Don't replicate upon itself
    continue
}

…but the replicate-to-matching (label selector) strategy lists namespaces straight from the API and passes them through unfiltered, so the source's own namespace can end up as a target.

Fix

Apply the same self-skip in replicateResourceToMatchingNamespacesByLabel: filter the source namespace out of the selector-matched list before replicating.

Tests

Adds two regression tests in replicate/secret:

  • replicate-to-matching self-match — fails without this change, passes with it.
  • replicate-to pattern self-match — exercises the pre-existing guard, which had no coverage.

Both verified against a kind cluster; the full replicate/secret suite passes.

Fixes #407

Mirrors the existing self-skip in the replicate-to path so a selector
that matches the source's own namespace no longer loops. Adds regression
tests for both strategies.
@mcastellini

Copy link
Copy Markdown
Contributor Author

@elenz97, any chance you can look at this fix?

@elenz97 elenz97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looking good, thank you for looking into this @mcastellini!

@elenz97
elenz97 merged commit 44dc6db into mittwald:master Jul 7, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Infinite reconciliation loop for secrets causing high kube-apiserver load

2 participants