MCO-2153: Add drift protection tests for NetworkPolicies#6155
MCO-2153: Add drift protection tests for NetworkPolicies#6155HarshwardhanPatil07 wants to merge 1 commit into
Conversation
Add unit tests verifying that user modifications and deletions of NetworkPolicies are reverted by the sync loop: - DriftProtection: manual spec modification is reverted on resync - Idempotent: repeated syncs produce stable policy count - DeletionRecreation: single policy deletion triggers re-creation - AllDeletedRecreation: bulk deletion of all static policies - MOBDeletionRecreation: conditional MOB policy deletion Signed-off-by: HarshwardhanPatil07 <harshpat@redhat.com>
|
Pipeline controller notification For optional jobs, comment This repository is configured in: LGTM mode |
|
@HarshwardhanPatil07: This pull request references MCO-2153 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 story to target the "5.0.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. |
WalkthroughThis PR introduces a new test file ChangesNetworkPolicy sync behavior tests
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 13 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (13 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: HarshwardhanPatil07 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
pkg/operator/network_policy_drift_test.go (1)
22-23: 💤 Low valueConsider using
context.Background()instead ofcontext.TODO().While
context.TODO()is acceptable in test code, usingcontext.Background()would be more semantically correct for test operations that don't require a specific parent context. Alternatively, considercontext.WithTimeout()to prevent tests from hanging if operations block unexpectedly.♻️ Example refactor
- policy, err := optr.kubeClient.NetworkingV1().NetworkPolicies(ctrlcommon.MCONamespace).Get( - context.TODO(), "allow-machine-config-operator", metav1.GetOptions{}) + ctx := context.Background() + policy, err := optr.kubeClient.NetworkingV1().NetworkPolicies(ctrlcommon.MCONamespace).Get( + ctx, "allow-machine-config-operator", metav1.GetOptions{})Or with timeout:
+ ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() policy, err := optr.kubeClient.NetworkingV1().NetworkPolicies(ctrlcommon.MCONamespace).Get( - context.TODO(), "allow-machine-config-operator", metav1.GetOptions{}) + ctx, "allow-machine-config-operator", metav1.GetOptions{})Also applies to: 27-28, 31-32, 39-40
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@pkg/operator/network_policy_drift_test.go` around lines 22 - 23, Replace the use of context.TODO() in the network policy test calls with a more appropriate context: use context.Background() for simple test operations or, preferably, context.WithTimeout() to bound RPCs and avoid hangs; update the Get calls on optr.kubeClient.NetworkingV1().NetworkPolicies(...).Get (and the other occurrences flagged around the same test) to accept the new context and ensure any created timeout contexts are canceled (defer cancel()) where applicable.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@pkg/operator/network_policy_drift_test.go`:
- Around line 22-23: Replace the use of context.TODO() in the network policy
test calls with a more appropriate context: use context.Background() for simple
test operations or, preferably, context.WithTimeout() to bound RPCs and avoid
hangs; update the Get calls on
optr.kubeClient.NetworkingV1().NetworkPolicies(...).Get (and the other
occurrences flagged around the same test) to accept the new context and ensure
any created timeout contexts are canceled (defer cancel()) where applicable.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: da9ed0f2-3717-4b11-b368-0a76f5d6d6b7
📒 Files selected for processing (1)
pkg/operator/network_policy_drift_test.go
|
@HarshwardhanPatil07: The following tests failed, say
Full PR test history. Your PR dashboard. 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. I understand the commands that are listed here. |
|
/retitle MCO-2153: Add drift protection tests for NetworkPolicies |
Add unit tests verifying that user modifications and deletions of NetworkPolicies are reverted by the sync loop:
- What I did
network_policy_drift_test.go).- How to verify it
- Description for the changelog
Summary by CodeRabbit