Skip to content

Rename VirtualMachineGuestOptions hardwareVersion field to version - #1793

Draft
faisalabujabal wants to merge 7 commits into
vmware-tanzu:mainfrom
faisalabujabal:vmop-3932-rename-hardwareversion
Draft

Rename VirtualMachineGuestOptions hardwareVersion field to version#1793
faisalabujabal wants to merge 7 commits into
vmware-tanzu:mainfrom
faisalabujabal:vmop-3932-rename-hardwareversion

Conversation

@faisalabujabal

Copy link
Copy Markdown
Contributor

Draft — stacked on #1782, do not review until that merges.

What does this PR do, and why is it needed?

Follow-up to #1782 (vmop-3932). aruneshpa flagged that
VirtualMachineGuestOptionsHardwareVersionStatus.HardwareVersion
stutters with its parent field, HardwareVersions -- giving
status.hardwareVersions[].hardwareVersion instead of
status.hardwareVersions[].version.

Confirmed vim.vmware.com/v1alpha1 has never been tagged or released
(no shipped consumers), so this is a clean rename rather than a
breaking API change requiring a conversion webhook. Updated the
+listMapKey marker alongside the field, and regenerated the deepcopy
code and external CRD manifest via controller-gen.

This PR stacks on #1782, same as #1789: opened against main
only because GitHub requires a PR's base branch to exist in the base
repository, and vmop-3932-gc-unused-guestoptions only exists on my
fork. The diff currently includes #1782's full changeset. Once #1782
merges this branch will be rebased onto main and the diff will
shrink to just this rename (commit c35ca36e).

Which issue(s) is/are addressed by this PR?:

