Skip to content

Commit 42a6f1b

Browse files
Update recipes to per resource unique name format (#5480)
# Description - Updated environment swagger spec - Updated datamodel and conversions and unit tests. - Refactored the codebase with the updated per resource format changes. - Updated getMetadata api: - updated the api to accept req body and moved pathparam(recipe name) and linktype inside it. - refactored the code with updated api changes - Update cli commands - updated "recipe unregister" command to accept recipename and linktype as params - updated "recipe register" and "recipe list" commands to work with the new format ## Issue reference Fixes: #5228 ## Checklist Please make sure you've completed the relevant tasks for this PR, out of the following list: * [x] Code compiles correctly * [x] Adds necessary unit tests for change * [ ] Adds necessary E2E tests for change * [x] Unit tests passing * [x] Extended the documentation / Created issue for it
1 parent ff8052f commit 42a6f1b

File tree

83 files changed

+892
-483
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+892
-483
lines changed

hack/bicep-types-radius/generated/applications/applications.core/2022-03-15-privatepreview/types.json

+1-1
Large diffs are not rendered by default.

hack/bicep-types-radius/generated/applications/applications.core/2022-03-15-privatepreview/types.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@
313313
* **extensions**: [EnvironmentExtension](#environmentextension)[]: Extensions spec of the resource
314314
* **providers**: [Providers](#providers): Cloud providers configuration
315315
* **provisioningState**: 'Accepted' | 'Canceled' | 'Deleting' | 'Failed' | 'Provisioning' | 'Succeeded' | 'Updating' (ReadOnly): Provisioning state of the resource at the time the operation was called.
316-
* **recipes**: [EnvironmentPropertiesRecipes](#environmentpropertiesrecipes): Dictionary of <EnvironmentRecipeProperties>
316+
* **recipes**: [EnvironmentPropertiesRecipes](#environmentpropertiesrecipes): Specifies Recipes linked to the Environment.
317317
* **useDevRecipes**: bool: Flag to use radius owned recipes.
318318

319319
## EnvironmentExtension
@@ -353,11 +353,15 @@
353353
## EnvironmentPropertiesRecipes
354354
### Properties
355355
### Additional Properties
356+
* **Additional Properties Type**: [DictionaryOfEnvironmentRecipeProperties](#dictionaryofenvironmentrecipeproperties)
357+
358+
## DictionaryOfEnvironmentRecipeProperties
359+
### Properties
360+
### Additional Properties
356361
* **Additional Properties Type**: [EnvironmentRecipeProperties](#environmentrecipeproperties)
357362

358363
## EnvironmentRecipeProperties
359364
### Properties
360-
* **linkType**: string (Required): Type of the link this recipe can be consumed by. For example: 'Applications.Link/mongoDatabases'
361365
* **parameters**: any: Any object
362366
* **templatePath**: string (Required): Path to the template provided by the recipe. Currently only link to Azure Container Registry is supported.
363367

Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"Resources":{"Applications.Core/environments@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":50},"Applications.Core/applications@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":74},"Applications.Core/httpRoutes@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":88},"Applications.Core/gateways@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":106},"Applications.Core/containers@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":171},"Applications.Core/volumes@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":208},"Applications.Core/secretStores@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":231},"Applications.Link/daprInvokeHttpRoutes@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":35},"Applications.Link/daprPubSubBrokers@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":55},"Applications.Link/daprSecretStores@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":73},"Applications.Link/daprStateStores@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":93},"Applications.Link/mongoDatabases@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":114},"Applications.Link/rabbitMQMessageQueues@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":133},"Applications.Link/redisCaches@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":154},"Applications.Link/sqlDatabases@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":174},"Applications.Link/extenders@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":189}},"Functions":{"applications.core/secretstores":{"2022-03-15-privatepreview":[{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":234}]},"applications.link/mongodatabases":{"2022-03-15-privatepreview":[{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":191}]},"applications.link/rabbitmqmessagequeues":{"2022-03-15-privatepreview":[{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":193}]},"applications.link/rediscaches":{"2022-03-15-privatepreview":[{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":195}]},"applications.link/extenders":{"2022-03-15-privatepreview":[{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":197}]}}}
1+
{"Resources":{"Applications.Core/environments@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":51},"Applications.Core/applications@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":75},"Applications.Core/httpRoutes@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":89},"Applications.Core/gateways@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":107},"Applications.Core/containers@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":172},"Applications.Core/volumes@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":209},"Applications.Core/secretStores@2022-03-15-privatepreview":{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":232},"Applications.Link/daprInvokeHttpRoutes@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":35},"Applications.Link/daprPubSubBrokers@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":55},"Applications.Link/daprSecretStores@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":73},"Applications.Link/daprStateStores@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":93},"Applications.Link/mongoDatabases@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":114},"Applications.Link/rabbitMQMessageQueues@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":133},"Applications.Link/redisCaches@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":154},"Applications.Link/sqlDatabases@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":174},"Applications.Link/extenders@2022-03-15-privatepreview":{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":189}},"Functions":{"applications.core/secretstores":{"2022-03-15-privatepreview":[{"RelativePath":"applications/applications.core/2022-03-15-privatepreview/types.json","Index":235}]},"applications.link/mongodatabases":{"2022-03-15-privatepreview":[{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":191}]},"applications.link/rabbitmqmessagequeues":{"2022-03-15-privatepreview":[{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":193}]},"applications.link/rediscaches":{"2022-03-15-privatepreview":[{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":195}]},"applications.link/extenders":{"2022-03-15-privatepreview":[{"RelativePath":"applications/applications.link/2022-03-15-privatepreview/types.json","Index":197}]}}}

pkg/armrpc/api/v1/error.go

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ type ErrClientRP struct {
3939
func (r *ErrClientRP) Error() string {
4040
return fmt.Sprintf("code %v: err %v", r.Code, r.Message)
4141
}
42+
func (e *ErrClientRP) Is(target error) bool {
43+
_, ok := target.(*ErrClientRP)
44+
return ok
45+
}
4246

4347
func NewClientErrInvalidRequest(message string) *ErrClientRP {
4448
err := new(ErrClientRP)

pkg/cli/clients/clients.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ type ApplicationsManagementClient interface {
159159
ListUCPGroup(ctx context.Context, planeType string, planeName string) ([]ucp_v20220901privatepreview.ResourceGroupResource, error)
160160

161161
// ShowRecipe shows recipe details including list of all parameters for a given recipe registered to an environment
162-
ShowRecipe(ctx context.Context, environmentName string, recipeName string) (corerp.EnvironmentRecipeProperties, error)
162+
ShowRecipe(ctx context.Context, environmentName string, recipe corerp.Recipe) (corerp.EnvironmentRecipeProperties, error)
163163
}
164164

165165
func ShallowCopy(params DeploymentParameters) DeploymentParameters {

pkg/cli/clients/mock_applicationsclient.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/cli/clivalidation.go

+12
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ type AzureResource struct {
2626
SubscriptionID string
2727
}
2828

29+
const (
30+
LinkTypeFlag = "link-type"
31+
)
32+
2933
func RequireEnvironmentNameArgs(cmd *cobra.Command, args []string, workspace workspaces.Workspace) (string, error) {
3034
environmentName, err := ReadEnvironmentNameArgs(cmd, args)
3135
if err != nil {
@@ -431,3 +435,11 @@ func RequireRecipeNameArgs(cmd *cobra.Command, args []string) (string, error) {
431435
}
432436
return args[0], nil
433437
}
438+
439+
func RequireLinkType(cmd *cobra.Command) (string, error) {
440+
linkType, err := cmd.Flags().GetString(LinkTypeFlag)
441+
if err != nil {
442+
return linkType, err
443+
}
444+
return linkType, nil
445+
}

pkg/cli/cmd/commonflags/flags.go

+4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ func AddParameterFlag(cmd *cobra.Command) {
6161
cmd.Flags().StringArrayP("parameters", "p", []string{}, "Specify parameters for the deployment")
6262
}
6363

64+
func AddLinkTypeFlag(cmd *cobra.Command) {
65+
cmd.Flags().String("link-type", "", "Specify the type of the link this recipe can be consumed by")
66+
}
67+
6468
func AddAzureScopeFlags(cmd *cobra.Command) {
6569
AddAzureSubscriptionFlag(cmd)
6670
AddAzureResourceGroupFlag(cmd)

pkg/cli/cmd/recipe/list/list.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,14 @@ func (r *Runner) Run(ctx context.Context) error {
9292
return err
9393
}
9494
var envRecipes []EnvironmentRecipe
95-
for recipeName, recipeProperties := range envResource.Properties.Recipes {
96-
recipe := EnvironmentRecipe{
97-
Name: recipeName,
98-
LinkType: *recipeProperties.LinkType,
99-
TemplatePath: *recipeProperties.TemplatePath,
95+
for link, recipes := range envResource.Properties.Recipes {
96+
for recipeName, recipeDetails := range recipes {
97+
envRecipes = append(envRecipes, EnvironmentRecipe{
98+
Name: recipeName,
99+
LinkType: link,
100+
TemplatePath: *recipeDetails.TemplatePath,
101+
})
100102
}
101-
envRecipes = append(envRecipes, recipe)
102103
}
103104
err = r.Output.WriteFormatted(r.Format, envRecipes, objectformats.GetEnvironmentRecipesTableFormat())
104105
if err != nil {

pkg/cli/cmd/recipe/list/list_test.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,11 @@ func Test_Run(t *testing.T) {
7373
Type: to.Ptr("applications.core/environments"),
7474
Location: to.Ptr(v1.LocationGlobal),
7575
Properties: &v20220315privatepreview.EnvironmentProperties{
76-
Recipes: map[string]*v20220315privatepreview.EnvironmentRecipeProperties{
77-
"cosmosDB": {
78-
LinkType: to.Ptr(linkrp.MongoDatabasesResourceType),
79-
TemplatePath: to.Ptr("testpublicrecipe.azurecr.io/bicep/modules/mongodatabases:v1"),
76+
Recipes: map[string]map[string]*v20220315privatepreview.EnvironmentRecipeProperties{
77+
linkrp.MongoDatabasesResourceType: {
78+
"cosmosDB": {
79+
TemplatePath: to.Ptr("testpublicrecipe.azurecr.io/bicep/modules/mongodatabases:v1"),
80+
},
8081
},
8182
},
8283
},

pkg/cli/cmd/recipe/register/register.go

+14-21
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
"github.com/project-radius/radius/pkg/cli/framework"
1818
"github.com/project-radius/radius/pkg/cli/output"
1919
"github.com/project-radius/radius/pkg/cli/workspaces"
20-
corerpapps "github.com/project-radius/radius/pkg/corerp/api/v20220315privatepreview"
20+
corerp "github.com/project-radius/radius/pkg/corerp/api/v20220315privatepreview"
2121
"github.com/spf13/cobra"
2222
)
2323

@@ -103,7 +103,7 @@ func (r *Runner) Validate(cmd *cobra.Command, args []string) error {
103103
}
104104
r.TemplatePath = templatePath
105105

106-
linkType, err := requireLinkType(cmd)
106+
linkType, err := cli.RequireLinkType(cmd)
107107
if err != nil {
108108
return err
109109
}
@@ -139,22 +139,23 @@ func (r *Runner) Run(ctx context.Context) error {
139139
return err
140140
}
141141

142-
recipeProperties := envResource.Properties.Recipes
143-
if recipeProperties == nil {
144-
recipeProperties = map[string]*corerpapps.EnvironmentRecipeProperties{}
142+
envRecipes := envResource.Properties.Recipes
143+
if envRecipes == nil {
144+
envRecipes = map[string]map[string]*corerp.EnvironmentRecipeProperties{}
145145
}
146146

147-
if recipeProperties[r.RecipeName] != nil {
148-
return &cli.FriendlyError{Message: fmt.Sprintf("recipe with name %q already exists in the environment %q", r.RecipeName, r.Workspace.Environment)}
149-
}
150-
151-
recipeProperties[r.RecipeName] = &corerpapps.EnvironmentRecipeProperties{
152-
LinkType: &r.LinkType,
147+
properties := &corerp.EnvironmentRecipeProperties{
153148
TemplatePath: &r.TemplatePath,
154149
Parameters: bicep.ConvertToMapStringInterface(r.Parameters),
155150
}
156-
157-
envResource.Properties.Recipes = recipeProperties
151+
if val, ok := envRecipes[r.LinkType]; ok {
152+
val[r.RecipeName] = properties
153+
} else {
154+
envRecipes[r.LinkType] = map[string]*corerp.EnvironmentRecipeProperties{
155+
r.RecipeName: properties,
156+
}
157+
}
158+
envResource.Properties.Recipes = envRecipes
158159

159160
isEnvCreated, err := client.CreateEnvironment(ctx, r.Workspace.Environment, v1.LocationGlobal, envResource.Properties)
160161
if err != nil || !isEnvCreated {
@@ -173,11 +174,3 @@ func requireTemplatePath(cmd *cobra.Command) (string, error) {
173174
return templatePath, nil
174175

175176
}
176-
177-
func requireLinkType(cmd *cobra.Command) (string, error) {
178-
linkType, err := cmd.Flags().GetString("link-type")
179-
if err != nil {
180-
return linkType, err
181-
}
182-
return linkType, nil
183-
}

0 commit comments

Comments
 (0)