Skip to content

Commit 6fc9d1d

Browse files
Updates Machine Tests
- Fixes the test that transitions through Migrating to MachineAPI, checking Paused remains True is functional. - Use IsRetryableAPIError from testutils
1 parent eb19e21 commit 6fc9d1d

File tree

1 file changed

+8
-28
lines changed

1 file changed

+8
-28
lines changed

pkg/controller/machine/machine_controller_test.go

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ import (
3131
"github.com/openshift/cluster-control-plane-machine-set-operator/test/e2e/framework"
3232
testutils "github.com/openshift/machine-api-operator/pkg/util/testing"
3333

34-
apierrs "k8s.io/apimachinery/pkg/api/errors"
35-
utilnet "k8s.io/apimachinery/pkg/util/net"
3634
"sigs.k8s.io/controller-runtime/pkg/client"
3735
"sigs.k8s.io/controller-runtime/pkg/envtest/komega"
3836
"sigs.k8s.io/controller-runtime/pkg/manager"
@@ -144,11 +142,6 @@ var _ = Describe("Machine Reconciler", func() {
144142
HaveField("Status", Equal(corev1.ConditionTrue)),
145143
))))
146144

147-
By("Transitioning the AuthoritativeAPI though 'Migrating' to MachineAPI")
148-
Eventually(k.UpdateStatus(instance, func() {
149-
instance.Status.AuthoritativeAPI = machinev1.MachineAuthorityMigrating
150-
})).Should(Succeed())
151-
152145
// The condition should remain true whilst transitioning through 'Migrating'
153146
// Run this in a goroutine so we don't block
154147

@@ -164,7 +157,7 @@ var _ = Describe("Machine Reconciler", func() {
164157

165158
localInstance := instanceCopy.DeepCopy()
166159
if err := k8sClient.Get(ctx, client.ObjectKeyFromObject(localInstance), localInstance); err != nil {
167-
return g.Expect(err).Should(WithTransform(isRetryableAPIError, BeTrue()), "expected temporary error while getting machine: %v", err)
160+
return g.Expect(err).Should(WithTransform(testutils.IsRetryableAPIError, BeTrue()), "expected temporary error while getting machine: %v", err)
168161
}
169162

170163
return g.Expect(localInstance.Status.Conditions).Should(ContainElement(SatisfyAll(
@@ -179,13 +172,18 @@ var _ = Describe("Machine Reconciler", func() {
179172

180173
localInstance := instanceCopy.DeepCopy()
181174
if err := k8sClient.Get(ctx, client.ObjectKeyFromObject(localInstance), localInstance); err != nil {
182-
return g.Expect(err).Should(WithTransform(isRetryableAPIError, BeTrue()), "expected temporary error while getting machine: %v", err)
175+
return g.Expect(err).Should(WithTransform(testutils.IsRetryableAPIError, BeTrue()), "expected temporary error while getting machine: %v", err)
183176
}
184177

185-
return g.Expect(localInstance.Status.AuthoritativeAPI).ToNot(Equal(machinev1.MachineAuthorityMachineAPI))
178+
return g.Expect(localInstance.Status.AuthoritativeAPI).To(Equal(machinev1.MachineAuthorityMachineAPI))
186179
})
187180
}()
188181

182+
By("Transitioning the AuthoritativeAPI though 'Migrating' to MachineAPI")
183+
Eventually(k.UpdateStatus(instance, func() {
184+
instance.Status.AuthoritativeAPI = machinev1.MachineAuthorityMigrating
185+
})).Should(Succeed())
186+
189187
By("Updating the AuthoritativeAPI from Migrating to MachineAPI")
190188
Eventually(k.UpdateStatus(instance, func() {
191189
instance.Status.AuthoritativeAPI = machinev1.MachineAuthorityMachineAPI
@@ -220,21 +218,3 @@ func cleanResources(namespace string) error {
220218

221219
return nil
222220
}
223-
224-
// isRetryableAPIError returns whether an API error is retryable or not.
225-
// inspired by: k8s.io/kubernetes/test/utils.
226-
func isRetryableAPIError(err error) bool {
227-
// These errors may indicate a transient error that we can retry in tests.
228-
if apierrs.IsInternalError(err) || apierrs.IsTimeout(err) || apierrs.IsServerTimeout(err) ||
229-
apierrs.IsTooManyRequests(err) || utilnet.IsProbableEOF(err) || utilnet.IsConnectionReset(err) ||
230-
utilnet.IsHTTP2ConnectionLost(err) {
231-
return true
232-
}
233-
234-
// If the error sends the Retry-After header, we respect it as an explicit confirmation we should retry.
235-
if _, shouldRetry := apierrs.SuggestsClientDelay(err); shouldRetry {
236-
return true
237-
}
238-
239-
return false
240-
}

0 commit comments

Comments
 (0)