diff --git a/pkg/controller/plan/kubevirt.go b/pkg/controller/plan/kubevirt.go index 8652aca30..f038cf8cc 100644 --- a/pkg/controller/plan/kubevirt.go +++ b/pkg/controller/plan/kubevirt.go @@ -523,7 +523,8 @@ func (r *KubeVirt) DeleteVM(vm *plan.VMStatus) (err error) { } func (r *KubeVirt) DataVolumes(vm *plan.VMStatus) (dataVolumes []cdi.DataVolume, err error) { - secret, err := r.ensureSecret(vm.Ref, r.secretDataSetterForCDI(vm.Ref), false) + labels := r.vmLabels(vm.Ref) + secret, err := r.ensureSecret(vm.Ref, r.secretDataSetterForCDI(vm.Ref), labels) if err != nil { return } @@ -540,7 +541,8 @@ func (r *KubeVirt) DataVolumes(vm *plan.VMStatus) (dataVolumes []cdi.DataVolume, } func (r *KubeVirt) PopulatorVolumes(vmRef ref.Ref) (pvcs []*core.PersistentVolumeClaim, err error) { - secret, err := r.ensureSecret(vmRef, r.copyDataFromProviderSecret, false) + labels := r.vmLabels(vmRef) + secret, err := r.ensureSecret(vmRef, r.copyDataFromProviderSecret, labels) if err != nil { err = liberr.Wrap(err) return @@ -781,7 +783,8 @@ func (r *KubeVirt) getListOptionsNamespaced() (listOptions *client.ListOptions) // Ensure the guest conversion (virt-v2v) pod exists on the destination. func (r *KubeVirt) EnsureGuestConversionPod(vm *plan.VMStatus, vmCr *VirtualMachine, pvcs []*core.PersistentVolumeClaim) (err error) { - v2vSecret, err := r.ensureSecret(vm.Ref, r.secretDataSetterForCDI(vm.Ref), false) + labels := r.vmLabels(vm.Ref) + v2vSecret, err := r.ensureSecret(vm.Ref, r.secretDataSetterForCDI(vm.Ref), labels) if err != nil { return } @@ -1762,7 +1765,9 @@ func (r *KubeVirt) podVolumeMounts(vmVolumes []cnv.Volume, configMap *core.Confi }, }) if vm.LUKS.Name != "" { - secret, erro := r.ensureSecret(vm.Ref, r.secretLUKS(vm.LUKS.Name, r.Plan.Namespace), true) + labels := r.vmLabels(vm.Ref) + labels[kLUKS] = "true" + secret, erro := r.ensureSecret(vm.Ref, r.secretLUKS(vm.LUKS.Name, r.Plan.Namespace), labels) if erro != nil { err = liberr.Wrap(erro) return @@ -1976,13 +1981,13 @@ func (r *KubeVirt) secretLUKS(name, namespace string) func(*core.Secret) error { } // Ensure the credential secret for the data transfer exists on the destination. -func (r *KubeVirt) ensureSecret(vmRef ref.Ref, setSecretData func(*core.Secret) error, isLUKS bool) (secret *core.Secret, err error) { +func (r *KubeVirt) ensureSecret(vmRef ref.Ref, setSecretData func(*core.Secret) error, labels map[string]string) (secret *core.Secret, err error) { _, err = r.Source.Inventory.VM(&vmRef) if err != nil { return } - newSecret, err := r.secret(vmRef, setSecretData, isLUKS) + newSecret, err := r.secret(vmRef, setSecretData, labels) if err != nil { return } @@ -2041,11 +2046,7 @@ func (r *KubeVirt) ensureSecret(vmRef ref.Ref, setSecretData func(*core.Secret) } // Build the credential secret for the data transfer (CDI importer / popoulator pod). -func (r *KubeVirt) secret(vmRef ref.Ref, setSecretData func(*core.Secret) error, isLUKS bool) (secret *core.Secret, err error) { - labels := r.vmLabels(vmRef) - if isLUKS { - labels[kLUKS] = "true" - } +func (r *KubeVirt) secret(vmRef ref.Ref, setSecretData func(*core.Secret) error, labels map[string]string) (secret *core.Secret, err error) { secret = &core.Secret{ ObjectMeta: meta.ObjectMeta{ Labels: labels, diff --git a/virt-v2v/cold/entrypoint.go b/virt-v2v/cold/entrypoint.go index 245e82b89..1c1888a43 100644 --- a/virt-v2v/cold/entrypoint.go +++ b/virt-v2v/cold/entrypoint.go @@ -129,13 +129,7 @@ func buildCommand() []string { } } // Adds LUKS keys, if exist. - if _, err := os.Stat(LUKSDIR); os.IsNotExist(err) { - // do nothing - } else { - if err != nil { - fmt.Println("Error accessing the LUKS directory ", err) - os.Exit(1) - } + if _, err := os.Stat(LUKSDIR); err == nil { files, err := getFilesInPath(LUKSDIR) if err != nil { fmt.Println("Error reading files in LUKS directory ", err) @@ -144,6 +138,9 @@ func buildCommand() []string { for _, file := range files { virtV2vArgs = append(virtV2vArgs, "--key", fmt.Sprintf("all:file:%s", file)) } + } else if !os.IsNotExist(err) { + fmt.Println("Error accessing the LUKS directory ", err) + os.Exit(1) } if info, err := os.Stat(VDDK); err == nil && info.IsDir() {