Skip to content

OCPBUGS-86826: Make vsphere template updates atomic#6117

Open
djoshy wants to merge 1 commit into
openshift:mainfrom
djoshy:make-vsphere-atomic
Open

OCPBUGS-86826: Make vsphere template updates atomic#6117
djoshy wants to merge 1 commit into
openshift:mainfrom
djoshy:make-vsphere-atomic

Conversation

@djoshy
Copy link
Copy Markdown
Contributor

@djoshy djoshy commented Jun 2, 2026

- What I did

  • Import new OVA under a temp name, keeping the old template live throughout the upload
  • Swap with two fast renames once new template is ready and then destroy the old template
  • If we crash mid-swap, next reconciliation detects the missing template and renames the old one back

- How to verify it

This is fairly hard to reproduce as it only happens due to network failures. At the very least, we should ensure that vsphere bootimage tests continue to work as expected.

Summary by CodeRabbit

  • New Features

    • Deterministic temporary and rollback naming to enable safer, atomic template swaps without downtime.
  • Bug Fixes

    • OVF import now preserves live templates during upload and performs rename-based swap post-import instead of pre-destroy.
    • Improved recovery to restore missing production templates and resume reconciliation.
    • Cleans up stale temp/rollback VMs from failed attempts to prevent leaks.

@openshift-merge-bot
Copy link
Copy Markdown
Contributor

Pipeline controller notification
This repo is configured to use the pipeline controller. Second-stage tests will be triggered either automatically or after lgtm label is added, depending on the repository configuration. The pipeline controller will automatically detect which contexts are required and will utilize /test Prow commands to trigger the second stage.

For optional jobs, comment /test ? to see a list of all defined jobs. To trigger manually all jobs from second stage use /pipeline required command.

This repository is configured in: LGTM mode

@openshift-ci-robot openshift-ci-robot added jira/severity-low Referenced Jira bug's severity is low for the branch this PR is targeting. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. labels Jun 2, 2026
@openshift-ci-robot
Copy link
Copy Markdown
Contributor

@djoshy: This pull request references Jira Issue OCPBUGS-86826, which is valid. The bug has been moved to the POST state.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (5.0.0) matches configured target version for branch (5.0.0)
  • bug is in the state New, which is one of the valid states (NEW, ASSIGNED, POST)

The bug has been updated to refer to the pull request using the external bug tracker.

Details

In response to this:

- What I did

  • Import new OVA under a temp name, keeping the old template live throughout the upload
  • Swap with two fast renames once new template is ready and then destroy the old template
  • If we crash mid-swap, next reconciliation detects the missing template and renames the old one back

- How to verify it

This is fairly hard to reproduce as it only happens due to network failures. At the very least, we should ensure that vsphere bootimage tests continue to work as expected.

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.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: openshift/coderabbit/.coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 025b21f8-9c78-4a7d-a89a-31e39a8830fb

📥 Commits

Reviewing files that changed from the base of the PR and between 276fe58 and fab78e4.

📒 Files selected for processing (1)
  • pkg/controller/bootimage/vsphere_helpers.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • pkg/controller/bootimage/vsphere_helpers.go

Walkthrough

Adds deterministic temp/rollback VM naming, pre-import cleanup of stale temp/rollback VMs, importing OVFs to a deterministic temp VM, atomic rename-based template replacement (rename old->rollback, temp->prod, destroy rollback), and reconciliation recovery that renames rollback back to production when needed.

Changes

Template Replacement Atomicity

Layer / File(s) Summary
Atomic operation helpers
pkg/controller/bootimage/vsphere_helpers.go
Adds atomicTempName, destroyVMIfPresent, and swapTemplate to compute fixed-length deterministic temp/rollback names and perform rename-swap + destroy sequence.
Import flow and temp VM setup
pkg/controller/bootimage/vsphere_helpers.go
Updates createNewVMTemplateWithNameForFailureDomain to compute tempName/oldTempName, pre-clean stale temp/rollback VMs, and set the OVF import target to the deterministic tempName. Also removes the prior pre-import destroy of an existing template.
Post-import template swap or rename
pkg/controller/bootimage/vsphere_helpers.go
After OVF import, if a production template exists call swapTemplate to perform rename-old->rollback, rename-temp->prod, then destroy rollback; otherwise rename the imported temp VM directly to the production template name.
Crash recovery and missing template handling
pkg/controller/bootimage/vsphere_helpers.go
When reconciliation cannot find the production template, compute the deterministic rollback-name VM, rename it back to the production name, re-fetch the VM reference, and continue reconciliation.
sequenceDiagram
  participant Reconciler
  participant vSphere
  participant ImportedVM
  participant ProdTemplate
  Reconciler->>vSphere: compute tempName and rollbackName
  Reconciler->>vSphere: destroyVMIfPresent tempName and rollbackName
  Reconciler->>vSphere: import OVF to ImportedVM (tempName)
  vSphere->>vSphere: check ProdTemplate exists
  alt ProdTemplate exists
    vSphere->>ProdTemplate: rename Prod -> rollback
    vSphere->>ImportedVM: rename temp -> Prod
    vSphere->>ProdTemplate: destroy rollback
  else
    vSphere->>ImportedVM: rename temp -> Prod
  end
  Reconciler->>vSphere: on missing ProdTemplate rename rollback -> Prod
  Reconciler->>vSphere: fetch refreshed ProdTemplate reference
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes


