Skip to content

Commit

Permalink
Queue a reconcile request after marking the resource as ready
Browse files Browse the repository at this point in the history
Signed-off-by: Alper Rifat Ulucinar <ulucinar@users.noreply.github.com>
  • Loading branch information
ulucinar committed Aug 23, 2023
1 parent ce56bba commit 2f18c26
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
11 changes: 11 additions & 0 deletions pkg/controller/external.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const (

const (
rateLimiterScheduler = "scheduler"
rateLimiterStatus = "status"
retryLimit = 20
)

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -313,6 +319,10 @@ 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.")
if e.eventHandler != nil {
e.eventHandler.Forget(rateLimiterStatus, mg.GetName())
}
return managed.ExternalObservation{
ResourceExists: true,
ResourceUpToDate: true,
Expand All @@ -327,6 +337,7 @@ func (e *external) Observe(ctx context.Context, mg xpresource.Managed) (managed.
}

resource.SetUpToDateCondition(mg, plan.UpToDate)
e.logger.Debug("Called plan on the resource.", "upToDate", plan.UpToDate)

return managed.ExternalObservation{
ResourceExists: true,
Expand Down
3 changes: 2 additions & 1 deletion pkg/controller/external_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 2f18c26

Please sign in to comment.