Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Queue a reconcile request after marking the resource as ready #262

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading