MCO-2152: MCO-2153: MCO-2154: Create MCO network policies for pods#6151
MCO-2152: MCO-2153: MCO-2154: Create MCO network policies for pods#6151HarshwardhanPatil07 wants to merge 5 commits into
Conversation
- manifests/networkpolicy/00-default-deny.yaml: Default deny-all policy selecting all pods with no ingress/egress rules. - manifests/networkpolicy/01-allow-machine-config-operator.yaml: Allow policy for MCO (egress all, ingress TCP 9001 metrics). - manifests/networkpolicy/02-allow-machine-config-controller.yaml: Allow policy for MCC (egress all, ingress TCP 9001 metrics). - manifests/networkpolicy/03-allow-machine-os-builder.yaml: Conditional allow policy for MOB (egress all, ingress TCP 9001 metrics). - pkg/operator/network_policy_test.go: Added 7 unit tests covering all lifecycle scenarios. Files Modified: - pkg/operator/sync.go: Added manifest path constants and syncNetworkPolicies() with retry logic and conditional MOB lifecycle management. - pkg/operator/operator.go: Added networkPolicyInformerSynced field, registered informer for drift detection, and wired it into the sync chain. - cmd/machine-config-operator/start.go: Passed NetworkPolicies informer factory to operator.New(). Test Results (7 new tests passing, existing suite green): - TestSyncNetworkPolicies_StaticPoliciesCreated: Verifies 3 static policies created, MOB absent. - TestSyncNetworkPolicies_DefaultDenySpec: Verifies empty podSelector, both policyTypes, no rules. - TestSyncNetworkPolicies_AllowPolicySpecs: Verifies podSelector labels, egress allow-all, ingress metrics port 9001. - TestSyncNetworkPolicies_MOBPolicyWithLayeredPools: Verifies MOB policy created when layered pools exist. - TestSyncNetworkPolicies_MOBPolicyDeletedWithoutLayeredPools: Verifies MOB cleanup when pools are removed. - TestSyncNetworkPolicies_DriftProtection: Verifies manual modifications are reverted on resync. - TestSyncNetworkPolicies_Idempotent: Verifies stable policy count across multiple syncs. Signed-off-by: HarshwardhanPatil07 <harshpat@redhat.com>
|
Pipeline controller notification For optional jobs, comment This repository is configured in: LGTM mode |
WalkthroughThis PR adds NetworkPolicy management to the machine-config-operator controller. It wires a NetworkPolicy informer into the operator lifecycle, implements reconciliation to apply static and conditional NetworkPolicies in the machine-config namespace, adds an admission policy preventing deletion of managed policies, and includes unit and e2e tests validating behavior. ChangesNetworkPolicy Management for Machine Config Operator
🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 13 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ 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 |
|
/retitle (WIP) MCO-2152: Create MCO network policies for pods |
|
@HarshwardhanPatil07: This pull request references MCO-2152 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. |
Remove DriftProtection and Idempotent tests from this file as they belong to the drift protection scope tracked under MCO-2153. Signed-off-by: HarshwardhanPatil07 <harshpat@redhat.com>
Replace traditional Get/Create/Update with SSA for stronger drift protection. The operator now owns all policy fields via FieldManager with Force:true, ensuring user modifications are always reverted. - Build policies programmatically using typed apply configurations - Remove YAML manifests (no longer needed with SSA) - Move syncNetworkPolicies to dedicated network_policy.go file Signed-off-by: HarshwardhanPatil07 <harshpat@redhat.com>
|
/test security |
…ion and e2e tests Add a ValidatingAdmissionPolicy that prevents deletion of MCO-managed NetworkPolicies (default-deny, allow-machine-config-operator, allow-machine-config-controller, allow-machine-os-builder) in the openshift-machine-config-operator namespace. This is needed because the default-deny policy blocks all egress, so deleting an allow policy causes the MCO pod to lose API server access, creating an unrecoverable deadlock where the sync loop cannot recreate the deleted policy. Modifications to managed policies are still reverted via Server-Side Apply on the next sync cycle. Also adds e2e presubmit tests to test/e2e-2of2/ covering: - Default policies exist with correct specs - Modifications are reverted by SSA - Deletions are blocked by ValidatingAdmissionPolicy - MCO processes continue working with policies in place - User-created policies coexist with managed policies Signed-off-by: HarshwardhanPatil07 <harshpat@redhat.com>
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: HarshwardhanPatil07 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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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.
Inline comments:
In `@test/e2e-2of2/network_policy_test.go`:
- Around line 33-42: The helper skipIfNoNetworkPolicies currently calls t.Skip
when the NetworkPolicy list is empty, which hides regressions; change this to
make the test fail instead. In skipIfNoNetworkPolicies (function name), after
the require.NoError check, replace the t.Skip branch with an assertion that the
returned policies list is non-empty (e.g., require.Greater(t,
len(policies.Items), 0, "expected at least one NetworkPolicy in MCO namespace")
or t.Fatalf with an explanatory message) so missing managed NetworkPolicies
cause a test failure rather than being skipped.
- Around line 178-187: The test currently only asserts statuses when a condition
is present, allowing missing conditions to pass; update the loop over
co.Status.Conditions to track presence of configv1.OperatorAvailable and
configv1.OperatorDegraded (e.g., foundAvailable, foundDegraded booleans),
continue asserting their Status values as you already do for
OperatorAvailable==ConditionTrue and OperatorDegraded==ConditionFalse, and after
the loop add explicit assertions that both foundAvailable and foundDegraded are
true so missing conditions fail the test (refer to co.Status.Conditions and the
condition Type checks for configv1.OperatorAvailable and
configv1.OperatorDegraded).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 5872788b-97d8-4b08-a54b-7435f9797cc1
📒 Files selected for processing (4)
manifests/machineconfigcontroller/networkpolicy-deletion-guard-validatingadmissionpolicy.yamlmanifests/machineconfigcontroller/networkpolicy-deletion-guard-validatingadmissionpolicybinding.yamlpkg/operator/sync.gotest/e2e-2of2/network_policy_test.go
✅ Files skipped from review due to trivial changes (2)
- manifests/machineconfigcontroller/networkpolicy-deletion-guard-validatingadmissionpolicybinding.yaml
- manifests/machineconfigcontroller/networkpolicy-deletion-guard-validatingadmissionpolicy.yaml
Replace t.Skip with require.NotEmpty when no NetworkPolicies are found so missing managed policies fail the test instead of being skipped. Add explicit presence assertions for OperatorAvailable and OperatorDegraded conditions to prevent silent pass when conditions are absent. Signed-off-by: HarshwardhanPatil07 <harshpat@redhat.com>
|
@HarshwardhanPatil07: all tests passed! 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. |
- What I did
Added NetworkPolicy support for the openshift-machine-config-operator namespace to implement default-deny plus explicit allow rules for pod-networked MCO components.
Introduced new manifests:
- How to verify it
- Description for the changelog
Summary by CodeRabbit
New Features
Tests