diff --git a/operator/config/crd/bases/forklift.konveyor.io_migrations.yaml b/operator/config/crd/bases/forklift.konveyor.io_migrations.yaml index c99739f63..b480534cd 100644 --- a/operator/config/crd/bases/forklift.konveyor.io_migrations.yaml +++ b/operator/config/crd/bases/forklift.konveyor.io_migrations.yaml @@ -297,6 +297,9 @@ spec: description: 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 phase: description: Phase type: string diff --git a/operator/config/crd/bases/forklift.konveyor.io_plans.yaml b/operator/config/crd/bases/forklift.konveyor.io_plans.yaml index d23356159..b96328e25 100644 --- a/operator/config/crd/bases/forklift.konveyor.io_plans.yaml +++ b/operator/config/crd/bases/forklift.konveyor.io_plans.yaml @@ -737,6 +737,10 @@ spec: description: 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 phase: description: Phase type: string diff --git a/pkg/apis/forklift/v1beta1/plan/vm.go b/pkg/apis/forklift/v1beta1/plan/vm.go index d2d2444bd..127e9b02f 100644 --- a/pkg/apis/forklift/v1beta1/plan/vm.go +++ b/pkg/apis/forklift/v1beta1/plan/vm.go @@ -61,6 +61,8 @@ type VMStatus struct { RestorePowerState VMPowerState `json:"restorePowerState,omitempty"` // The firmware type detected from the OVF file produced by virt-v2v. Firmware string `json:"firmware,omitempty"` + // The new name of the VM after matching DNS1123 requirements. + NewName string `json:"newName,omitempty"` // Conditions. libcnd.Conditions `json:",inline"` diff --git a/pkg/controller/plan/kubevirt.go b/pkg/controller/plan/kubevirt.go index df813c310..5c23011af 100644 --- a/pkg/controller/plan/kubevirt.go +++ b/pkg/controller/plan/kubevirt.go @@ -24,7 +24,6 @@ import ( "k8s.io/apimachinery/pkg/conversion" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" - k8svalidation "k8s.io/apimachinery/pkg/util/validation" "k8s.io/apimachinery/pkg/util/wait" cnv "kubevirt.io/api/core/v1" instancetype "kubevirt.io/api/instancetype/v1beta1" @@ -1168,13 +1167,9 @@ 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) } @@ -1545,6 +1540,12 @@ func (r *KubeVirt) guestConversionPod(vm *plan.VMStatus, vmVolumes []cnv.Volume, if err != nil { return } + environment = append(environment, + core.EnvVar{ + Name: "V2V_NewName", + Value: vm.NewName, + }) + // pod annotations annotations := map[string]string{} if r.Plan.Spec.TransferNetwork != nil { diff --git a/pkg/controller/plan/migration.go b/pkg/controller/plan/migration.go index 699a36a61..d16381cb1 100644 --- a/pkg/controller/plan/migration.go +++ b/pkg/controller/plan/migration.go @@ -28,6 +28,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" ) @@ -709,6 +710,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} diff --git a/virt-v2v/cold/entrypoint.go b/virt-v2v/cold/entrypoint.go index af29615a3..3a749e90a 100644 --- a/virt-v2v/cold/entrypoint.go +++ b/virt-v2v/cold/entrypoint.go @@ -64,8 +64,13 @@ func main() { fmt.Println("Error creating directory ", err) os.Exit(1) } - virtV2vArgs = append(virtV2vArgs, "-o", "kubevirt", "-os", DIR) + virtV2vArgs = append(virtV2vArgs, "-o", "kubevirt") + if checkEnvVariablesSet("V2V_NewName") { + virtV2vArgs = append(virtV2vArgs, "-on", os.Getenv("V2V_NewName")) + } + + virtV2vArgs = append(virtV2vArgs, "-os", DIR) //Disks on filesystem storage. if err := LinkDisks(FS, 15); err != nil { os.Exit(1)