tofu-controller icon indicating copy to clipboard operation
tofu-controller copied to clipboard

Remove/replace uses of `Eventually` which just do `k8sClient.Get`

Open squaremo opened this issue 2 years ago • 0 comments

There are a number of places in the tests where Eventually is used like this:

var tf infrav1.Terraform
g.Eventually(func() error {
    return k8sClient.Get(ctx, key, &tf)
}).Should(Succeed())

Some of these are immediately after creating the object identified by key (here's an example) -- those can just be removed. If k8sClient.Create succeeded, you can assume the object exists.

In some places, it's used as a wrapper around just k8sClient.Get because in the past, the test in question has flaked with a spurious error. For these cases I suggest writing a helper that uses https://pkg.go.dev/k8s.io/client-go/util/retry#OnError.

Occasionally, the k8sClient.Get is used in a "legit" Eventually block, e.g., to check that an object's status eventually gains a particular condition. These usually account for API flakes anyway, since it'll fail the check and retry if there's an error.

squaremo avatar Nov 16 '23 16:11 squaremo