Important

Pre-merge checks failed

Please resolve all errors before merging. Addressing warnings is optional.

❌ Failed checks (1 error)

Check name Status Explanation Resolution
Container-Privileges ❌ Error PR adds manifests/bootstrap-pod-v2.yaml with privileged: true and hostNetwork: true in containers without justification in PR description. Review and justify the need for privileged mode and hostNetwork in bootstrap-pod-v2.yaml, or use non-privileged alternatives with specific required capabilities.
✅ Passed checks (14 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: making vSphere template updates atomic through deterministic naming and rename-based swaps.
Docstring Coverage ✅ Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%.
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 PR contains no Ginkgo tests. Test file uses standard Go testing with 46 static, deterministic test names with no dynamic values, timestamps, UUIDs, or generated identifiers.
Test Structure And Quality ✅ Passed PR modifies only production code (vsphere_helpers.go helper functions), not test code. No Ginkgo tests were added or modified, making the test structure quality check inapplicable.
Microshift Test Compatibility ✅ Passed No new Ginkgo e2e tests were added in this PR. The PR adds a 633-line helper file (vsphere_helpers.go) containing only utility functions for vSphere VM template management, not tests.
Single Node Openshift (Sno) Test Compatibility ✅ Passed PR does not add any Ginkgo e2e tests. Modified file (vsphere_helpers.go) is a helper module containing utility functions for vSphere operations, not a test file.
Topology-Aware Scheduling Compatibility ✅ Passed PR modifies only vSphere boot image template helper code. No Kubernetes deployment manifests, pod scheduling constraints, affinity rules, or topology-aware code changes are introduced.
Ote Binary Stdout Contract ✅ Passed No OTE Binary Stdout Contract violations found. All klog calls are in utility functions, not process-level code, and klog v2 writes to stderr by default.
Ipv6 And Disconnected Network Test Compatibility ✅ Passed No Ginkgo e2e tests added. Only standard Go unit tests using testing.T in pkg/controller/bootimage/boot_image_controller_test.go.
No-Weak-Crypto ✅ Passed PR uses only SHA256 for non-security-critical VM name generation and logging; no weak algorithms, custom crypto, or insecure comparisons detected.
No-Sensitive-Data-In-Logs ✅ Passed No sensitive data exposure found. PR logs only operational information (VM names, versions) and maintains the prior security fix preventing vCenter URL credential exposure.
✨ 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)

Command failed


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

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Jun 2, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: djoshy

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

The pull request process is described 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

@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 2, 2026
@openshift-ci-robot
Copy link
Copy Markdown
Contributor

@djoshy: This pull request references Jira Issue OCPBUGS-86826, which is valid.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target version (5.0.0) matches configured target version for branch (5.0.0)
  • bug is in the state POST, which is one of the valid states (NEW, ASSIGNED, POST)
Details

In response to this:

- What I did

  • Import new OVA under a temp name, keeping the old template live throughout the upload
  • Swap with two fast renames once new template is ready and then destroy the old template
  • If we crash mid-swap, next reconciliation detects the missing template and renames the old one back

- How to verify it

This is fairly hard to reproduce as it only happens due to network failures. At the very least, we should ensure that vsphere bootimage tests continue to work as expected.

Summary by CodeRabbit

Release Notes

  • Bug Fixes
  • Improved reliability and atomicity of vSphere template replacement operations
  • Enhanced crash recovery mechanisms when template imports fail, automatically restoring from previous state
  • Better cleanup of temporary resources from incomplete operations to prevent resource leaks

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.

@djoshy
Copy link
Copy Markdown
Contributor Author

djoshy commented Jun 2, 2026

/payload-job periodic-ci-openshift-machine-config-operator-release-5.0-periodics-e2e-vsphere-mco-disruptive

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Jun 2, 2026

