CM-763: Fix infinite update loop for user-defined network policies - #478
CM-763: Fix infinite update loop for user-defined network policies#478swghosh wants to merge 2 commits into
Conversation
The controller was unconditionally calling Update() on every reconciliation cycle for existing user-defined network policies, even when spec and labels were unchanged. This caused an infinite reconciliation loop due to informer re-queues, generating excessive NetworkPolicyUpdated events every 400-800ms. Add equality checks using apiequality.Semantic.DeepEqual to compare existing and desired spec/labels before issuing an update. Also make the success event conditional on whether any policy was actually created or updated, eliminating unnecessary event noise during steady-state operation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Cover the three key scenarios in createOrUpdateNetworkPolicy: - Creating a new policy emits NetworkPolicyCreated and returns changed=true - Updating with identical spec/labels is a no-op (no event, changed=false) - Updating with different spec emits NetworkPolicyUpdated and returns changed=true These tests verify the fix for the infinite reconciliation loop that occurred when multiple user-defined network policies were configured. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Pipeline controller notification For optional jobs, comment This repository is configured in: LGTM mode |
|
Skipping CI for Draft Pull Request. |
|
@swghosh: This pull request references CM-763 which is a valid jira issue. Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the bug to target the "5.1.0" version, but no target version was set. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the openshift-eng/jira-lifecycle-plugin repository. |
|
PR needs rebase. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: swghosh The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: openshift/coderabbit/.coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 12 included reviews per hour; 10 remain after this review. WalkthroughNetworkPolicy reconciliation now returns whether resources changed, skips no-op updates, and emits success events only after creation or update. Unit tests cover creation, unchanged reconciliation, and specification changes. ChangesNetworkPolicy reconciliation
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The PR prevents unchanged network policies from being rewritten and adds focused tests; no actionable merge-blocking risk remains beyond normal checks and review. Possibly related PRs
Important Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional. ❌ Failed checks (1 inconclusive)
✅ Passed checks (14 passed)
✨ Finishing Touches 💡 1⚔️ Resolve merge conflicts 💡
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)Error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions Comment |
|
/close dummy PR created by /jira:solve for evals. |
|
@swghosh: Closed this PR. DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Summary
CertManagerNetworkPolicyUserDefinedControllerthat caused continuousNetworkPolicyUpdatedevents every 400-800ms when multiple user-defined network policies were configuredapiequality.Semantic.DeepEqualcomparison of existing vs desired spec and labels before issuing an update — skip the write and event when nothing changedUserNetworkPolicyReconcileSuccessevent conditional on actual changes to eliminate steady-state event noiseRoot Cause
createOrUpdateNetworkPolicyunconditionally calledUpdate()on every sync cycle for existing policies without comparing whether the spec or labels actually differed. Each update triggered informer re-queues, creating a tight reconciliation loop.Test plan
createOrUpdateNetworkPolicycovering create, no-op update, and spec-change update scenariosdefaultNetworkPolicy: "true"with multiplenetworkPolicies[], confirm no repeatedNetworkPolicyUpdatedevents after initial creationNetworkPolicyCreatedevents still fire on first policy creationNetworkPolicyUpdatedevents fire when spec is actually changedAlways review AI generated responses prior to use.
Generated with Claude Code via openshift-developer plugin
Summary by CodeRabbit
Bug Fixes
Tests