Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Arik Hadas <[email protected]>
  • Loading branch information
ahadas committed Jun 9, 2024
1 parent 480d139 commit 30911ab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
23 changes: 12 additions & 11 deletions pkg/controller/plan/kubevirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 4 additions & 7 deletions virt-v2v/cold/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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() {
Expand Down

0 comments on commit 30911ab

Please sign in to comment.