Skip to content

SPLAT-2790: Added new VAP for vSphere infra validation against current cpms and machines#1510

Draft
vr4manta wants to merge 1 commit into
openshift:mainfrom
vr4manta:infra-vap
Draft

SPLAT-2790: Added new VAP for vSphere infra validation against current cpms and machines#1510
vr4manta wants to merge 1 commit into
openshift:mainfrom
vr4manta:infra-vap

Conversation

@vr4manta

@vr4manta vr4manta commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

SPLAT-2790

Changes

  • Added logic to add new VAP for validating infrastructure (FD) removals against current CPMS and machines

Summary by CodeRabbit

  • New Features
    • Added vSphere failure domain protection policies to prevent accidental removal of failure domains still referenced by Machines and ControlPlaneMachineSets during Infrastructure updates, ensuring cluster stability.

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jun 15, 2026
@openshift-ci openshift-ci Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 15, 2026
@openshift-ci-robot

openshift-ci-robot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

@vr4manta: This pull request references SPLAT-2790 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.

Details

In response to this:

SPLAT-2790

Changes

  • Added logic to add new VAP for validating infrastructure (FD) removals against current CPMS and machines

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.

@openshift-ci

openshift-ci Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@coderabbitai

coderabbitai Bot commented Jun 15, 2026

Copy link
Copy Markdown

Walkthrough

Adds two ValidatingAdmissionPolicy resources and their bindings to prevent vSphere failure domain removal from Infrastructure objects while Machine or ControlPlaneMachineSet resources still reference those domains. The operator's syncWebhookConfiguration is extended with a vSphere branch that applies these VAPs. The machine-api-operator ClusterRole gains the required RBAC verbs on the new resource types.

Changes

vSphere Failure Domain ValidatingAdmissionPolicy Support

Layer / File(s) Summary
VAP constructors and constants
pkg/webhooks/vap.go
Defines VAPMachineFailureDomainName and VAPCPMSFailureDomainName constants, admission action variables, and four constructors: NewVSphereFailureDomainMachineVAP (CEL rules check region/zone labels on Machine params), NewVSphereFailureDomainMachineVAPBinding, NewVSphereFailureDomainCPMSVAP (CEL rules check CPMS template FD name references), and NewVSphereFailureDomainCPMSVAPBinding. Both policies match Infrastructure UPDATE on vSphere clusters and use ParameterNotFound: Allow.
RBAC permissions and operator sync wiring
install/0000_30_machine-api-operator_09_rbac.yaml, pkg/operator/sync.go
Extends ClusterRole machine-api-operator with get/list/watch/create/update on validatingadmissionpolicies and validatingadmissionpolicybindings, and get/list/watch on machines and controlplanemachinesets. Adds a vSphere conditional in syncWebhookConfiguration that calls syncVSphereFailureDomainVAPs, which applies all four VAP/binding objects sequentially.
Unit tests
pkg/webhooks/vap_test.go, pkg/operator/sync_test.go
Tests for each VAP and binding constructor assert name, ParamKind, match constraints, CEL variables, validation rules, failure policy, and ParameterNotFoundAction. TestVAPNamesAreConsistent cross-checks binding PolicyName against VAP names. TestSyncVSphereFailureDomainVAPs verifies zero VAPs for non-vSphere and exactly two policies plus two bindings for vSphere, including name and policy-reference assertions.

Sequence Diagram(s)

