From a5ec26c303172bc23b044637e35c0a910889ca9f Mon Sep 17 00:00:00 2001 From: Bryan Venteicher Date: Wed, 28 Jan 2026 17:32:19 -0600 Subject: [PATCH] Add annotation to skip registering unmanaged volumes When present, this annotation will cause the reconcile to exit early and update the condition to indicate that the annotation has been seen. This is useful for an external operation that needs to either prevent registration, or perform an unregister once disks are registered. --- pkg/constants/constants.go | 4 ++++ .../register/unmanagedvolumes_register.go | 10 ++++++++++ .../unmanagedvolumes_register_test.go | 20 +++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index 4a75bb086..257a1d326 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -252,4 +252,8 @@ const ( // CreatedByLabel is the label key that indicates an object was // created on behalf of a VM Operator VM. The value is the name of a VM. CreatedByLabel = "vmoperator.vmware.com/created-by" + + // NoUnmanagedVolumesRegisterAnnotationKey is the annotation to not create any CNSRegisterVolumes + // by skipping the unmanaged volume register reconcile. + NoUnmanagedVolumesRegisterAnnotationKey = "vmoperator.vmware.com/no-unmanaged-volumes-register" ) diff --git a/pkg/vmconfig/volumes/unmanaged/register/unmanagedvolumes_register.go b/pkg/vmconfig/volumes/unmanaged/register/unmanagedvolumes_register.go index 508a8a731..ad9704080 100644 --- a/pkg/vmconfig/volumes/unmanaged/register/unmanagedvolumes_register.go +++ b/pkg/vmconfig/volumes/unmanaged/register/unmanagedvolumes_register.go @@ -117,6 +117,16 @@ func (r reconciler) Reconcile( logger := pkglog.FromContextOrDefault(ctx) + if _, ok := vm.Annotations[pkgconst.NoUnmanagedVolumesRegisterAnnotationKey]; ok { + logger.Info("Skipping register unmanaged volumes because of annotation") + pkgcond.MarkFalse( + vm, + Condition, + "NoUnmanagedVolumesRegisterAnnotation", + "") + return nil + } + // Check if the VM is in the middle of promoting linked cloned disks. for _, t := range pkgctx.GetVMRecentTasks(ctx) { // If so, then return early. diff --git a/pkg/vmconfig/volumes/unmanaged/register/unmanagedvolumes_register_test.go b/pkg/vmconfig/volumes/unmanaged/register/unmanagedvolumes_register_test.go index c392ab2e3..981ad3690 100644 --- a/pkg/vmconfig/volumes/unmanaged/register/unmanagedvolumes_register_test.go +++ b/pkg/vmconfig/volumes/unmanaged/register/unmanagedvolumes_register_test.go @@ -315,6 +315,26 @@ var _ = Describe("Reconcile", func() { configSpec)).To(Succeed()) }) }) + + When("VM has NoUnmanagedVolumesRegisterAnnotationKey annotation", func() { + BeforeEach(func() { + vm.Annotations[pkgconst.NoUnmanagedVolumesRegisterAnnotationKey] = "" + }) + + It("should return nil without error and update condition", func() { + Expect(unmanagedvolsreg.Reconcile( + ctx, + k8sClient, + vimClient, + vm, + moVM, + configSpec)).To(Succeed()) + cond := pkgcond.Get(vm, unmanagedvolsreg.Condition) + Expect(cond).ToNot(BeNil()) + Expect(cond.Status).To(Equal(metav1.ConditionFalse)) + Expect(cond.Reason).To(Equal("NoUnmanagedVolumesRegisterAnnotation")) + }) + }) }) Context("PVC creation and management", func() {