Skip to content

Commit

Permalink
Merge pull request kubevirt#8095 from jean-edouard/waitforcrdelete
Browse files Browse the repository at this point in the history
tests: single-replica: improve and hopefully un-flake
  • Loading branch information
kubevirt-bot authored Jul 14, 2022
2 parents 989ac54 + 173f17f commit d86f5fb
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions tests/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2637,8 +2637,17 @@ spec:
kvOrig := copyOriginalKv()
kv := copyOriginalKv()

By("storing the actual replica counts for the cluster")
originalReplicaCounts := make(map[string]int)
for _, name := range []string{"virt-api", "virt-controller"} {
pods, err := virtClient.CoreV1().Pods(flags.KubeVirtInstallNamespace).List(context.Background(), metav1.ListOptions{LabelSelector: fmt.Sprintf("%s=%s", v1.AppLabel, name)})
Expect(err).ToNot(HaveOccurred())
originalReplicaCounts[name] = len(pods.Items)
}

By("deleting the kv CR")
virtClient.KubeVirt(kv.Namespace).Delete(kv.Name, &metav1.DeleteOptions{})
err = virtClient.KubeVirt(kv.Namespace).Delete(kv.Name, &metav1.DeleteOptions{})
Expect(err).ToNot(HaveOccurred())

By("waiting for virt-api and virt-controller to be gone")
Eventually(func() bool {
Expand All @@ -2652,6 +2661,12 @@ spec:
return true
}, 120*time.Second, 4*time.Second).Should(BeTrue())

By("waiting for the kv CR to be gone")
Eventually(func() bool {
_, err := virtClient.KubeVirt(kv.Namespace).Get(kv.Name, &metav1.GetOptions{})
return errors.IsNotFound(err)
}, 120*time.Second, 4*time.Second).Should(BeTrue())

By("creating a new single-replica kv CR")
if kv.Spec.Infra == nil {
kv.Spec.Infra = &v1.ComponentConfig{}
Expand Down Expand Up @@ -2680,20 +2695,16 @@ spec:
patchKvInfra(kvOrig.Spec.Infra, false, "")

By("waiting for virt-api and virt-controller replicas to respawn")
expectedReplicas := 2
if kvOrig.Spec.Infra != nil && kvOrig.Spec.Infra.Replicas != nil {
expectedReplicas = int(*kvOrig.Spec.Infra.Replicas)
}
Eventually(func() bool {
Eventually(func() error {
for _, name := range []string{"virt-api", "virt-controller"} {
pods, err := virtClient.CoreV1().Pods(flags.KubeVirtInstallNamespace).List(context.Background(), metav1.ListOptions{LabelSelector: fmt.Sprintf("%s=%s", v1.AppLabel, name)})
Expect(err).ToNot(HaveOccurred())
if len(pods.Items) != expectedReplicas {
return false
if len(pods.Items) != originalReplicaCounts[name] {
return fmt.Errorf("expected %d replicas for %s, got %d", originalReplicaCounts[name], name, len(pods.Items))
}
}
return true
}, 120*time.Second, 4*time.Second).Should(BeTrue())
return nil
}, 120*time.Second, 4*time.Second).ShouldNot(HaveOccurred())
})
})

Expand Down

0 comments on commit d86f5fb

Please sign in to comment.