Skip to content

Conversation

kumargauravsharma
Copy link
Contributor

Issue #, if available:

aws-controllers-k8s/community#836

Description of changes:

This PR is to related to aws-controllers-k8s/runtime#21
It makes the code-generator changes for delete api as discussed under: aws-controllers-k8s/runtime#21 (comment)

Testing:

  • make test passed.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link
Collaborator

@jaypipes jaypipes left a comment

Choose a reason for hiding this comment

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

See inline... we will need a change to ACK runtime first (the interface for AWSResourceManager needs to be updated before the templates here).

Also, please change the PR summary to reflect what this is doing (returning the latest resource from the Delete() call, not "Provide custom resource delete progress for long-running delete")

Thanks!
-jay

Comment on lines +132 to +137
// service API, returning an AWSResource representing the
// resource being deleted (if delete is asynchronous and takes time)
func (rm *resourceManager) Delete(
ctx context.Context,
res acktypes.AWSResource,
) error {
) (acktypes.AWSResource, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

you cannot change this method signature before changing the interface in ACK runtime:

https://github.com/aws-controllers-k8s/runtime/blob/main/pkg/types/aws_resource_manager.go#L61-L63

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PR: aws-controllers-k8s/runtime#21 contained changes in runtime.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated the PR summary as: "Returning the latest resource from the Delete() call"

@jaypipes jaypipes added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 9, 2021
@kumargauravsharma kumargauravsharma changed the title Provide custom resource delete progress for long running delete Returning the latest resource from the Delete() call Jul 12, 2021
ack-bot pushed a commit to aws-controllers-k8s/runtime that referenced this pull request Jul 12, 2021
Related issue: aws-controllers-k8s/community#836

This PR contains code changes to patch custom resource with latest details during long running delete.
It does so if resource manager's Delete function return requeue related errors. 
The expectation is that resource manager's ReadOne method would set appropriate conditions (example: `ACK.ResourceSynced` to false with message) and provide latest details about the resource which is being deleted.
Conditions can also be set at some common place where common conditions logic should reside.

Testing:
`make test` passed for runtime.

**Alternate approach** that was considered, but was not taken up as it involved non-intrusive changes to resource manager's APIs. Following are the details:
Currently, [resource manager's `Delete` API](https://github.com/aws-controllers-k8s/code-generator/blob/main/templates/pkg/resource/manager.go.tpl#L136) returns only one data field of type `error`, it does not return `resource`.
Also, the [`sdk.go::sdkDelete()` logic](https://github.com/aws-controllers-k8s/code-generator/blob/main/templates/pkg/resource/sdk.go.tpl#L141) does not parse the return result output of service delete API.

It can be updated such that `sdk.go::sdkDelete()` logic parses the output response, and allows a `sdk_delete_post_set_output` hook for service controllers to have custom logic (as needed). The resultant resource reference would then be returned from this method.
In case, requeue is required then the return values from this method will have both resource, error (requeue type) as not nil.
And the [reconciler:cleanup() logic here](https://github.com/aws-controllers-k8s/runtime/blob/main/pkg/runtime/reconciler.go#L327), would patch the current resource with the returned resource from `rm.Delete()` call and return the error (if any).

Though this change is similar to the approach taken for [resource manager ReadOne here](https://github.com/aws-controllers-k8s/code-generator/blob/main/templates/pkg/resource/manager.go.tpl#L76-L78), this is more intrusive as it changes the Delete API's return type.
However, it does have advantage that there is no need for another ReadOne call from reconciler, and also provides flexibility to service controller's to implement custom hook specific to delete scenario.

[EDIT]: the alternate approach that is mentioned above, is the final approach taken per the discussion/comments in this PR.
Related PR in code-generator: aws-controllers-k8s/code-generator#114
Copy link
Collaborator

@jaypipes jaypipes left a comment

Choose a reason for hiding this comment

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

OK, I cut https://github.com/aws-controllers-k8s/runtime/releases/tag/v0.5.0 with the changes to the AWSResourceManager.Delete interface method. Please update code-gen's go.mod file accordingly in this PR.

@kumargauravsharma
Copy link
Contributor Author

Updated code-gen go.mod file to refer runtime 0.5.0

Copy link
Collaborator

@jaypipes jaypipes left a comment

Choose a reason for hiding this comment

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

👍

@jaypipes
Copy link
Collaborator

/lgtm

@ack-bot ack-bot added the lgtm Indicates that a PR is ready to be merged. label Jul 12, 2021
@a-hilaly
Copy link
Member

@ack-bot ack-bot removed the lgtm Indicates that a PR is ready to be merged. label Jul 12, 2021
@kumargauravsharma
Copy link
Contributor Author

@a-hilaly thanks. I have updated the Makefile.

@a-hilaly
Copy link
Member

/lgtm

@ack-bot ack-bot added the lgtm Indicates that a PR is ready to be merged. label Jul 12, 2021
@ack-bot
Copy link
Collaborator

ack-bot commented Jul 12, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: A-Hilaly, jaypipes, kumargauravsharma, surajkota

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@jaypipes jaypipes removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 12, 2021
@jaypipes jaypipes merged commit 1423dc8 into aws-controllers-k8s:main Jul 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants