From 2ba36fdc23cab0fe4b2424cb3f130b3642a6dc8c Mon Sep 17 00:00:00 2001 From: Tal Shor Date: Sun, 20 Aug 2023 13:56:56 +0300 Subject: [PATCH] add create test --- controllers/serviceinstance_controller.go | 5 ++++ .../serviceinstance_controller_test.go | 24 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/controllers/serviceinstance_controller.go b/controllers/serviceinstance_controller.go index 8be5e02c..1bba4804 100644 --- a/controllers/serviceinstance_controller.go +++ b/controllers/serviceinstance_controller.go @@ -274,6 +274,11 @@ func (r *ServiceInstanceReconciler) createInstance(ctx context.Context, smClient if provisionErr != nil { log.Error(provisionErr, "failed to create service instance", "serviceOfferingName", serviceInstance.Spec.ServiceOfferingName, "servicePlanName", serviceInstance.Spec.ServicePlanName) + if isOrphanMitigationError(provisionErr) { + log.Info(OrphanMitigationLog) + r.updateInstanceAsInOrphanMitigation(ctx, serviceInstance) + return ctrl.Result{}, r.updateStatus(ctx, serviceInstance) + } return r.handleError(ctx, smClientTypes.CREATE, provisionErr, serviceInstance) } diff --git a/controllers/serviceinstance_controller_test.go b/controllers/serviceinstance_controller_test.go index af474f4b..169a79aa 100644 --- a/controllers/serviceinstance_controller_test.go +++ b/controllers/serviceinstance_controller_test.go @@ -923,6 +923,30 @@ var _ = Describe("ServiceInstance controller", func() { }} }) + Context("create failed", func() { + It("polls until sm returns not found", func() { + fakeClient.ProvisionReturns(nil, orphanMitigationErr) + fakeClient.DeprovisionReturns("", orphanMitigationErr) + smInstance := smclientTypes.ServiceInstance{ID: fakeInstanceID, LastOperation: &smClientTypes.Operation{State: smClientTypes.FAILED, Type: smClientTypes.DELETE, DeletionScheduled: time.Now()}} + fakeClient.GetInstanceByIDReturns(&smInstance, nil) + fakeClient.ListInstancesReturns(&smclientTypes.ServiceInstances{ + ServiceInstances: []smclientTypes.ServiceInstance{smInstance}}, nil) + serviceInstance = createInstance(ctx, instanceSpec, false) + verifyOrphanMitigationStatus(true, defaultLookupKey, ctx) + + /* only after sm returns not found the instance should be deleted */ + fakeClient.GetInstanceByIDReturns(nil, &sm.ServiceManagerError{ + StatusCode: http.StatusNotFound, + Description: "deleted successfully", + }) + + Eventually(func() bool { + err := k8sClient.Get(ctx, defaultLookupKey, serviceInstance) + return apierrors.IsNotFound(err) + }, timeout, interval).Should(BeTrue()) + }) + }) + Context("delete failed", func() { It("polls until sm returns not found", func() { serviceInstance = createInstance(ctx, instanceSpec, true)