Skip to content

Commit c0ff571

Browse files
committed
Added some new uses of VirtualMachines causing errors
if virtual machine CRDs were not installed. This fixes it so that it ignores the no match for kind error and continues on. Signed-off-by: Alexander Wels <[email protected]>
1 parent 65087ec commit c0ff571

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

pkg/controller/directvolumemigration/vm.go

+21
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ func getVolumeNameToVmMap(client k8sclient.Client, namespace string) (map[string
222222
vmList := virtv1.VirtualMachineList{}
223223
err := client.List(context.TODO(), &vmList, k8sclient.InNamespace(namespace))
224224
if err != nil {
225+
if meta.IsNoMatchError(err) {
226+
return nil, nil
227+
}
225228
return nil, err
226229
}
227230
for _, vm := range vmList.Items {
@@ -244,6 +247,9 @@ func (t *Task) storageLiveMigrateVM(vmName, namespace string, volumes *vmVolumes
244247
}
245248
vm := &virtv1.VirtualMachine{}
246249
if err := sourceClient.Get(context.TODO(), k8sclient.ObjectKey{Namespace: namespace, Name: vmName}, vm); err != nil {
250+
if meta.IsNoMatchError(err) {
251+
return nil
252+
}
247253
return err
248254
}
249255
// Check if the source volumes match before attempting to migrate.
@@ -312,6 +318,9 @@ func (t *Task) verifyVMs() error {
312318
vm := &virtv1.VirtualMachine{}
313319
err := sourceClient.Get(context.TODO(), k8sclient.ObjectKey{Namespace: namespace, Name: vmName}, vm)
314320
if err != nil {
321+
if meta.IsNoMatchError(err) {
322+
return nil
323+
}
315324
t.Log.Info("Failed to get running VM", "err", err)
316325
return liberr.Wrap(FatalPlanError, err.Error())
317326
}
@@ -335,6 +344,9 @@ func (t *Task) verifyVMs() error {
335344
func findVirtualMachineInstanceMigration(client k8sclient.Client, vmName, namespace string) (*virtv1.VirtualMachineInstanceMigration, error) {
336345
vmimList := &virtv1.VirtualMachineInstanceMigrationList{}
337346
if err := client.List(context.TODO(), vmimList, k8sclient.InNamespace(namespace)); err != nil {
347+
if meta.IsNoMatchError(err) {
348+
return nil, nil
349+
}
338350
if k8serrors.IsNotFound(err) {
339351
return nil, nil
340352
}
@@ -401,6 +413,9 @@ func virtualMachineMigrationStatus(client k8sclient.Client, vmName, namespace st
401413
func cancelLiveMigration(client k8sclient.Client, vmName, namespace string, volumes *vmVolumes, log logr.Logger) error {
402414
vm := &virtv1.VirtualMachine{}
403415
if err := client.Get(context.TODO(), k8sclient.ObjectKey{Namespace: namespace, Name: vmName}, vm); err != nil {
416+
if meta.IsNoMatchError(err) {
417+
return nil
418+
}
404419
return err
405420
}
406421

@@ -414,6 +429,9 @@ func cancelLiveMigration(client k8sclient.Client, vmName, namespace string, volu
414429
func liveMigrationsCompleted(client k8sclient.Client, namespace string, vmNames []string) (bool, error) {
415430
vmim := &virtv1.VirtualMachineInstanceMigrationList{}
416431
if err := client.List(context.TODO(), vmim, k8sclient.InNamespace(namespace)); err != nil {
432+
if meta.IsNoMatchError(err) {
433+
return true, nil
434+
}
417435
return false, err
418436
}
419437
completed := true
@@ -569,6 +587,9 @@ func (t *Task) getVolumeVMIMInNamespaces(namespaces []string) (map[string]*virtv
569587
for volumeName, vmName := range volumeVMMap {
570588
vmimList := &virtv1.VirtualMachineInstanceMigrationList{}
571589
if err := t.sourceClient.List(context.TODO(), vmimList, k8sclient.InNamespace(namespace)); err != nil {
590+
if meta.IsNoMatchError(err) {
591+
return nil, nil
592+
}
572593
return nil, err
573594
}
574595
for _, vmim := range vmimList.Items {

pkg/pods/template.go

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
batchv1 "k8s.io/api/batch/v1"
1010
batchv1beta "k8s.io/api/batch/v1beta1"
1111
corev1 "k8s.io/api/core/v1"
12+
"k8s.io/apimachinery/pkg/api/meta"
1213
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1314
virtv1 "kubevirt.io/api/core/v1"
1415
k8sclient "sigs.k8s.io/controller-runtime/pkg/client"
@@ -312,6 +313,9 @@ func listVirtualMachineTemplatePodsForNamespace(client k8sclient.Client, ns stri
312313
list := virtv1.VirtualMachineList{}
313314
err := client.List(context.TODO(), &list, k8sclient.InNamespace(ns))
314315
if err != nil {
316+
if meta.IsNoMatchError(err) {
317+
return pods, nil
318+
}
315319
return nil, err
316320
}
317321
for _, vm := range list.Items {

0 commit comments

Comments
 (0)