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

Change created virt-v2v conversion output to -o kubeVirt #778

Closed
wants to merge 11 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,9 @@ spec:
The VM Namespace
Only relevant for an openshift source.
type: string
newName:
description: The new name of the VM after matching DNS1123 requirements.
type: string
bkhizgiy marked this conversation as resolved.
Show resolved Hide resolved
operatingSystem:
description: The Operating System detected by virt-v2v.
type: string
Expand Down
4 changes: 4 additions & 0 deletions operator/config/crd/bases/forklift.konveyor.io_plans.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,10 @@ spec:
The VM Namespace
Only relevant for an openshift source.
type: string
newName:
description: The new name of the VM after matching DNS1123
requirements.
type: string
operatingSystem:
description: The Operating System detected by virt-v2v.
type: string
Expand Down
2 changes: 2 additions & 0 deletions pkg/apis/forklift/v1beta1/plan/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ type VMStatus struct {
Firmware string `json:"firmware,omitempty"`
// The Operating System detected by virt-v2v.
OperatingSystem string `json:"operatingSystem,omitempty"`
// The new name of the VM after matching DNS1123 requirements.
NewName string `json:"newName,omitempty"`

// Conditions.
libcnd.Conditions `json:",inline"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/plan/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ go_library(
"//pkg/controller/base",
"//pkg/controller/plan/adapter",
"//pkg/controller/plan/adapter/base",
"//pkg/controller/plan/adapter/ova",
"//pkg/controller/plan/context",
"//pkg/controller/plan/handler",
"//pkg/controller/plan/scheduler",
"//pkg/controller/plan/util",
"//pkg/controller/provider/web",
"//pkg/controller/provider/web/vsphere",
"//pkg/controller/validation",
Expand Down
2 changes: 0 additions & 2 deletions pkg/controller/plan/adapter/ova/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ go_library(
"builder.go",
"client.go",
"destinationclient.go",
"ovfparser.go",
"validator.go",
],
importpath = "github.com/konveyor/forklift-controller/pkg/controller/plan/adapter/ova",
Expand All @@ -27,7 +26,6 @@ go_library(
"//pkg/lib/error",
"//pkg/lib/inventory/web",
"//pkg/lib/itinerary",
"//pkg/lib/logging",
"//vendor/github.com/go-logr/logr",
"//vendor/k8s.io/api/core/v1:core",
"//vendor/k8s.io/apimachinery/pkg/api/resource",
Expand Down
146 changes: 0 additions & 146 deletions pkg/controller/plan/adapter/ova/ovfparser.go

This file was deleted.

35 changes: 20 additions & 15 deletions pkg/controller/plan/kubevirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"time"

planbase "github.com/konveyor/forklift-controller/pkg/controller/plan/adapter/base"
"github.com/konveyor/forklift-controller/pkg/controller/plan/util"
"github.com/konveyor/forklift-controller/pkg/controller/provider/web"
model "github.com/konveyor/forklift-controller/pkg/controller/provider/web/vsphere"
libref "github.com/konveyor/forklift-controller/pkg/lib/ref"
Expand All @@ -28,7 +29,6 @@ import (
"k8s.io/apimachinery/pkg/conversion"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
k8svalidation "k8s.io/apimachinery/pkg/util/validation"
cnv "kubevirt.io/api/core/v1"
instancetypeapi "kubevirt.io/api/instancetype"
instancetype "kubevirt.io/api/instancetype/v1beta1"
Expand All @@ -38,7 +38,6 @@ import (
"github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1/plan"
"github.com/konveyor/forklift-controller/pkg/apis/forklift/v1beta1/ref"
"github.com/konveyor/forklift-controller/pkg/controller/plan/adapter"
ovfparser "github.com/konveyor/forklift-controller/pkg/controller/plan/adapter/ova"
plancontext "github.com/konveyor/forklift-controller/pkg/controller/plan/context"
libcnd "github.com/konveyor/forklift-controller/pkg/lib/condition"
liberr "github.com/konveyor/forklift-controller/pkg/lib/error"
Expand Down Expand Up @@ -941,7 +940,7 @@ func (r *KubeVirt) UpdateVmByConvertedConfig(vm *plan.VMStatus, pod *core.Pod, s
return
}

url := fmt.Sprintf("http://%s:8080/ovf", pod.Status.PodIP)
url := fmt.Sprintf("http://%s:8080/vm", pod.Status.PodIP)

/* Due to the virt-v2v operation, the ovf file is only available after the command's execution,
meaning it appears following the copydisks phase.
Expand All @@ -959,24 +958,24 @@ func (r *KubeVirt) UpdateVmByConvertedConfig(vm *plan.VMStatus, pod *core.Pod, s
}
defer resp.Body.Close()

vmConfigBytes, err := io.ReadAll(resp.Body)
vmConf, err := io.ReadAll(resp.Body)
if err != nil {
err = liberr.Wrap(err)
return
}
vmConfigXML := string(vmConfigBytes)

switch r.Source.Provider.Type() {
case api.Ova:
if vm.Firmware, err = ovfparser.GetFirmwareFromConfig(vmConfigXML); err != nil {
if vm.Firmware, err = util.GetFirmwareFromYaml(vmConf); err != nil {
err = liberr.Wrap(err)
return
}
case api.VSphere:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so wouldn't it be missing for vSphere?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this function is called during the conversion phase in the migration process, so both vSphere and OVA providers enter here. Instead of applying it only to vSphere, it will apply to OVA as well.

if vm.OperatingSystem, err = ovfparser.GetOperationSystemFromConfig(vmConfigXML); err != nil {
r.Log.Info("Setting the vm firmware ", vm.Firmware, "vmId", vm.ID)

if vm.OperatingSystem, err = util.GetOperationSystemFromYaml(vmConf); err != nil {
bkhizgiy marked this conversation as resolved.
Show resolved Hide resolved
err = liberr.Wrap(err)
return
}
r.Log.Info("Setting the vm OS ", vm.OperatingSystem, "vmId", vm.ID)
}

shutdownURL := fmt.Sprintf("http://%s:8080/shutdown", pod.Status.PodIP)
Expand Down Expand Up @@ -1260,13 +1259,10 @@ func (r *KubeVirt) virtualMachine(vm *plan.VMStatus) (object *cnv.VirtualMachine
//convention it will be automatically changed.
var originalName string

if errs := k8svalidation.IsDNS1123Label(vm.Name); len(errs) > 0 {
if vm.NewName != "" {
originalName = vm.Name
vm.Name, err = r.changeVmNameDNS1123(vm.Name, r.Plan.Spec.TargetNamespace)
if err != nil {
r.Log.Error(err, "Failed to update the VM name to meet DNS1123 protocol requirements.")
return
}
vm.Name = vm.NewName

r.Log.Info("VM name is incompatible with DNS1123 RFC, renaming",
"originalName", originalName, "newName", vm.Name)
}
Expand Down Expand Up @@ -1722,6 +1718,15 @@ func (r *KubeVirt) guestConversionPod(vm *plan.VMStatus, vmVolumes []cnv.Volume,
Value: vm.RootDisk,
})
}

if vm.NewName != "" {
environment = append(environment,
core.EnvVar{
Name: "V2V_NewName",
Value: vm.NewName,
})
}

// pod annotations
annotations := map[string]string{}
if r.Plan.Spec.TransferNetwork != nil {
Expand Down
8 changes: 8 additions & 0 deletions pkg/controller/plan/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
meta "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
k8svalidation "k8s.io/apimachinery/pkg/util/validation"
cdi "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1"
"sigs.k8s.io/controller-runtime/pkg/client"
)
Expand Down Expand Up @@ -718,6 +719,13 @@ func (r *Migration) execute(vm *plan.VMStatus) (err error) {
err = nil
break
}
if errs := k8svalidation.IsDNS1123Label(vm.Name); len(errs) > 0 {
vm.NewName, err = r.kubevirt.changeVmNameDNS1123(vm.Name, r.Plan.Spec.TargetNamespace)
if err != nil {
r.Log.Error(err, "Failed to update the VM name to meet DNS1123 protocol requirements.")
return
}
}
vm.Phase = r.next(vm.Phase)
case PreHook, PostHook:
runner := HookRunner{Context: r.Context}
Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/plan/util/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "util",
srcs = [
"kubevirtvmparser.go",
"openstack.go",
"ovirt.go",
"utils.go",
Expand All @@ -13,7 +14,9 @@ go_library(
"//pkg/apis/forklift/v1beta1",
"//pkg/controller/provider/web/openstack",
"//pkg/controller/provider/web/ovirt",
"//pkg/lib/logging",
"//pkg/settings",
"//vendor/gopkg.in/yaml.v2:yaml_v2",
"//vendor/k8s.io/api/core/v1:core",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:meta",
],
Expand Down
Loading
Loading