-
Notifications
You must be signed in to change notification settings - Fork 120
add type, name and id to properties accessible. #10932
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: nithyatsu <[email protected]>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #10932 +/- ##
==========================================
+ Coverage 50.43% 50.46% +0.02%
==========================================
Files 672 672
Lines 42057 42072 +15
==========================================
+ Hits 21213 21230 +17
- Misses 18788 18789 +1
+ Partials 2056 2053 -3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: nithyatsu <[email protected]>
Radius functional test overviewClick here to see the test run details
Test Status⌛ Building Radius and pushing container images for functional tests... |
| // context.resource.connections.[connection-name].id | ||
| // context.resource.connections.[connection-name].name | ||
| // context.resource.connections.[connection-name].type | ||
| Connections map[string]recipes.ConnectedResource `json:"connections,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zachcasper @sk593 , the comment captures the change to connections. please review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enhances the recipe context by exposing connected resource metadata (ID, Name, Type) in addition to the existing Properties field. Previously, recipes could only access connected resource properties directly; now they must access them through a properties field while also having access to resource metadata.
Key changes:
- Introduced
ConnectedResourcestruct containing ID, Name, Type, and Properties fields - Changed
ConnectedResourcesPropertiesfrommap[string]map[string]anytomap[string]ConnectedResourcethroughout the codebase - Updated recipe templates (Bicep and Terraform) to access connected resource properties via
.properties.path
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/recipes/types.go | Added new ConnectedResource struct to encapsulate connected resource metadata and properties; updated ResourceMetadata.ConnectedResourcesProperties field type |
| pkg/resourceutil/utils.go | Added ResourceMetadata struct and GetAllPropertiesFromResource function to extract resource ID, name, type, and properties from resources |
| pkg/resourceutil/utils_test.go | Added comprehensive tests for GetAllPropertiesFromResource including edge cases, error scenarios, and nested properties |
| pkg/recipes/recipecontext/types.go | Updated Resource.Connections field type from map[string]map[string]any to map[string]recipes.ConnectedResource and updated documentation |
| pkg/recipes/recipecontext/context_test.go | Added test TestNewContext_WithConnectedResources to verify connected resource metadata is properly populated in recipe context |
| pkg/recipes/engine/engine_test.go | Updated test data to use new ConnectedResource struct format |
| pkg/recipes/terraform/execute_test.go | Updated test data to use new ConnectedResource struct format with full metadata |
| pkg/portableresources/backend/controller/createorupdateresource.go | Changed to call GetAllPropertiesFromResource instead of GetPropertiesFromResource and populate ConnectedResource struct with metadata |
| pkg/portableresources/backend/controller/createorupdateresource_test.go | Updated test data and added integration test for GetAllPropertiesFromResource |
| test/testrecipes/test-bicep-recipes/dynamicrp_recipe.bicep | Updated recipe to access connected resource properties via new .properties.configMap path |
| test/testrecipes/test-terraform-recipes/parent-udt/main.tf | Updated recipe to access connected resource properties via new .properties.configMap path |
| // ResourceMetadata represents resource metadata including ID, Name, Type and Properties | ||
| type ResourceMetadata struct { | ||
| ID string `json:"id"` | ||
| Name string `json:"name"` | ||
| Type string `json:"type"` | ||
| Properties map[string]any `json:"properties,omitempty"` | ||
| } |
Copilot
AI
Dec 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are now two different ResourceMetadata types in the codebase with the same name but different purposes:
resourceutil.ResourceMetadata(this struct) - represents resource metadata with ID, Name, Type, and Propertiesrecipes.ResourceMetadata- represents recipe metadata including resource ID, properties, connected resources, and parameters
This creates naming confusion and ambiguity. Consider renaming this struct to something more specific like ResourceInfo or ExtractedResourceMetadata to clearly differentiate it from the recipes package type and indicate its purpose is for extracting resource information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be an important feedback.
| rpv1 "github.com/radius-project/radius/pkg/rp/v1" | ||
| ) | ||
|
|
||
| // ConnectedResource represents a connected resource's metadata and properties |
Copilot
AI
Dec 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment should follow Go documentation conventions by starting with the type name. It should read: "ConnectedResource represents a connected resource's metadata and properties."
| // ConnectedResource represents a connected resource's metadata and properties | |
| // ConnectedResource represents a connected resource's metadata and properties. |
|
|
||
| func TestGetAllPropertiesFromResource_Integration(t *testing.T) { | ||
| // Simple integration test for resourceutil.GetAllPropertiesFromResource | ||
| connectedResourceID := "/planes/radius/local/resourceGroups/radius-test-rg/providers/Applications.Datastores/sqlDatabases/test-db" |
Copilot
AI
Dec 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected after the resource ID string. Remove the trailing whitespace for cleaner code.
|
|
||
| // Test the GetAllPropertiesFromResource function | ||
| metadata, err := resourceutil.GetAllPropertiesFromResource(testResource, connectedResourceID) | ||
|
|
Copilot
AI
Dec 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing whitespace detected after the function call. Remove the trailing whitespace for cleaner code.
| // Properties represents the properties of the resource. | ||
| Properties map[string]any `json:"properties,omitempty"` | ||
|
|
||
| // Connections represent a map of connections to other resources. |
Copilot
AI
Dec 12, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment has inconsistent capitalization. "Connections" should start with a lowercase letter to follow Go documentation conventions for field comments. Change "Connections represent" to "connections represent".
| return nil, fmt.Errorf("failed to get connected resource IDs: %w", err) | ||
| } | ||
| connectedResourcesProperties := make(map[string]map[string]any) | ||
| connectedResourcesProperties := make(map[string]recipes.ConnectedResource) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be renamed to just connectedResources? Do we need to have Properties postfix?
| } | ||
|
|
||
| connectedResourceProperties, err := resourceutil.GetPropertiesFromResource(connectedResource.Data) | ||
| connectedResourceMetadata, err := resourceutil.GetAllPropertiesFromResource(connectedResource.Data, connectedResourceID) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the connectedResourceID here? Is it the same as connectedResource.ID?
| connectedResourceMetadata, err := resourceutil.GetAllPropertiesFromResource(connectedResource.Data, connectedResourceID) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to get properties from connected resource %s: %w", connectedResourceID, err) | ||
| return nil, fmt.Errorf("failed to get metadata from connected resource %s: %w", connectedResourceID, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function is named GetAllPropertiesFromResource, why did we change the log to say metadata instead of properties?
| } | ||
| } | ||
|
|
||
| func TestGetAllPropertiesFromResource_Integration(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does the _Integration mean here? What is our naming convention for tests like this? Should we have an underscore right after Test prefix?
| "resourceName": "resource1", | ||
| }, | ||
| ConnectedResourcesProperties: map[string]map[string]any{ | ||
| ConnectedResourcesProperties: map[string]recipes.ConnectedResource{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to do some assertions here?
| Connections map[string]map[string]any `json:"connections,omitempty"` | ||
| // The key is the connection name, and the value contains the connected resource's metadata and properties. | ||
| // We enrich the recipe context with this, allowing the recipe to access connected resource info using: | ||
| // context.resource.connections.[connection-name].properties.[property-name] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be as follows:
| // context.resource.connections.[connection-name].properties.[property-name] | |
| // context.resource.connections.[connection-name].properties[property-name] |
?
| }, | ||
| ResourceRecipe: &recipes.ResourceMetadata{ | ||
| ConnectedResourcesProperties: map[string]map[string]any{ | ||
| ConnectedResourcesProperties: map[string]recipes.ConnectedResource{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to do some assertions?
| // ResourceMetadata represents resource metadata including ID, Name, Type and Properties | ||
| type ResourceMetadata struct { | ||
| ID string `json:"id"` | ||
| Name string `json:"name"` | ||
| Type string `json:"type"` | ||
| Properties map[string]any `json:"properties,omitempty"` | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be an important feedback.
|
|
||
| // GetAllPropertiesFromResource extracts the resource metadata including ID, Name, Type and properties | ||
| // by parsing the resource ID and extracting properties. | ||
| func GetAllPropertiesFromResource[P any](resource P, resourceID string) (*ResourceMetadata, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the resourceID belong to the resource? If so, why do we need to pass in the resourceID? Can't we just do resource.ID?
If not, is it the target resource or somethin like that?
We need clearer argument names, I believe.
| return &ResourceMetadata{ | ||
| ID: resourceID, | ||
| Name: parsedResourceID.Name(), | ||
| Type: parsedResourceID.Type(), | ||
| Properties: properties, | ||
| }, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the difference between resourceID and parsedResourceID?
Description
Populate Name, ID and Type of the child resource in addition to existing Properties, in the data accessible to a parent resource's recipe.
Type of change
Fixes: #issue_number
Contributor checklist
Please verify that the PR meets the following requirements, where applicable: