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

Make CreateOrUpdate controller async for link resources #5006

Merged
merged 16 commits into from
Jan 28, 2023

Conversation

vishwahiremat
Copy link
Contributor

Description

  • Refactor to have single DeploymentObject for linkrp and corerp
  • refactor the deployment.Delete signature to take only outputresources
  • add a new async controller for createorupdate for linkrp

Issue reference

Fixes: https://dev.azure.com/azure-octo/Incubations/_workitems/edit/5788

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Adds necessary unit tests for change
  • Adds necessary E2E tests for change
  • Unit tests passing
  • Extended the documentation / Created issue for it

@vishwahiremat vishwahiremat requested a review from a team as a code owner January 23, 2023 21:44
SecretValues map[string]rp.SecretValueReference
RecipeData datamodel.RecipeData
}
// type DeploymentOutput struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this supposed to be commented out?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


// AsyncOperationTimeout returns the timeput for the operation.
func (b *Operation[P, T]) AsyncOperationTimeout() time.Duration {
if b.resourceOptions.AsyncOperationTimeout == 0 {

Choose a reason for hiding this comment

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

Can you please add the simple unittest for this ?

Suggested change
if b.resourceOptions.AsyncOperationTimeout == 0 {
if b.resourceOptions.AsyncOperationTimeout == time.Time{} {

@@ -332,6 +333,7 @@ func AddRoutes(ctx context.Context, router *mux.Router, pathBase string, isARM b
rp_frontend.PrepareRadiusResource[*datamodel.VolumeResource],
vol_ctrl.ValidateRequest,
},
AsyncOperationTimeout: time.Duration(2) * time.Minute,

Choose a reason for hiding this comment

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

this is unnecessary.

@youngbupark
Copy link

I made huge change in the morning. Please rebase this branch with main.

@vishwahiremat
Copy link
Contributor Author

I made huge change in the morning. Please rebase this branch with main.

Rebased with main.

// AsyncOperationTimeout returns the timeput for the operation.
func (b *Operation[P, T]) AsyncOperationTimeout() time.Duration {
if b.resourceOptions.AsyncOperationTimeout == 0 {
return time.Duration(2) * time.Minute
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be a constant?

// AsyncOperationTimeout returns the timeput for the operation.
func (b *Operation[P, T]) AsyncOperationTimeout() time.Duration {
if b.resourceOptions.AsyncOperationTimeout == 0 {
return time.Duration(2) * time.Minute
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a reason for the 2 min AsyncOperationTimeout?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this is the default timeout for all the resources, and we can override it for each resource by sending a timeout for each operation.

@@ -362,6 +362,9 @@ func AddRoutes(ctx context.Context, router *mux.Router, pathBase string, isARM b
frontend_ctrl.ResourceOptions[datamodel.VolumeResource]{
RequestConverter: converter.VolumeResourceModelFromVersioned,
ResponseConverter: converter.VolumeResourceModelToVersioned,
UpdateFilters: []frontend_ctrl.UpdateFilter[datamodel.VolumeResource]{
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be a delete filter?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it should. Nice catch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

figuered delete/update filters are not required and removed it

@@ -2,8 +2,38 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// ------------------------------------------------------------

Copy link
Contributor

@mishrapratikshya mishrapratikshya Jan 27, 2023

Choose a reason for hiding this comment

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

The file mostly has recipe related data. shouldn't this be in a recipe file instead? we have a task for it. #5035

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think its better to move these to linkrp as these are used by differnet packages inside linkrp to avoid cyclic dependency

// Parameters are key/value parameters to pass into the recipe at deployment
Parameters map[string]any `json:"parameters,omitempty"`
}

const (
DaprInvokeHttpRoutesResourceType = "Applications.Link/daprInvokeHttpRoutes"
Copy link
Contributor

Choose a reason for hiding this comment

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

👌

Copy link
Contributor

@ytimocin ytimocin left a comment

Choose a reason for hiding this comment

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

Added a few comments and questions but looks good to me so far. Let me know when this PR takes its final shape and then I can review it again. Thanks for this change.

@@ -54,6 +55,9 @@ type ResourceOptions[T any] struct {

// UpdateFilters is a slice of filters that execute prior to updating a resource.
UpdateFilters []UpdateFilter[T]

// AsyncOperationTimeout is the default timeout duration of async put operation.
AsyncOperationTimeout time.Duration
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the best place to put this property?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think so, as this can accessed for all the operations for the resource.

// AsyncOperationTimeout returns the timeput for the operation.
func (b *Operation[P, T]) AsyncOperationTimeout() time.Duration {
if b.resourceOptions.AsyncOperationTimeout == 0 {
return time.Duration(2) * time.Minute
Copy link
Contributor

Choose a reason for hiding this comment

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

There should be a Default const for this somewhere in the code.

pkg/corerp/datamodel/application.go Show resolved Hide resolved
@@ -362,6 +362,9 @@ func AddRoutes(ctx context.Context, router *mux.Router, pathBase string, isARM b
frontend_ctrl.ResourceOptions[datamodel.VolumeResource]{
RequestConverter: converter.VolumeResourceModelFromVersioned,
ResponseConverter: converter.VolumeResourceModelToVersioned,
UpdateFilters: []frontend_ctrl.UpdateFilter[datamodel.VolumeResource]{
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it should. Nice catch.

@@ -6,6 +6,7 @@
package datamodel

import (
"github.com/project-radius/radius/pkg/linkrp"
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this create a cyclic dependency problem anytime soon?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

in that case we can move it all to linkrp instead. I create a types.go inside linkrp to remove the cyclic dependency

@@ -30,19 +30,3 @@ func getTestModels20220315privatepreview() (input *v20220315privatepreview.Redis

return input, dataModel, output
}

func getTestModelsForGetAndListApis20220315privatepreview() (input *v20220315privatepreview.RedisCacheResource, dataModel *datamodel.RedisCache, output *v20220315privatepreview.RedisCacheResource) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we deleting this data for Get and List? Was this a wrong naming? Because we are moving the Put and Delete.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We dont use this anymore as we moved list and get as part of the generic controller

UpdateFilters: []frontend_ctrl.UpdateFilter[datamodel.MongoDatabase]{
rp_frontend.PrepareRadiusResource[*datamodel.MongoDatabase],
},
AsyncOperationTimeout: time.Duration(10) * time.Minute,
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

Choose a reason for hiding this comment

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

This shouldn't affect the time of our functional tests, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes thats correct, as out functional tests run in parallel

UpdateFilters: []frontend_ctrl.UpdateFilter[datamodel.MongoDatabase]{
rp_frontend.PrepareRadiusResource[*datamodel.MongoDatabase],
},
AsyncOperationTimeout: time.Duration(15) * time.Minute,
Copy link
Contributor

Choose a reason for hiding this comment

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

🤣

frontend_ctrl.ResourceOptions[datamodel.MongoDatabase]{
RequestConverter: converter.MongoDatabaseDataModelFromVersioned,
ResponseConverter: converter.MongoDatabaseDataModelToVersioned,
UpdateFilters: []frontend_ctrl.UpdateFilter[datamodel.MongoDatabase]{
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if I remember the details of UpdateFilters and DeleteFilters but should this be DeleteFilters?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

figured we dont need delete/update filters and removed it

@vishwahiremat vishwahiremat force-pushed the vishwahiremat/asyscCreateOrDelete branch from 6dfac16 to 7ef7d11 Compare January 27, 2023 19:17
Copy link
Contributor

@ytimocin ytimocin left a comment

Choose a reason for hiding this comment

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

LGTM but left a few more comments and some may need addressing.
I would also get another thumbs up btw.

// AsyncOperationTimeout returns the timeput for the operation.
func (b *Operation[P, T]) AsyncOperationTimeout() time.Duration {
if b.resourceOptions.AsyncOperationTimeout == 0 {
return defaultAsyncPutTimeout
Copy link
Contributor

Choose a reason for hiding this comment

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

but this function is not only used for put calls, right? delete timeout should be different?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

currently we use the same default timeout duration for put and delete, i.e 2 mins and we can override it by providing timeout in routes

nil,
nil,
errors.New("error getting object"),
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you also want to test PATCH calls?


deploymentDataModel, ok := dataModel.(rpv1.DeploymentDataModel)
if !ok {
return ctrl.NewFailedResult(v1.ErrorDetails{Message: "deployment data model conversion error"}), nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we give more details? Like which data model and something like that?

Comment on lines +53 to +68
// ResourceInfo name and id of the resource
type ResourceInfo struct {
Name string `json:"name"`
ID string `json:"id"`
}

type Runtime struct {
Kubernetes Kubernetes `json:"kubernetes,omitempty"`
}

type Kubernetes struct {
// Namespace is set to the applicationNamespace when the Link is application-scoped, and set to the environmentNamespace when the Link is environment scoped
Namespace string `json:"namespace"`
// EnvironmentNamespace is set to environment namespace.
EnvironmentNamespace string `json:"environmentNamespace"`
}
Copy link
Contributor

Choose a reason for hiding this comment

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

If these are also being used by corerp, we should move them to the rp package.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

these are currently used only in linkrp

Comment on lines +73 to +76
deploymentDataModel, ok := dataModel.(rpv1.DeploymentDataModel)
if !ok {
return ctrl.NewFailedResult(v1.ErrorDetails{Message: "deployment data model conversion error"}), err
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We can move this check after L61 before rendering and deploying.

@rynowak rynowak merged commit 430a961 into main Jan 28, 2023
@rynowak rynowak deleted the vishwahiremat/asyscCreateOrDelete branch January 28, 2023 00:31
@rynowak
Copy link
Contributor

rynowak commented Jan 28, 2023

Merging to unblock next round of work. The failures are flakiness on the delete path of an Azure resource.

vishwahiremat added a commit that referenced this pull request Jan 30, 2023
# Description

Addressing few pr comments from
#5006

## Issue reference

<!--
We strive to have all PR being opened based on an issue, where the
problem or feature have been discussed prior to implementation.
-->

Fixes: #issue_number

## Checklist

Please make sure you've completed the relevant tasks for this PR, out of
the following list:

* [x] Code compiles correctly
* [ ] Adds necessary unit tests for change
* [ ] Adds necessary E2E tests for change
* [x] Unit tests passing
* [ ] Extended the documentation / Created issue for it
mishrapratikshya pushed a commit that referenced this pull request Feb 2, 2023
# Description

- Refactor to have single DeploymentObject for linkrp and corerp
- refactor the deployment.Delete signature to take only outputresources
- add a new async controller for createorupdate for linkrp

## Issue reference

<!--
We strive to have all PR being opened based on an issue, where the
problem or feature have been discussed prior to implementation.
-->

Fixes: https://dev.azure.com/azure-octo/Incubations/_workitems/edit/5788

## Checklist

Please make sure you've completed the relevant tasks for this PR, out of
the following list:

* [x] Code compiles correctly
* [ ] Adds necessary unit tests for change
* [ ] Adds necessary E2E tests for change
* [x] Unit tests passing
* [ ] Extended the documentation / Created issue for it
mishrapratikshya pushed a commit that referenced this pull request Feb 2, 2023
# Description

Addressing few pr comments from
#5006

## Issue reference

<!--
We strive to have all PR being opened based on an issue, where the
problem or feature have been discussed prior to implementation.
-->

Fixes: #issue_number

## Checklist

Please make sure you've completed the relevant tasks for this PR, out of
the following list:

* [x] Code compiles correctly
* [ ] Adds necessary unit tests for change
* [ ] Adds necessary E2E tests for change
* [x] Unit tests passing
* [ ] Extended the documentation / Created issue for it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants