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() {