From a4189cd33add3233c553b6fb86c2f91ff15b82e4 Mon Sep 17 00:00:00 2001 From: Arik Hadas Date: Tue, 9 Apr 2024 12:32:30 +0300 Subject: [PATCH] vSphere: warn when independent disks are detected Signed-off-by: Arik Hadas --- .../provider/container/vsphere/model.go | 3 ++ .../provider/model/vsphere/model.go | 1 + .../konveyor/forklift/vmware/disk_mode.rego | 16 +++++++ .../forklift/vmware/disk_mode_test.rego | 47 +++++++++++++++++++ 4 files changed, 67 insertions(+) create mode 100644 validation/policies/io/konveyor/forklift/vmware/disk_mode.rego create mode 100644 validation/policies/io/konveyor/forklift/vmware/disk_mode_test.rego diff --git a/pkg/controller/provider/container/vsphere/model.go b/pkg/controller/provider/container/vsphere/model.go index 47f77fac1..4f57db2fe 100644 --- a/pkg/controller/provider/container/vsphere/model.go +++ b/pkg/controller/provider/container/vsphere/model.go @@ -691,6 +691,7 @@ func (v *VmAdapter) updateDisks(devArray *types.ArrayOfVirtualDevice) { Key: disk.Key, File: backing.FileName, Capacity: disk.CapacityInBytes, + Mode: backing.DiskMode, } if backing.Datastore != nil { datastoreId, _ := sanitize(backing.Datastore.Value) @@ -706,6 +707,7 @@ func (v *VmAdapter) updateDisks(devArray *types.ArrayOfVirtualDevice) { File: backing.FileName, Capacity: disk.CapacityInBytes, Shared: backing.Sharing != "sharingNone", + Mode: backing.DiskMode, } if backing.Datastore != nil { datastoreId, _ := sanitize(backing.Datastore.Value) @@ -721,6 +723,7 @@ func (v *VmAdapter) updateDisks(devArray *types.ArrayOfVirtualDevice) { File: backing.FileName, Capacity: disk.CapacityInBytes, Shared: backing.Sharing != "sharingNone", + Mode: backing.DiskMode, RDM: true, } if backing.Datastore != nil { diff --git a/pkg/controller/provider/model/vsphere/model.go b/pkg/controller/provider/model/vsphere/model.go index 42503faf7..3eacb2bb4 100644 --- a/pkg/controller/provider/model/vsphere/model.go +++ b/pkg/controller/provider/model/vsphere/model.go @@ -277,6 +277,7 @@ type Disk struct { Capacity int64 `json:"capacity"` Shared bool `json:"shared"` RDM bool `json:"rdm"` + Mode string `json:"mode,omitempty"` } // Virtual Device. diff --git a/validation/policies/io/konveyor/forklift/vmware/disk_mode.rego b/validation/policies/io/konveyor/forklift/vmware/disk_mode.rego new file mode 100644 index 000000000..d07ae1d0c --- /dev/null +++ b/validation/policies/io/konveyor/forklift/vmware/disk_mode.rego @@ -0,0 +1,16 @@ +package io.konveyor.forklift.vmware +import future.keywords.in + +independent_disk { + some i + input.disks[i].mode in ["independent_persistent", "independent_nonpersistent"] +} + +concerns[flag] { + independent_disk + flag := { + "category": "Warning", + "label": "Independent disk detected", + "assessment": "Independent disks cannot be transferred using recent versions of VDDK. It is recommended to change them in vSphere to 'Dependent' mode, or alternatively, to export the VM to an OVA." + } +} diff --git a/validation/policies/io/konveyor/forklift/vmware/disk_mode_test.rego b/validation/policies/io/konveyor/forklift/vmware/disk_mode_test.rego new file mode 100644 index 000000000..4d52943f5 --- /dev/null +++ b/validation/policies/io/konveyor/forklift/vmware/disk_mode_test.rego @@ -0,0 +1,47 @@ +package io.konveyor.forklift.vmware + +test_with_no_disks { + mock_vm := { + "name": "test", + "disks": [] + } + results := concerns with input as mock_vm + count(results) == 0 +} + +test_with_no_independent_disk { + mock_vm := { + "name": "test", + "disks": [ + { "shared": false }, + { "shared": false, "mode": "dependent" } + ] + } + results := concerns with input as mock_vm + count(results) == 0 +} + +test_with_independent_persistent_disk { + mock_vm := { + "name": "test", + "disks": [ + { "shared": false }, + { "shared": false, "mode": "dependent" }, + { "shared": false, "mode": "independent_persistent" } + ] + } + results := concerns with input as mock_vm + count(results) == 1 +} + +test_with_independent_nonpersistent_disk { + mock_vm := { + "name": "test", + "disks": [ + { "shared": false, "mode": "independent_nonpersistent" } + ] + } + results := concerns with input as mock_vm + count(results) == 1 +} +