Tracked under vmop-3932 (same ticket as #1782 and #1789).

Are there any special notes for your reviewer:

Hold review until #1782 merges. To review only the net-new work now,
look at commit c35ca36e directly rather than the full PR diff.

Please add a release note if necessary:

None

— Faisal + Claude

The VirtualMachineConfigOptions controller fans out a
VirtualMachineGuestOptions per guest OS descriptor and upserts a
status.hardwareVersions entry per hardware version, but never
removed that entry once a hardware version stopped reporting the
guest OS -- unlike the analogous ConfigTarget -> VirtualMachineConfigOptions
garbage collection.

Add garbageCollectGuestOptions, invoked at the end of every
VirtualMachineConfigOptions reconcile: it removes the current
hardware version's status.hardwareVersions entry from any
VirtualMachineGuestOptions no longer reporting that guest OS, and
deletes the object outright once no hardware-version entries
remain. The live set is keyed by the sanitized object name (not the
raw guest OS ID) so two IDs that collide onto the same truncated,
DNS-safe name cannot cause a spurious deletion.

Update spec.md, research.md, and tasks.md for 001-class-policy-resize
to reflect that this follow-up (previously called out as deferred)
is now implemented.

vmop-3932
QueryConfigOptionEx returning nil with no error is vSphere's
positive answer that a hardware version has no config option in this
environment -- not a transient signal, which surfaces as a non-nil
error instead. ReconcileNormal treated that nil result as a dead end
and returned before fanOutGuestOptions ran, so a hardware version
that stopped being supported left its previously fanned-out
VirtualMachineGuestOptions entries orphaned forever, even though the
VirtualMachineConfigOptions object itself kept reconciling.

Route the nil-config-option path through fanOutGuestOptions with an
empty descriptor list instead, so it is pruned exactly like the
already-covered non-nil-but-empty case.

vmop-3932
removeHardwareVersionAndDeleteIfOrphaned fetches obj via the
caller's List, then deletes it unconditionally once its last
hardwareVersions entry is being removed. Between that List and the
Delete, another hardware version's reconcile could concurrently
upsert a new entry into this shared object; the unconditional delete
would silently discard that entry along with the object.

Pass client.Preconditions{ResourceVersion: &obj.ResourceVersion} to
Delete so a racing writer causes a conflict here instead, which
surfaces as a normal reconcile error and gets retried with fresh
data on the next attempt -- the same optimistic-locking approach
already used for this file's status patches.

Per automated review on vmop-3932.

vmop-3932
ReconcileDelete only removed the finalizer, so when a
VirtualMachineConfigOptions was deleted -- e.g. by ConfigTarget's own
GC dropping a hardware version -- any VirtualMachineGuestOptions it
had fanned out kept their status.hardwareVersions entry forever, even
though the owning object was gone.

Run the same garbageCollectGuestOptions used by ReconcileNormal
before removing the finalizer, so deletion prunes exactly like a live
reconcile that observes zero descriptors. The finalizer is removed
only after GC succeeds -- it exists to hold the object until cleanup
completes, so removing it unconditionally would let a GC error vanish
along with the object, and the leak would never retry.

Per review feedback on vmop-3932 (why doesn't deleting the CR clean up
its guest options?).

vmop-3932
aruneshpa suggested slices.DeleteFunc instead of the manual
find-index-then-splice in removeHardwareVersionAndDeleteIfOrphaned.
Deleting is now decided by comparing the slice length before and
after, rather than a separate found-index check, and the delete-vs-
patch branch reads directly off the resulting length.

base is captured before DeleteFunc runs, since DeleteFunc mutates the
slice's backing array in place -- copying after would capture the
already-pruned state and make the status patch below compute an empty
diff.
Claude Code review on vmware-tanzu#1782 flagged that the fan-out write path has no
defense against two guest OS descriptors sanitizing to the same
object name, unlike the GC path which is deliberately keyed on the
sanitized name for that exact reason -- a real collision would make
reconcileGuestOptions patch spec.ID back and forth every reconcile, a
self-sustaining hot loop.

This is latent, not live: vSphere guest IDs are camelCase-alphanumeric,
so a collision would need two IDs differing only by case, which
vSphere doesn't produce. Document the assumption next to the helper
that encodes it, so it's explicit rather than implied.
aruneshpa flagged on PR vmware-tanzu#1782 that
VirtualMachineGuestOptionsHardwareVersionStatus.HardwareVersion
stutters with its parent field, HardwareVersions -- giving
status.hardwareVersions[].hardwareVersion instead of
status.hardwareVersions[].version.

vim.vmware.com/v1alpha1 has never been tagged or released (no shipped
consumers), so this is a clean rename rather than a breaking API
change requiring a conversion webhook. Updated the +listMapKey marker
alongside the field, and regenerated the deepcopy code and external
CRD manifest via controller-gen.
@github-actions github-actions Bot added the size/L Denotes a PR that changes 100-499 lines. label Aug 3, 2026
@github-actions

github-actions Bot commented Aug 3, 2026

Copy link
Copy Markdown

Code Coverage

Package Line Rate Health
github.com/vmware-tanzu/vm-operator/controllers/configtarget 74%
github.com/vmware-tanzu/vm-operator/controllers/contentlibrary/clustercontentlibraryitem 67%
github.com/vmware-tanzu/vm-operator/controllers/contentlibrary/contentlibraryitem 67%
github.com/vmware-tanzu/vm-operator/controllers/contentlibrary/utils 85%
github.com/vmware-tanzu/vm-operator/controllers/infra/capability/configmap 92%
github.com/vmware-tanzu/vm-operator/controllers/infra/capability/crd 100%
github.com/vmware-tanzu/vm-operator/controllers/infra/configmap 75%
github.com/vmware-tanzu/vm-operator/controllers/infra/node 77%
github.com/vmware-tanzu/vm-operator/controllers/infra/secret 76%
github.com/vmware-tanzu/vm-operator/controllers/infra/validatingwebhookconfiguration 87%
github.com/vmware-tanzu/vm-operator/controllers/infra/workloadnetworkconfig 86%
github.com/vmware-tanzu/vm-operator/controllers/infra/zone 80%
github.com/vmware-tanzu/vm-operator/controllers/storage/storageclass 93%
github.com/vmware-tanzu/vm-operator/controllers/storage/storagepolicy 96%
github.com/vmware-tanzu/vm-operator/controllers/storage/storagepolicyquota 91%
github.com/vmware-tanzu/vm-operator/controllers/storage/volumeattributesclass 93%
github.com/vmware-tanzu/vm-operator/controllers/util/encoding 73%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachine/storagepolicyusage 96%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachine/virtualmachine 65%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachine/volume 85%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachine/volumebatch 89%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachineclass 73%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachineconfigoptions 87%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachinegroup 90%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachinegrouppublishrequest 88%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachineimagecache 89%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachinepublishrequest 84%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachinereplicaset 67%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachineservice 91%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachineservice/providers 93%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachinesetresourcepolicy 81%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachinesnapshot 91%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachinewebconsolerequest 72%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachinewebconsolerequest/v1alpha1 72%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachinewebconsolerequest/v1alpha1/conditions 88%
github.com/vmware-tanzu/vm-operator/controllers/virtualmachinewebconsolerequest/v1alpha1/patch 78%
github.com/vmware-tanzu/vm-operator/controllers/vspherepolicy/policyevaluation 85%
github.com/vmware-tanzu/vm-operator/pkg/bitmask 100%
github.com/vmware-tanzu/vm-operator/pkg/builder 89%
github.com/vmware-tanzu/vm-operator/pkg/conditions 90%
github.com/vmware-tanzu/vm-operator/pkg/config 100%
github.com/vmware-tanzu/vm-operator/pkg/config/capabilities 97%
github.com/vmware-tanzu/vm-operator/pkg/config/env 100%
github.com/vmware-tanzu/vm-operator/pkg/context 37%
github.com/vmware-tanzu/vm-operator/pkg/context/generic 100%
github.com/vmware-tanzu/vm-operator/pkg/context/operation 100%
github.com/vmware-tanzu/vm-operator/pkg/crd 77%
github.com/vmware-tanzu/vm-operator/pkg/errors 74%
github.com/vmware-tanzu/vm-operator/pkg/exit 100%
github.com/vmware-tanzu/vm-operator/pkg/log 100%
github.com/vmware-tanzu/vm-operator/pkg/mem 100%
github.com/vmware-tanzu/vm-operator/pkg/patch 78%
github.com/vmware-tanzu/vm-operator/pkg/prober 89%
github.com/vmware-tanzu/vm-operator/pkg/prober/probe 90%
github.com/vmware-tanzu/vm-operator/pkg/prober/worker 77%
github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere 74%
github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/clustermodules 73%
github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/config 88%
github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/contentlibrary 76%
github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/credentials 100%
github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/network 83%
github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/placement 70%
github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/session 60%
github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/storage 44%
github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/upgrade/virtualmachine 96%
github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/upgrade/virtualmachine/backfill 96%
github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/vcenter 86%
github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/virtualmachine 84%
github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/virtualmachine/extraconfig 87%
github.com/vmware-tanzu/vm-operator/pkg/providers/vsphere/vmlifecycle 75%
github.com/vmware-tanzu/vm-operator/pkg/record 84%
github.com/vmware-tanzu/vm-operator/pkg/topology 91%
github.com/vmware-tanzu/vm-operator/pkg/util 79%
github.com/vmware-tanzu/vm-operator/pkg/util/cloudinit 89%
github.com/vmware-tanzu/vm-operator/pkg/util/cloudinit/validate 91%
github.com/vmware-tanzu/vm-operator/pkg/util/image 100%
github.com/vmware-tanzu/vm-operator/pkg/util/kube 91%
github.com/vmware-tanzu/vm-operator/pkg/util/kube/cource 100%
github.com/vmware-tanzu/vm-operator/pkg/util/kube/internal 100%
github.com/vmware-tanzu/vm-operator/pkg/util/kube/networksettings 100%
github.com/vmware-tanzu/vm-operator/pkg/util/kube/proxyaddr 73%
github.com/vmware-tanzu/vm-operator/pkg/util/kube/spq 99%
github.com/vmware-tanzu/vm-operator/pkg/util/linuxprep 97%
github.com/vmware-tanzu/vm-operator/pkg/util/netplan 100%
github.com/vmware-tanzu/vm-operator/pkg/util/nil 100%
github.com/vmware-tanzu/vm-operator/pkg/util/ovfcache 75%
github.com/vmware-tanzu/vm-operator/pkg/util/ovfcache/internal 100%
github.com/vmware-tanzu/vm-operator/pkg/util/paused 100%
github.com/vmware-tanzu/vm-operator/pkg/util/ptr 100%
github.com/vmware-tanzu/vm-operator/pkg/util/resize 98%
github.com/vmware-tanzu/vm-operator/pkg/util/sysprep 98%
github.com/vmware-tanzu/vm-operator/pkg/util/vmopv1 88%
github.com/vmware-tanzu/vm-operator/pkg/util/volumes 100%
github.com/vmware-tanzu/vm-operator/pkg/util/vsphere/client 66%
github.com/vmware-tanzu/vm-operator/pkg/util/vsphere/datastore 100%
github.com/vmware-tanzu/vm-operator/pkg/util/vsphere/fault 100%
github.com/vmware-tanzu/vm-operator/pkg/util/vsphere/library 95%
github.com/vmware-tanzu/vm-operator/pkg/util/vsphere/storage 82%
github.com/vmware-tanzu/vm-operator/pkg/util/vsphere/task 100%
github.com/vmware-tanzu/vm-operator/pkg/util/vsphere/vm 78%
github.com/vmware-tanzu/vm-operator/pkg/util/vsphere/watcher 85%
github.com/vmware-tanzu/vm-operator/pkg/vmconfig 95%
github.com/vmware-tanzu/vm-operator/pkg/vmconfig/anno2extraconfig 100%
github.com/vmware-tanzu/vm-operator/pkg/vmconfig/bootoptions 88%
github.com/vmware-tanzu/vm-operator/pkg/vmconfig/cdrom 88%
github.com/vmware-tanzu/vm-operator/pkg/vmconfig/crypto 92%
github.com/vmware-tanzu/vm-operator/pkg/vmconfig/diskpromo 100%
github.com/vmware-tanzu/vm-operator/pkg/vmconfig/extraconfig 100%
github.com/vmware-tanzu/vm-operator/pkg/vmconfig/networkextraconfig 71%
github.com/vmware-tanzu/vm-operator/pkg/vmconfig/policy 97%
github.com/vmware-tanzu/vm-operator/pkg/vmconfig/virtualcontroller 93%
github.com/vmware-tanzu/vm-operator/pkg/vmconfig/volumes/unmanaged/backfill 98%
github.com/vmware-tanzu/vm-operator/pkg/vmconfig/volumes/unmanaged/register 92%
github.com/vmware-tanzu/vm-operator/pkg/webconsolevalidation 100%
github.com/vmware-tanzu/vm-operator/services/vm-watcher 85%
github.com/vmware-tanzu/vm-operator/webhooks/common 98%
github.com/vmware-tanzu/vm-operator/webhooks/configtarget/validation 87%
github.com/vmware-tanzu/vm-operator/webhooks/persistentvolumeclaim/validation 95%
github.com/vmware-tanzu/vm-operator/webhooks/unifiedstoragequota/validation 89%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachine/mutation 86%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachine/validation 96%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachineclass/mutation 62%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachineclass/validation 89%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachineconfigoptions/validation 88%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachinegroup/mutation 87%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachinegroup/validation 93%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachinegrouppublishrequest/mutation 86%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachinegrouppublishrequest/validation 88%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachineguestoptions/validation 88%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachinepublishrequest/validation 90%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachinereplicaset/validation 90%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachineservice/mutation 67%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachineservice/validation 92%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachinesetresourcepolicy/validation 89%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachinesnapshot/mutation 86%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachinesnapshot/validation 91%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachinewebconsolerequest/v1alpha1/validation 92%
github.com/vmware-tanzu/vm-operator/webhooks/virtualmachinewebconsolerequest/validation 92%
Summary 84% (21507 / 25582)

Minimum allowed line rate is 79%

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

Labels

size/L Denotes a PR that changes 100-499 lines.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant