Skip to content

Commit

Permalink
fix(RHTAPREL-828): do not fail on missing Application
Browse files Browse the repository at this point in the history
Service logs were being cluttered whenever the ReleasePlan was created
before the Application. With this change, the error when trying to
find the Application is ignored and the ReleasePlan is set to be
reconciled after a minute.

Signed-off-by: David Moreno García <[email protected]>
  • Loading branch information
davidmogar authored and jinqi7 committed Mar 13, 2024
1 parent 17f7710 commit f869f17
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions controllers/releaseplan/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package releaseplan
import (
"context"
"reflect"
"time"

"github.com/go-logr/logr"
"github.com/redhat-appstudio/operator-toolkit/controller"
Expand Down Expand Up @@ -54,13 +55,18 @@ func newAdapter(ctx context.Context, client client.Client, releasePlan *v1alpha1
}

// EnsureOwnerReferenceIsSet is an operation that will ensure that the owner reference is set.
// If the Application who owns the ReleasePlan is not found, the error will be ignored and the
// ReleasePlan will be reconciled again after a minute.
func (a *adapter) EnsureOwnerReferenceIsSet() (controller.OperationResult, error) {
if len(a.releasePlan.OwnerReferences) > 0 {
return controller.ContinueProcessing()
}

application, err := a.loader.GetApplication(a.ctx, a.client, a.releasePlan)
if err != nil {
if errors.IsNotFound(err) {
return controller.RequeueAfter(time.Minute, nil)
}
return controller.RequeueWithError(err)
}

Expand Down
16 changes: 16 additions & 0 deletions controllers/releaseplan/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package releaseplan

import (
"reflect"
"time"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -70,6 +71,21 @@ var _ = Describe("ReleasePlan adapter", Ordered, func() {
adapter = createReleasePlanAndAdapter()
})

It("should not fail if the Application does not exist", func() {
adapter.ctx = toolkit.GetMockedContext(ctx, []toolkit.MockData{
{
ContextKey: loader.ApplicationContextKey,
Err: errors.NewNotFound(schema.GroupResource{}, ""),
},
})

result, err := adapter.EnsureOwnerReferenceIsSet()
Expect(result.RequeueRequest && !result.CancelRequest).To(BeTrue())
Expect(result.RequeueDelay).To(Equal(time.Minute))
Expect(err).NotTo(HaveOccurred())
Expect(adapter.releasePlan.OwnerReferences).To(HaveLen(0))
})

It("should set the owner reference", func() {
adapter.ctx = toolkit.GetMockedContext(ctx, []toolkit.MockData{
{
Expand Down

0 comments on commit f869f17

Please sign in to comment.