Skip to content

Commit

Permalink
Try to address volumepopulator test flake
Browse files Browse the repository at this point in the history
- updates to error out in Eventually() if we do get a flake
  to help debug if the issue still happens intermittently.

Signed-off-by: Tesshu Flower <tflower@redhat.com>
  • Loading branch information
tesshuflower committed Jun 23, 2023
1 parent ec4bcc2 commit 994ef33
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions controllers/volumepopulator_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
kerrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
utilrand "k8s.io/apimachinery/pkg/util/rand"
"k8s.io/apimachinery/pkg/util/yaml"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -564,9 +565,10 @@ var _ = Describe("VolumePopulator", func() {
})

Context("When a storageclassname is specified in the pvc spec", func() {
storageClassName := "vp-test-storageclass1"
var storageClassName string

BeforeEach(func() {
storageClassName = "vp-test-storageclass-" + utilrand.String(5)
pvc.Spec.StorageClassName = &storageClassName
})

Expand Down Expand Up @@ -661,31 +663,36 @@ var _ = Describe("VolumePopulator", func() {
Expect(pvcPrime.Spec.DataSourceRef.Kind).To(Equal("VolumeSnapshot"))
Expect(pvcPrime.Spec.DataSourceRef.Name).To(Equal(snap.GetName()))

Eventually(func() bool {
Eventually(func() error {
// re-load the snapshot to prevent timing issues, as the controller will need to create
// pvcPrime before adding it as an ownerRef on the snapshot
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(snap), snap)).To(Succeed())
err := (k8sClient.Get(ctx, client.ObjectKeyFromObject(snap), snap))
if err != nil {
return err
}

// Snapshot should have a label indicating it's in-use by volume populator
v, ok := snap.GetLabels()[getSnapshotInUseLabelKey(pvc)]
if !ok {
return false
return fmt.Errorf("Snapshot missing volumepopulator in-use label")
}
if v != pvc.GetName() {
return false
return fmt.Errorf("Snapshot volume populator in-use label does not match the pvc."+
" pvc label value is: %s", v)
}

// Snapshot should get ownerRef pointing to pvcPrime
ownerRefs := snap.GetOwnerReferences()
if len(ownerRefs) != 1 {
return false
return fmt.Errorf("Snapshot owner references incorrect - len(ownerRefs): %d", len(ownerRefs))
}
if ownerRefs[0].UID != pvcPrime.UID {
return false
return fmt.Errorf("Snapshot ownerRef UID: %s does not match pvcPrime.UID: %s",
ownerRefs[0].UID, pvcPrime.UID)
}

return true
}, maxWait, interval).Should(BeTrue())
return nil
}, maxWait, interval).Should(Succeed())
})

It("pvcPrime should be created", func() {
Expand Down

0 comments on commit 994ef33

Please sign in to comment.