Skip to content

Commit

Permalink
Merge pull request #262 from ulucinar/queue-after-ready
Browse files Browse the repository at this point in the history
Queue a reconcile request after marking the resource as ready
  • Loading branch information
ulucinar authored Aug 23, 2023
2 parents ce56bba + 8e859d6 commit a5cc50f
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,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,
Expand All @@ -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,
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 a5cc50f

Please sign in to comment.