Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vSphere: warn when independent disks are detected #894

Merged
merged 2 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions pkg/controller/provider/container/vsphere/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,13 +685,13 @@ func (v *VmAdapter) updateDisks(devArray *types.ArrayOfVirtualDevice) {
switch dev.(type) {
case *types.VirtualDisk:
disk := dev.(*types.VirtualDisk)
switch disk.Backing.(type) {
switch backing := disk.Backing.(type) {
case *types.VirtualDiskFlatVer1BackingInfo:
backing := disk.Backing.(*types.VirtualDiskFlatVer1BackingInfo)
md := model.Disk{
Key: disk.Key,
File: backing.FileName,
Capacity: disk.CapacityInBytes,
Mode: backing.DiskMode,
}
if backing.Datastore != nil {
datastoreId, _ := sanitize(backing.Datastore.Value)
Expand All @@ -702,12 +702,12 @@ func (v *VmAdapter) updateDisks(devArray *types.ArrayOfVirtualDevice) {
}
disks = append(disks, md)
case *types.VirtualDiskFlatVer2BackingInfo:
backing := disk.Backing.(*types.VirtualDiskFlatVer2BackingInfo)
md := model.Disk{
Key: disk.Key,
File: backing.FileName,
Capacity: disk.CapacityInBytes,
Shared: backing.Sharing != "sharingNone",
Mode: backing.DiskMode,
}
if backing.Datastore != nil {
datastoreId, _ := sanitize(backing.Datastore.Value)
Expand All @@ -718,12 +718,12 @@ func (v *VmAdapter) updateDisks(devArray *types.ArrayOfVirtualDevice) {
}
disks = append(disks, md)
case *types.VirtualDiskRawDiskMappingVer1BackingInfo:
backing := disk.Backing.(*types.VirtualDiskRawDiskMappingVer1BackingInfo)
md := model.Disk{
Key: disk.Key,
File: backing.FileName,
Capacity: disk.CapacityInBytes,
Shared: backing.Sharing != "sharingNone",
Mode: backing.DiskMode,
RDM: true,
}
if backing.Datastore != nil {
Expand All @@ -735,7 +735,6 @@ func (v *VmAdapter) updateDisks(devArray *types.ArrayOfVirtualDevice) {
}
disks = append(disks, md)
case *types.VirtualDiskRawDiskVer2BackingInfo:
backing := disk.Backing.(*types.VirtualDiskRawDiskVer2BackingInfo)
md := model.Disk{
Key: disk.Key,
File: backing.DescriptorFileName,
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/provider/model/vsphere/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 16 additions & 0 deletions validation/policies/io/konveyor/forklift/vmware/disk_mode.rego
Original file line number Diff line number Diff line change
@@ -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."
}
}
Original file line number Diff line number Diff line change
@@ -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
}

Loading