forked from crossplane/crossplane-runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add machinery for tracking external resource create time
Per crossplane-contrib/provider-aws#802 some external APIs (including some AWS APIs) appear to experience some delay between the time a new resource is successfully created and the time at which that resource appears in queries. This commit adds a new 'crossplane.io/external-create-time' annotation and a new 'ResourcePending' field in the Observation struct. Together these can be used by an Observe method to allow for a small grace period before it determines that a resource does not exist. For example: ```go func Observe(ctx context.Context, mg resource.Managed) (managed.ExternalObservation, error) { err := api.Get(AsInput(mg)) if IsNotFound(err) { if t := meta.GetExternalCreateTime(); t != nil && time.Since(t.Time) < 1 * time.Minute { // We're in the grace period - wait a bit longer for the resource to appear. return managed.ExternalObservation{ResourcePending: true}, nil } // The resource does not exist. return managed.ExternalObservation{ResourceExists: false}, nil } if err != nil { return managed.ExternalObservation{}, nil } return managed.ExternalObervation{ResourceExists: true} } func Create(ctx context.Context, mg resource.Managed) (managed.ExternalCreation, error) { _ := api.Create(AsInput(mg)) meta.SetExternalCreateTime() return managed.ExternalCreation{ExternalCreateTimeSet: true}, nil } ``` Signed-off-by: Nic Cope <negz@rk0n.org>
- Loading branch information
Showing
4 changed files
with
151 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters