Skip to content

Commit

Permalink
Add a check to the LUKS secret existence
Browse files Browse the repository at this point in the history
Instead of the plan keep being running and the conversion pod try to
init, we can query and check the secret existence for LUKS keys before.
In the case it's doesn't exist, fail the migration properly.

Signed-off-by: Liran Rotenberg <[email protected]>
  • Loading branch information
liranr23 committed May 29, 2024
1 parent abcddd7 commit 6afd76a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pkg/controller/plan/kubevirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -1760,6 +1760,11 @@ func (r *KubeVirt) podVolumeMounts(vmVolumes []cnv.Volume, configMap *core.Confi
},
})
if vm.LUKS.Name != "" {
err = r.isSecretExist(vm.LUKS.Name, r.Plan.Spec.TargetNamespace)
if err != nil {
err = liberr.Wrap(err)
return

Check warning on line 1766 in pkg/controller/plan/kubevirt.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/plan/kubevirt.go#L1762-L1766

Added lines #L1762 - L1766 were not covered by tests
}
volumes = append(volumes, core.Volume{
Name: "luks",
VolumeSource: core.VolumeSource{
Expand Down Expand Up @@ -1956,6 +1961,12 @@ func (r *KubeVirt) secretDataSetterForCDI(vmRef ref.Ref) func(*core.Secret) erro
}
}

func (r *KubeVirt) isSecretExist(name, namespace string) (err error) {
secret := &core.Secret{}
err = r.Destination.Client.Get(context.TODO(), client.ObjectKey{Name: name, Namespace: namespace}, secret)
return

Check warning on line 1967 in pkg/controller/plan/kubevirt.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/plan/kubevirt.go#L1964-L1967

Added lines #L1964 - L1967 were not covered by tests
}

// Ensure the credential secret for the data transfer exists on the destination.
func (r *KubeVirt) ensureSecret(vmRef ref.Ref, setSecretData func(*core.Secret) error) (secret *core.Secret, err error) {
_, err = r.Source.Inventory.VM(&vmRef)
Expand Down

0 comments on commit 6afd76a

Please sign in to comment.