@djoshy: trigger 1 job(s) for the /payload-(with-prs|job|aggregate|job-with-prs|aggregate-with-prs) command

  • periodic-ci-openshift-machine-config-operator-release-5.0-periodics-e2e-vsphere-mco-disruptive

See details on https://pr-payload-tests.ci.openshift.org/runs/ci/81361080-5e98-11f1-8281-d019b8daff8d-0

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
pkg/controller/bootimage/vsphere_helpers.go (1)

321-333: 💤 Low value

Consider also cleaning up stale oldTempName VMs.

Currently, only tempName (mco-tmp-*) is cleaned up at the start. If a previous swapTemplate completed both renames but the final Destroy failed, the old template under oldTempName (mco-old-*) would remain orphaned. Adding a cleanup call for oldTempName here would prevent accumulation of orphaned VMs from repeated destroy failures.

♻️ Suggested improvement
 	if err := cleanupStaleTempVM(ctx, finder, tempName); err != nil {
 		return err
 	}
+	if err := cleanupStaleTempVM(ctx, finder, oldTempName); err != nil {
+		return err
+	}
🤖 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/controller/bootimage/vsphere_helpers.go` around lines 321 - 333, The
current startup cleanup only calls cleanupStaleTempVM for tempName which leaves
orphaned oldTempName VMs if a prior swap left mco-old-* behind; add a call to
cleanupStaleTempVM(ctx, finder, oldTempName) alongside the existing cleanup for
tempName (handle its error return the same way) before proceeding with
swapTemplate/findAllRequiredResources so both tempName and oldTempName are
cleaned up; reference tempName, oldTempName, cleanupStaleTempVM and ensure error
is returned if cleanupStaleTempVM(ctx, finder, oldTempName) fails.
🤖 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 `@pkg/controller/bootimage/vsphere_helpers.go`:
- Around line 556-559: The error returned when finder.VirtualMachine(ctx,
oldTempName) fails currently wraps only the original err and omits oldErr;
update the error construction in the rollback VM lookup (around
finder.VirtualMachine / oldVM / oldErr) to include oldErr details (e.g., add
oldErr to the fmt.Errorf message or wrap it with %w) so the returned error
contains both the template not found context and the actual failure reason from
oldErr when looking up oldTempName alongside the existing err and variables
name/oldTempName.

---

Nitpick comments:
In `@pkg/controller/bootimage/vsphere_helpers.go`:
- Around line 321-333: The current startup cleanup only calls cleanupStaleTempVM
for tempName which leaves orphaned oldTempName VMs if a prior swap left
mco-old-* behind; add a call to cleanupStaleTempVM(ctx, finder, oldTempName)
alongside the existing cleanup for tempName (handle its error return the same
way) before proceeding with swapTemplate/findAllRequiredResources so both
tempName and oldTempName are cleaned up; reference tempName, oldTempName,
cleanupStaleTempVM and ensure error is returned if cleanupStaleTempVM(ctx,
finder, oldTempName) fails.
🪄 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: 518a9907-6871-46fa-85ac-cc35b0a64636

📥 Commits

Reviewing files that changed from the base of the PR and between 26d41f7 and 80b5b21.

📒 Files selected for processing (1)
  • pkg/controller/bootimage/vsphere_helpers.go

Comment thread pkg/controller/bootimage/vsphere_helpers.go
@djoshy
Copy link
Copy Markdown
Contributor Author

djoshy commented Jun 2, 2026

/payload-abort

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Jun 2, 2026

@djoshy: aborted 1 active payload job(s) for pull request #6117

@djoshy djoshy force-pushed the make-vsphere-atomic branch from 80b5b21 to 276fe58 Compare June 2, 2026 15:50
@djoshy
Copy link
Copy Markdown
Contributor Author

djoshy commented Jun 2, 2026

/payload-job periodic-ci-openshift-machine-config-operator-release-5.0-periodics-e2e-vsphere-mco-disruptive

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci Bot commented Jun 2, 2026

@djoshy: trigger 1 job(s) for the /payload-(with-prs|job|aggregate|job-with-prs|aggregate-with-prs) command

  • periodic-ci-openshift-machine-config-operator-release-5.0-periodics-e2e-vsphere-mco-disruptive

See details on https://pr-payload-tests.ci.openshift.org/runs/ci/bb9eb130-5e9a-11f1-9e66-32f081cd610f-0

@djoshy djoshy force-pushed the make-vsphere-atomic branch from 276fe58 to fab78e4 Compare June 2, 2026 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. jira/severity-low Referenced Jira bug's severity is low for the branch this PR is targeting. jira/valid-bug Indicates that a referenced Jira bug is valid for the branch this PR is targeting. 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