operators: fix flaky env test

This commit is contained in:
Markus Rudy 2023-12-19 12:06:33 +01:00 committed by Markus Rudy
parent 3c05150721
commit 7f8cfb8f03

View File

@ -43,6 +43,22 @@ var _ = Describe("PendingNode controller", func() {
interval = time.Millisecond * 250 interval = time.Millisecond * 250
) )
beGone := func() OmegaMatcher {
return MatchError(&errors.StatusError{
ErrStatus: metav1.Status{
Status: "Failure",
Message: `pendingnodes.update.edgeless.systems "pending-node" not found`,
Reason: "NotFound",
Details: &metav1.StatusDetails{
Name: pendingNodeName,
Group: "update.edgeless.systems",
Kind: "pendingnodes",
},
Code: http.StatusNotFound,
},
})
}
pendingNodeLookupKey := types.NamespacedName{Name: pendingNodeName} pendingNodeLookupKey := types.NamespacedName{Name: pendingNodeName}
Context("When creating pending node with goal join", func() { Context("When creating pending node with goal join", func() {
@ -107,27 +123,17 @@ var _ = Describe("PendingNode controller", func() {
fakes.nodeStateGetter.setNodeState(updatev1alpha1.NodeStateTerminated) fakes.nodeStateGetter.setNodeState(updatev1alpha1.NodeStateTerminated)
// trigger reconciliation before regular check interval to speed up test by changing the spec // trigger reconciliation before regular check interval to speed up test by changing the spec
Eventually(func() error { Eventually(func() error {
Expect(k8sClient.Get(ctx, pendingNodeLookupKey, pendingNode)).Should(Succeed()) if err := k8sClient.Get(ctx, pendingNodeLookupKey, pendingNode); err != nil {
return err
}
pendingNode.Spec.Deadline = &metav1.Time{Time: fakes.clock.Now().Add(time.Second)} pendingNode.Spec.Deadline = &metav1.Time{Time: fakes.clock.Now().Add(time.Second)}
return k8sClient.Update(ctx, pendingNode) return k8sClient.Update(ctx, pendingNode)
}, timeout, interval).Should(Succeed()) }, timeout, interval).Should(Or(Succeed(), beGone()))
By("checking if the pending node resource is deleted") By("checking if the pending node resource is deleted")
Eventually(func() error { Eventually(func() error {
return k8sClient.Get(ctx, pendingNodeLookupKey, createdPendingNode) return k8sClient.Get(ctx, pendingNodeLookupKey, createdPendingNode)
}, timeout, interval).Should(MatchError(&errors.StatusError{ }, timeout, interval).Should(beGone())
ErrStatus: metav1.Status{
Status: "Failure",
Message: `pendingnodes.update.edgeless.systems "pending-node" not found`,
Reason: "NotFound",
Details: &metav1.StatusDetails{
Name: pendingNodeName,
Group: "update.edgeless.systems",
Kind: "pendingnodes",
},
Code: http.StatusNotFound,
},
}))
}) })
It("Should should detect successful node join", func() { It("Should should detect successful node join", func() {