Skip to content

ROX-33608: add EnsureVirtualMachineExists to VM v2 datastore#19551

Open
dashrews78 wants to merge 3 commits intomasterfrom
dashrews/virt-v2-ensure-33608
Open

ROX-33608: add EnsureVirtualMachineExists to VM v2 datastore#19551
dashrews78 wants to merge 3 commits intomasterfrom
dashrews/virt-v2-ensure-33608

Conversation

@dashrews78
Copy link
Copy Markdown
Contributor

@dashrews78 dashrews78 commented Mar 23, 2026

Description

The scan index pipeline needs to insert a minimal VM record before
upserting scan data to satisfy FK constraints (VirtualMachineScanV2.VmV2Id
→ VirtualMachineV2.Id). EnsureVirtualMachineExists checks if the VM row
exists; if not, it inserts a minimal placeholder with just id and
cluster_id, avoiding overwriting richer metadata from the VM pipeline.

Partially generated by AI.

Co-Authored-By: Claude Opus 4.6 (1M context) noreply@anthropic.com

User-facing documentation

Testing and quality

  • the change is production ready: the change is GA, or otherwise the functionality is gated by a feature flag
  • CI results are inspected

Automated testing

  • added unit tests
  • added e2e tests
  • added regression tests
  • added compatibility tests
  • modified existing tests

How I validated my change

new unit tests.

@dashrews78
Copy link
Copy Markdown
Contributor Author

dashrews78 commented Mar 23, 2026

@openshift-ci
Copy link
Copy Markdown

openshift-ci bot commented Mar 23, 2026

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

@rhacs-bot
Copy link
Copy Markdown
Contributor

rhacs-bot commented Mar 23, 2026

Images are ready for the commit at 8d6e9a2.

To use with deploy scripts, first export MAIN_IMAGE_TAG=4.11.x-456-g8d6e9a27b3.

@dashrews78 dashrews78 force-pushed the dashrews/vm-v2-converters-33608 branch from 07beb4c to 3e3239d Compare March 24, 2026 13:28
@dashrews78 dashrews78 force-pushed the dashrews/virt-v2-ensure-33608 branch from ae3cb10 to 13ce987 Compare March 24, 2026 13:28
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 24, 2026

Codecov Report

❌ Patch coverage is 0% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.31%. Comparing base (3f2fbd5) to head (8d6e9a2).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
...tral/virtualmachine/v2/datastore/datastore_impl.go 0.00% 17 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #19551      +/-   ##
==========================================
- Coverage   49.32%   49.31%   -0.01%     
==========================================
  Files        2737     2737              
  Lines      206445   206462      +17     
==========================================
+ Hits       101823   101827       +4     
- Misses      97075    97090      +15     
+ Partials     7547     7545       -2     
Flag Coverage Δ
go-unit-tests 49.31% <0.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dashrews78 dashrews78 force-pushed the dashrews/vm-v2-converters-33608 branch from 3e3239d to 2fc5dd0 Compare March 26, 2026 10:39
Base automatically changed from dashrews/vm-v2-converters-33608 to master March 26, 2026 15:46
The scan index pipeline needs to insert a minimal VM record before
upserting scan data to satisfy FK constraints (VirtualMachineScanV2.VmV2Id
→ VirtualMachineV2.Id). EnsureVirtualMachineExists checks if the VM row
exists; if not, it inserts a minimal placeholder with just id and
cluster_id, avoiding overwriting richer metadata from the VM pipeline.

Partially generated by AI.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dashrews78 dashrews78 force-pushed the dashrews/virt-v2-ensure-33608 branch from 13ce987 to 504a110 Compare March 26, 2026 15:48
dashrews78 and others added 2 commits March 26, 2026 11:56
Clarify that the upsert creates a minimal VM record with only the ID
and cluster association when the VM doesn't yet exist.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dashrews78 dashrews78 marked this pull request as ready for review March 27, 2026 10:34
Copy link
Copy Markdown
Contributor

@ajheflin ajheflin left a comment

Choose a reason for hiding this comment

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

I assume this is going to be actually used somewhere in another PR

@dashrews78
Copy link
Copy Markdown
Contributor Author

I assume this is going to be actually used somewhere in another PR

The next one in fact.

@dashrews78
Copy link
Copy Markdown
Contributor Author

/retest-required

return ds.store.GetMany(ctx, ids)
}

func (ds *datastoreImpl) EnsureVirtualMachineExists(ctx context.Context, vmID string, clusterID string) error {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need to validate the clusterID isn't empty like we're doing for vmID?

@openshift-ci
Copy link
Copy Markdown

openshift-ci bot commented Mar 27, 2026

@dashrews78: The following test 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/gke-ui-e2e-tests 8d6e9a2 link true /test gke-ui-e2e-tests

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.

return errors.New("cannot ensure VM exists without an id")
}

_, exists, err := ds.store.Get(ctx, vmID)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit : Use count.
Get is probably fine too though. Since Scan is separated out, the proto won't be that big.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants