Skip to content

Commit

Permalink
fix(STONEINTG-737): stop reconciliation if ITS is not find for SEB
Browse files Browse the repository at this point in the history
* It's not possible to reconcile a SnapshotEnvironmentBinding if
  the associated IntegrationTestScenario is missing (was deleted)

Signed-off-by: dirgim <kpavic@redhat.com>
  • Loading branch information
dirgim committed Jan 5, 2024
1 parent 3b2fc4d commit c199d26
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
3 changes: 3 additions & 0 deletions controllers/binding/snapshotenvironmentbinding_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
integrationTestScenario, err := r.getIntegrationTestScenarioFromSnapshotEnvironmentBinding(ctx, snapshotEnvironmentBinding)
if err != nil {
logger.Error(err, "Failed to get IntegrationTestScenario from the SnapshotEnvironmentBinding")
if errors.IsNotFound(err) {
return ctrl.Result{}, nil
}
return ctrl.Result{}, err
}

Expand Down
24 changes: 20 additions & 4 deletions controllers/binding/snapshotenvironmentbinding_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ var _ = Describe("BindingController", func() {
err := k8sClient.Delete(ctx, hasApp)
Eventually(func() bool {
err := k8sClient.Get(ctx, types.NamespacedName{
Namespace: hasComp.ObjectMeta.Namespace,
Name: hasComp.ObjectMeta.Name,
Namespace: hasApp.ObjectMeta.Namespace,
Name: hasApp.ObjectMeta.Name,
}, hasApp)
return err != nil && errors.IsNotFound(err)
}).Should(BeTrue())
Expand All @@ -335,8 +335,8 @@ var _ = Describe("BindingController", func() {
err := k8sClient.Delete(ctx, hasSnapshot)
Eventually(func() bool {
err := k8sClient.Get(ctx, types.NamespacedName{
Namespace: hasComp.ObjectMeta.Namespace,
Name: hasComp.ObjectMeta.Name,
Namespace: hasSnapshot.ObjectMeta.Namespace,
Name: hasSnapshot.ObjectMeta.Name,
}, hasSnapshot)
return err != nil && errors.IsNotFound(err)
}).Should(BeTrue())
Expand All @@ -355,6 +355,22 @@ var _ = Describe("BindingController", func() {
}).ShouldNot(BeNil())
})

It("can fail when Reconcile fails to prepare the adapter when IntegrationTestScenario is not found", func() {
err := k8sClient.Delete(ctx, integrationTestScenario)
Expect(err).ToNot(HaveOccurred())
Eventually(func() bool {
err := k8sClient.Get(ctx, types.NamespacedName{
Namespace: integrationTestScenario.ObjectMeta.Namespace,
Name: integrationTestScenario.ObjectMeta.Name,
}, integrationTestScenario)
return err != nil && errors.IsNotFound(err)
}).Should(BeTrue())

result, err := bindingReconciler.Reconcile(ctx, req)
Expect(result).To(Equal(ctrl.Result{}))
Expect(err).ToNot(HaveOccurred())
})

It("can Reconcile function prepare the adapter and return the result of the reconcile handling operation", func() {
result, err := bindingReconciler.Reconcile(ctx, req)
Expect(reflect.TypeOf(result)).To(Equal(reflect.TypeOf(reconcile.Result{})))
Expand Down

0 comments on commit c199d26

Please sign in to comment.