sequenceDiagram
    participant Operator as machine-api-operator
    participant k8s as Kubernetes API
    participant MachineVAP as ValidatingAdmissionPolicy (Machine FD)
    participant CPMSVAP as ValidatingAdmissionPolicy (CPMS FD)

    rect rgba(100, 149, 237, 0.5)
        Note over Operator,k8s: syncVSphereFailureDomainVAPs (vSphere only)
        Operator->>k8s: apply NewVSphereFailureDomainMachineVAP
        k8s-->>Operator: ok
        Operator->>k8s: apply NewVSphereFailureDomainMachineVAPBinding
        k8s-->>Operator: ok
        Operator->>k8s: apply NewVSphereFailureDomainCPMSVAP
        k8s-->>Operator: ok
        Operator->>k8s: apply NewVSphereFailureDomainCPMSVAPBinding
        k8s-->>Operator: ok
    end

    rect rgba(255, 140, 0, 0.5)
        Note over k8s,CPMSVAP: Infrastructure UPDATE admission
        k8s->>MachineVAP: evaluate per Machine param (region/zone labels)
        MachineVAP-->>k8s: Deny if referenced FD removed
        k8s->>CPMSVAP: evaluate per ControlPlaneMachineSet param (template FD names)
        CPMSVAP-->>k8s: Deny if referenced FD removed
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 13 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 41.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Test Structure And Quality ⚠️ Warning vap_test.go contains 66 assertions without meaningful failure messages (e.g., Expect(policy).NotTo(BeNil())), violating the requirement that assertions include messages to help diagnose failures. Add meaningful messages to assertions in vap_test.go, e.g., g.Expect(policy).NotTo(BeNil(), "NewVSphereFailureDomainMachineVAP should not return nil").
✅ Passed checks (13 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding a new VAP (Validation Admission Policy) for vSphere infrastructure validation that validates against current CPMS and machines, which aligns with the core changes across all modified files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Stable And Deterministic Test Names ✅ Passed Test code uses standard Go testing (not Ginkgo); all test names are static and descriptive with no dynamic content, timestamps, or generated identifiers.
Microshift Test Compatibility ✅ Passed No Ginkgo e2e tests are added in this PR; all new tests are standard Go unit tests (TestSyncVSphereFailureDomainVAPs and vap_test.go test functions).
Single Node Openshift (Sno) Test Compatibility ✅ Passed No Ginkgo e2e tests added in this PR. The check is not applicable; only standard Go unit tests (func TestXxx pattern) are added.
Topology-Aware Scheduling Compatibility ✅ Passed This PR adds ValidatingAdmissionPolicy definitions and RBAC permissions only. No workload deployments, pod scheduling constraints, affinity rules, PodDisruptionBudgets, or topology-dependent config...
Ote Binary Stdout Contract ✅ Passed No stdout writes detected in changed files. New code (syncVSphereFailureDomainVAPs, VAP constructors, and tests) are not process-level code—they're called from operator reconciliation, not from mai...
Ipv6 And Disconnected Network Test Compatibility ✅ Passed No Ginkgo e2e tests are added in this PR. All new tests are standard Go unit tests using func TestXxx(t *testing.T) pattern without Ginkgo framework imports.
No-Weak-Crypto ✅ Passed No weak cryptography (MD5, SHA1, DES, RC4, 3DES, Blowfish, ECB), custom crypto implementations, or non-constant-time secret comparisons detected in the modified files. The PR adds ValidatingAdmissi...
Container-Privileges ✅ Passed The PR modifies RBAC rules and Go source code, with no container or K8s manifests containing privileged settings (no privileged: true, hostPID/Network/IPC, SYS_ADMIN, allowPrivilegeEscalation, or r...
No-Sensitive-Data-In-Logs ✅ Passed No logging statements in the PR expose passwords, tokens, API keys, PII, session IDs, internal hostnames, or customer data. MessageExpressions contain only public resource names and infrastructure...

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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
The command is terminated due to an error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/docs/product/migration-guide for migration instructions


Comment @coderabbitai help to get the list of available commands and usage tips.

@openshift-ci

openshift-ci Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign theobarberbany for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@vr4manta

Copy link
Copy Markdown
Contributor Author

/test all

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 `@install/0000_30_machine-api-operator_09_rbac.yaml`:
- Around line 484-495: The ClusterRole rule at lines 487–495 grants unnecessary
cluster-wide read access to machines and controlplanemachinesets when the VAP
policies scope parameter resolution to the openshift-machine-api namespace only.
Remove this cluster-wide rule from the ClusterRole, and instead add the get verb
to the existing namespaced Role rule at line 363 that already grants list and
watch on all resources in the openshift-machine-api namespace. This narrows
permissions to only the namespace where the operator actually needs access while
maintaining the required authorization for VAP binding creation.

In `@pkg/operator/sync.go`:
- Around line 285-304: The ApplyValidatingAdmissionPolicyV1 and
ApplyValidatingAdmissionPolicyBindingV1 calls are using context.TODO() which
does not provide cancellation or timeout bounds. Replace context.TODO() with a
bounded context that includes proper cancellation and timeout behavior suitable
for the reconcile path. Create or use an existing bounded context with
appropriate timeout values (such as deriving it from the reconciliation context
or creating one with a reasonable timeout) and pass it to all four resourceapply
function calls instead of context.TODO().
🪄 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: fa16aa88-d84f-4db6-80ab-a0191fea2bf4

📥 Commits

Reviewing files that changed from the base of the PR and between d7772c6 and b90994e.

📒 Files selected for processing (5)
  • install/0000_30_machine-api-operator_09_rbac.yaml
  • pkg/operator/sync.go
  • pkg/operator/sync_test.go
  • pkg/webhooks/vap.go
  • pkg/webhooks/vap_test.go

Comment thread install/0000_30_machine-api-operator_09_rbac.yaml
Comment thread pkg/operator/sync.go
@vr4manta

Copy link
Copy Markdown
Contributor Author

/test ?

@vr4manta

Copy link
Copy Markdown
Contributor Author

/test e2e-vsphere-ovn-serial e2e-vsphere-ovn-techpreview-serial

@vr4manta

Copy link
Copy Markdown
Contributor Author

/retest

@openshift-ci

openshift-ci Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

@vr4manta: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-vsphere-ovn-serial b90994e link false /test e2e-vsphere-ovn-serial
ci/prow/e2e-aws-ovn b90994e link true /test e2e-aws-ovn

Full PR test history. Your PR dashboard.

Details

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. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants