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

remove validation of resource types against the static list in recipes codebase #8391

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

nithyatsu
Copy link
Contributor

@nithyatsu nithyatsu commented Jan 31, 2025

Description

Since we now have APIs that lets us query the valid resourcetypes and the resource types can include UDTs, we refactored the code to remove the validation of resource types against the static list of redaius resource types.

Type of change

  • This pull request fixes a bug in Radius and has an approved issue (issue link required).

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

Contributor checklist

Please verify that the PR meets the following requirements, where applicable:

  • An overview of proposed schema changes is included in a linked GitHub issue.
    • Yes
    • Not applicable
  • A design document PR is created in the design-notes repository, if new APIs are being introduced.
    • Yes
    • Not applicable
  • The design document has been reviewed and approved by Radius maintainers/approvers.
    • Yes
    • Not applicable
  • A PR for the samples repository is created, if existing samples are affected by the changes in this PR.
    • Yes
    • Not applicable
  • A PR for the documentation repository is created, if the changes in this PR affect the documentation or any user facing updates are made.
    • Yes
    • Not applicable
  • A PR for the recipes repository is created, if existing recipes are affected by the changes in this PR.
    • Yes
    • Not applicable

@nithyatsu nithyatsu changed the title remove validation of resource types against the static list remove validation of resource types against the static list in recipes codebase Feb 10, 2025
@nithyatsu nithyatsu marked this pull request as ready for review February 10, 2025 23:55
@nithyatsu nithyatsu requested review from a team as code owners February 10, 2025 23:55
Copy link

codecov bot commented Feb 11, 2025

Codecov Report

Attention: Patch coverage is 61.11111% with 28 lines in your changes missing coverage. Please review.

Project coverage is 59.94%. Comparing base (ea992df) to head (43e33cc).

Files with missing lines Patch % Lines
...orerp/backend/controller/createorupdateresource.go 59.52% 12 Missing and 5 partials ⚠️
...g/corerp/backend/deployment/deploymentprocessor.go 57.69% 11 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8391      +/-   ##
==========================================
- Coverage   59.94%   59.94%   -0.01%     
==========================================
  Files         596      595       -1     
  Lines       40432    40435       +3     
==========================================
+ Hits        24238    24239       +1     
+ Misses      14367    14364       -3     
- Partials     1827     1832       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -60,16 +65,66 @@ func getDataModel(id resources.ID) (v1.DataModelInterface, error) {
}
}

func isPortableResource(resourceTypeResourceObj *database.Object) (bool, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Couple of callouts/questions about this approach -

  1. Will this work for built in portable types in their current state before they are migrated to the UDT schema (with capabilites/supportsRecipe property)?
  2. Is the output of this function only used for currently implemented built in portable resources or for UDT resources as well?
  3. If this is expected to work for UDTs as well, then checking if recipes are supported isn't reliable since user can opt out of recipes.

Copy link
Contributor

@lakshmimsft lakshmimsft Feb 19, 2025

Choose a reason for hiding this comment

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

Note: portable types are currently registered with the UDT schema along with all built-in types and includes supportsRecipies capability.

Copy link
Contributor

Choose a reason for hiding this comment

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

@lakshmimsft aren't we still relying on typespec to generate schema for portable resources: https://github.com/radius-project/radius/blob/main/typespec/Applications.Datastores/mongoDatabases.tsp? UDT based spec for portable resources is minimal, which I'm assuming was done purely for routing?

// Run checks if the resource exists, renders the resource, deploys the resource, applies the
// deployment output to the resource, deletes any resources that are no longer needed, and saves the resource.
func (c *CreateOrUpdateResource) Run(ctx context.Context, request *ctrl.Request) (ctrl.Result, error) {
// This code is general and we might be processing an async job for a resource or a scope, so using the general Parse function.
Copy link
Contributor

@kachawla kachawla Feb 19, 2025

Choose a reason for hiding this comment

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

I think there is room for abstraction/refactoring both in this controller and deploymentprocessor. This will help improve readability of the code and also deploymentprocessor is using isPortableResource in a weird way where it already has a hardcoded list of portable resource types in the switch case block https://github.com/radius-project/radius/blob/main/pkg/corerp/backend/deployment/deploymentprocessor.go#L517-L565

Copy link
Contributor

@kachawla kachawla left a comment

Choose a reason for hiding this comment

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

Could you please update the PR description to include manual testing that's mentioned in the link issue to validate this change?

- Manually test registration of Recipe for a nonexistent resource type
- Manually test Recipe webhook for a nonexistent resource type. Operation/processing might fail but creation should happen

@@ -60,16 +65,66 @@ func getDataModel(id resources.ID) (v1.DataModelInterface, error) {
}
}

func isPortableResource(resourceTypeResourceObj *database.Object) (bool, error) {
Copy link
Contributor

@lakshmimsft lakshmimsft Feb 19, 2025

Choose a reason for hiding this comment

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

We see this function returns resources that supportRecipes. Should we rename the function to reflect that??
Also where is this being used. 1. We use it in recipe_webhook.go to confirm if the resource runs with recipes 2. we refer to it to see if the resource can have AppId = "". (which needs it's own discussion perhaps)
I don't know is the name isPortableResource is conveying the right meaning.

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 thought portable resources are portable because of recipes and hence the function name. The name existed earlier too, but was a hardcoded listof built in types that supported recipes. I agree its a good idea to discuss. The idea of AppID= "" is because it is an environment resource (again prod env can have its recipe of mongo, test env has its recipe of mongo ). The logic and naming were already existing. The aspect I changed was to remove hardcoding of "portable" resource list and detect it based on manifest.

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.

3 participants