Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Callback for updating status with last operation error #103

Merged
merged 4 commits into from
Oct 27, 2021

Conversation

muvaf
Copy link
Member

@muvaf muvaf commented Oct 11, 2021

Description of your changes

Currently, when an error occurs in async calls, we'd reconcile after a whole minute to see the error, just like native async controllers like AWS RDS Instance. However, we can use the existing callback mechanism to set the error condition and that'd get us a re-queue if there is a change, which will then allow us process the resulting state.

I have:

  • Read and followed Crossplane's contribution process.
  • Run make reviewable to ensure this PR is ready for review.
  • Added backport release-x.y labels to auto-backport this PR if necessary.

How has this code been tested

Manually with RDS cluster resource and EC2 Instance.


// NewAPICallbacks returns a new APICallbacks.
func NewAPICallbacks(m ctrl.Manager, of xpresource.ManagedKind) *APICallbacks {
nt := func() resource.Terraformed {
Copy link
Member Author

@muvaf muvaf Oct 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opted for this pattern so that we need to keep only the metadata.name of the resource rather than the whole object accounting for @ulucinar 's concerns about memory consumption.

…rce is updated with the results of the async operation, which allows us to remove last operation error utilities from terraform.Operation

Signed-off-by: Muvaffak Onus <me@muvaf.com>
…cret utils now

Signed-off-by: Muvaffak Onus <me@muvaf.com>
Signed-off-by: Muvaffak Onus <me@muvaf.com>
return errors.Wrap(kErr, "cannot get Terraformed resource")
}
tr.SetConditions(resource.AsyncOperationCondition(err))
return errors.Wrap(ac.kube.Status().Update(ctx, tr), errStatusUpdate)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apply and Destroy function bodies are same, could we refactor not to duplicate?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that and it didn't really look better since the logic is so small anyway. Do you think I should still de-duplicate here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. If you've tried it but didn't like it, let's keep it as it is.

@@ -29,7 +29,7 @@ func Setup(mgr ctrl.Manager, l logging.Logger, rl workqueue.RateLimiter, s terra
xpresource.ManagedKind({{ .TypePackageAlias }}{{ .CRD.Kind }}GroupVersionKind),
managed.WithExternalConnecter(tjcontroller.NewConnector(mgr.GetClient(), ws, s, config.Store.GetForResource("{{ .ResourceType }}"),
{{- if .UseAsync }}
tjcontroller.UseAsync(),
tjcontroller.WithCallbackProvider(tjcontroller.NewAPICallbacks(mgr, xpresource.ManagedKind({{ .TypePackageAlias }}{{ .CRD.Kind }}GroupVersionKind))),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't we initialize this provider in NewConnector function, do we really need to pass this as an option?
I mean, we are already passing resource config which has UseAsync property and we can just use it to set a callback provider.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need the GVK of the resource and the mgr so that when we call newTerraformed(), the main schema can find the strong-typed Go object from its map of resources and these are not available in NewConnector. I thought of having scheme or manager and GVK as argument but didn't really want to make its argument list longer and also wanted to keep it similar to other providers where we don't need anything other than kube client in the ExternalClient implementation.

Copy link
Member

@turkenh turkenh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

Signed-off-by: Muvaffak Onus <me@muvaf.com>
@muvaf muvaf merged commit a9595d6 into crossplane:main Oct 27, 2021
@muvaf muvaf deleted the will-call-you-back branch October 27, 2021 15:13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants