Skip to content

Commit

Permalink
test: Fix VM controller tests pod GC error
Browse files Browse the repository at this point in the history
  • Loading branch information
scuzhanglei authored and fengye87 committed Jul 14, 2022
1 parent 5e8c111 commit 5f1c96a
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions pkg/controller/vm_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

virtv1alpha1 "github.com/smartxworks/virtink/pkg/apis/virt/v1alpha1"
)
Expand Down Expand Up @@ -213,25 +211,24 @@ var _ = Describe("VM controller", func() {
}
Expect(k8sClient.Create(ctx, &vm)).To(Succeed())

By("creating the VM pod")
By("updating VM phase to Scheduling")
vmPodKey = types.NamespacedName{
Name: uuid.New().String(),
Namespace: vmKey.Namespace,
}
vmPod := corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: vmPodKey.Name,
Namespace: vmPodKey.Namespace,
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{{
Name: "container",
Image: "image",
}},
},
}
Expect(controllerutil.SetControllerReference(&vm, &vmPod, scheme.Scheme)).To(Succeed())
Expect(k8sClient.Create(ctx, &vmPod)).To(Succeed())
Eventually(func() bool {
var vm virtv1alpha1.VirtualMachine
Expect(k8sClient.Get(ctx, vmKey, &vm)).To(Succeed())
vm.Status.Phase = virtv1alpha1.VirtualMachineScheduling
vm.Status.VMPodName = vmPodKey.Name
return k8sClient.Status().Update(ctx, &vm) == nil
}).Should(BeTrue())

By("checking the VM pod has been created")
Eventually(func() bool {
var vmPod corev1.Pod
return k8sClient.Get(ctx, vmPodKey, &vmPod) == nil
}).Should(BeTrue())

By("binding the VM pod")
nodeName := uuid.New().String()
Expand Down

0 comments on commit 5f1c96a

Please sign in to comment.