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

Add a warning and support for TPM #665

Merged
merged 5 commits into from
Dec 27, 2023
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
8 changes: 8 additions & 0 deletions pkg/controller/plan/adapter/ovirt/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ func (r *Builder) VirtualMachine(vmRef ref.Ref, object *cnv.VirtualMachineSpec,
r.mapMemory(vm, object)
r.mapClock(vm, object)
r.mapInput(object)
r.mapTpm(vm, object)
err = r.mapNetworks(vm, object)
if err != nil {
return
Expand Down Expand Up @@ -504,6 +505,13 @@ func (r *Builder) mapDisks(vm *model.Workload, persistentVolumeClaims []core.Per
object.Template.Spec.Domain.Devices.Disks = kDisks
}

func (r *Builder) mapTpm(vm *model.Workload, object *cnv.VirtualMachineSpec) {
if vm.OSType == "windows_2022" || vm.OSType == "windows_11" {
persistData := true
object.Template.Spec.Domain.Devices.TPM = &cnv.TPMDevice{Persistent: &persistData}
}
}

// Build tasks.
func (r *Builder) Tasks(vmRef ref.Ref) (list []*plan.Task, err error) {
vm := &model.Workload{}
Expand Down
8 changes: 8 additions & 0 deletions pkg/controller/plan/adapter/vsphere/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ func (r *Builder) VirtualMachine(vmRef ref.Ref, object *cnv.VirtualMachineSpec,
r.mapMemory(vm, object)
r.mapClock(host, object)
r.mapInput(object)
r.mapTpm(vm, object)
err = r.mapNetworks(vm, object)
if err != nil {
return
Expand Down Expand Up @@ -639,6 +640,13 @@ func (r *Builder) mapDisks(vm *model.VM, persistentVolumeClaims []core.Persisten
object.Template.Spec.Domain.Devices.Disks = kDisks
}

func (r *Builder) mapTpm(vm *model.VM, object *cnv.VirtualMachineSpec) {
if vm.TpmEnabled {
persistData := true
object.Template.Spec.Domain.Devices.TPM = &cnv.TPMDevice{Persistent: &persistData}
}
}

// Build tasks.
func (r *Builder) Tasks(vmRef ref.Ref) (list []*plan.Task, err error) {
vm := &model.VM{}
Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/provider/container/vsphere/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ const (
fChangeTracking = "config.changeTrackingEnabled"
fGuestName = "summary.config.guestFullName"
fGuestID = "summary.guest.guestId"
fTpmPresent = "summary.config.tpmPresent"
fBalloonedMemory = "summary.quickStats.balloonedMemory"
fVmIpAddress = "summary.guest.ipAddress"
fStorageUsed = "summary.storage.committed"
Expand Down Expand Up @@ -714,6 +715,7 @@ func (r *Collector) propertySpec() []types.PropertySpec {
fExtraConfig,
fGuestName,
fGuestID,
fTpmPresent,
fBalloonedMemory,
fVmIpAddress,
fStorageUsed,
Expand Down
4 changes: 4 additions & 0 deletions pkg/controller/provider/container/vsphere/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,10 @@ func (v *VmAdapter) Apply(u types.ObjectUpdate) {
if s, cast := p.Val.(string); cast {
v.model.GuestName = s
}
case fTpmPresent:
if b, cast := p.Val.(bool); cast {
v.model.TpmEnabled = b
}
case fGuestID:
if s, cast := p.Val.(string); cast {
// When the VM isn't powered on, the guest tools don't report
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 @@ -256,6 +256,7 @@ type VM struct {
Snapshot Ref `sql:""`
IsTemplate bool `sql:""`
ChangeTrackingEnabled bool `sql:""`
TpmEnabled bool `sql:""`
Devices []Device `sql:""`
NICs []NIC `sql:""`
Disks []Disk `sql:""`
Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/provider/web/vsphere/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ type VM struct {
BalloonedMemory int32 `json:"balloonedMemory"`
IpAddress string `json:"ipAddress"`
StorageUsed int64 `json:"storageUsed"`
TpmEnabled bool `json:"tpmEnabled"`
NumaNodeAffinity []string `json:"numaNodeAffinity"`
Devices []model.Device `json:"devices"`
NICs []model.NIC `json:"nics"`
Expand All @@ -255,6 +256,7 @@ func (r *VM) With(m *model.VM) {
r.BalloonedMemory = m.BalloonedMemory
r.IpAddress = m.IpAddress
r.StorageUsed = m.StorageUsed
r.TpmEnabled = m.TpmEnabled
r.FaultToleranceEnabled = m.FaultToleranceEnabled
r.Devices = m.Devices
r.NumaNodeAffinity = m.NumaNodeAffinity
Expand Down
16 changes: 16 additions & 0 deletions validation/policies/io/konveyor/forklift/ovirt/tpm.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.konveyor.forklift.ovirt

default has_tpm_os = false

has_tpm_os = true {
regex.match(`windows_2022|windows_11`, input.osType)
}

concerns[flag] {
has_tpm_os
flag := {
"category": "Warning",
"label": "VM configured with a TPM device",
"assessment": "The VM is detected with an operation system that must have a TPM device. TPM data is not transferred during the migration."
}
}
25 changes: 25 additions & 0 deletions validation/policies/io/konveyor/forklift/ovirt/tpm_test.rego
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.konveyor.forklift.ovirt

test_without_tpm_enabled {
mock_vm := { "name": "test",
"osType": "rhel_9x64"
}
results = concerns with input as mock_vm
count(results) == 0
}

test_with_tpm_enabled_w11 {
mock_vm := { "name": "test",
"osType": "windows_11"
}
results = concerns with input as mock_vm
count(results) == 1
}

test_with_tpm_enabled_w2k22 {
mock_vm := { "name": "test",
"osType": "windows_2022"
}
results = concerns with input as mock_vm
count(results) == 1
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.konveyor.forklift.vmware

default has_tpm_enabled = false

has_tpm_enabled = true {
input.tpmEnabled == true
}

concerns[flag] {
has_tpm_enabled
flag := {
"category": "Warning",
"label": "VM configured with a TPM device",
"assessment": "The VM is configured with a TPM device. TPM data is not transferred during the migration."
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.konveyor.forklift.vmware

test_with_tpm_disabled {
mock_vm := {
"name": "test",
"tpmEnabled": false,
}
results := concerns with input as mock_vm
count(results) == 0
}

test_with_cpu_hot_add_enabled {
mock_vm := {
"name": "test",
"tpmEnabled": true
}
results := concerns with input as mock_vm
count(results) == 1
}
Loading