From 8e859d61278beadb06758c31bd56a832e33e014e Mon Sep 17 00:00:00 2001 From: Alper Rifat Ulucinar Date: Tue, 22 Aug 2023 19:57:20 +0300 Subject: [PATCH] Queue a reconcile request after marking the resource as ready Signed-off-by: Alper Rifat Ulucinar --- pkg/controller/external.go | 11 +++++++++++ pkg/controller/external_test.go | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pkg/controller/external.go b/pkg/controller/external.go index bd317340..f8b6ce60 100644 --- a/pkg/controller/external.go +++ b/pkg/controller/external.go @@ -43,6 +43,7 @@ const ( const ( rateLimiterScheduler = "scheduler" + rateLimiterStatus = "status" retryLimit = 20 ) @@ -295,6 +296,7 @@ func (e *external) Observe(ctx context.Context, mg xpresource.Managed) (managed. switch { // we prioritize critical annotation updates over status updates case annotationsUpdated: + e.logger.Debug("Critical annotations have been updated.") return managed.ExternalObservation{ ResourceExists: true, ResourceUpToDate: true, @@ -305,6 +307,10 @@ func (e *external) Observe(ctx context.Context, mg xpresource.Managed) (managed. case !markedAvailable: addTTR(tr) tr.SetConditions(xpv1.Available()) + e.logger.Debug("Resource is marked as available.") + if e.eventHandler != nil { + e.eventHandler.RequestReconcile(rateLimiterStatus, mg.GetName(), nil) + } return managed.ExternalObservation{ ResourceExists: true, ResourceUpToDate: true, @@ -313,6 +319,7 @@ func (e *external) Observe(ctx context.Context, mg xpresource.Managed) (managed. // with the least priority wrt critical annotation updates and status updates // we allow a late-initialization before the Workspace.Plan call case lateInitedParams: + e.logger.Debug("Resource is late-initialized.") return managed.ExternalObservation{ ResourceExists: true, ResourceUpToDate: true, @@ -321,12 +328,16 @@ func (e *external) Observe(ctx context.Context, mg xpresource.Managed) (managed. }, nil // now we do a Workspace.Refresh default: + if e.eventHandler != nil { + e.eventHandler.Forget(rateLimiterStatus, mg.GetName()) + } plan, err := e.workspace.Plan(ctx) if err != nil { return managed.ExternalObservation{}, errors.Wrap(err, errPlan) } resource.SetUpToDateCondition(mg, plan.UpToDate) + e.logger.Debug("Called plan on the resource.", "upToDate", plan.UpToDate) return managed.ExternalObservation{ ResourceExists: true, diff --git a/pkg/controller/external_test.go b/pkg/controller/external_test.go index 9ca9bb38..cb76b511 100644 --- a/pkg/controller/external_test.go +++ b/pkg/controller/external_test.go @@ -19,6 +19,7 @@ import ( "testing" xpv1 "github.com/crossplane/crossplane-runtime/apis/common/v1" + "github.com/crossplane/crossplane-runtime/pkg/logging" xpmeta "github.com/crossplane/crossplane-runtime/pkg/meta" "github.com/crossplane/crossplane-runtime/pkg/reconciler/managed" xpresource "github.com/crossplane/crossplane-runtime/pkg/resource" @@ -601,7 +602,7 @@ func TestObserve(t *testing.T) { } for name, tc := range cases { t.Run(name, func(t *testing.T) { - e := &external{workspace: tc.w, config: config.DefaultResource("upjet_resource", nil, nil), kube: tc.args.client} + e := &external{workspace: tc.w, config: config.DefaultResource("upjet_resource", nil, nil), kube: tc.args.client, logger: logging.NewNopLogger()} observation, err := e.Observe(context.TODO(), tc.args.obj) if diff := cmp.Diff(tc.want.obs, observation); diff != "" { t.Errorf("\n%s\nObserve(...): -want observation, +got observation:\n%s", tc.reason, diff)