Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions cmd/rad/cmd/recipepack.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Copyright 2023 The Radius Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package cmd

import (
"github.com/spf13/cobra"
)

func init() {
RootCmd.AddCommand(recipePackCmd)
recipePackCmd.PersistentFlags().StringP("workspace", "w", "", "The workspace name")
}

func NewRecipePackCommand() *cobra.Command {
return &cobra.Command{
Use: "recipe-pack",
Short: "Manage recipe-packs",
Long: `Manage recipe-packs
Recipe-packs automate the deployment of infrastructure and configuration of radius resources.`,
}
}
9 changes: 9 additions & 0 deletions cmd/rad/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ import (
recipe_register "github.com/radius-project/radius/pkg/cli/cmd/recipe/register"
recipe_show "github.com/radius-project/radius/pkg/cli/cmd/recipe/show"
recipe_unregister "github.com/radius-project/radius/pkg/cli/cmd/recipe/unregister"
recipe_pack_list "github.com/radius-project/radius/pkg/cli/cmd/recipepack/list"
recipe_pack_show "github.com/radius-project/radius/pkg/cli/cmd/recipepack/show"
resource_create "github.com/radius-project/radius/pkg/cli/cmd/resource/create"
resource_delete "github.com/radius-project/radius/pkg/cli/cmd/resource/delete"
resource_list "github.com/radius-project/radius/pkg/cli/cmd/resource/list"
Expand Down Expand Up @@ -124,6 +126,7 @@ var resourceCmd = NewResourceCommand()
var resourceProviderCmd = NewResourceProviderCommand()
var resourceTypeCmd = NewResourceTypeCommand()
var recipeCmd = NewRecipeCommand()
var recipePackCmd = NewRecipePackCommand()
var envCmd = NewEnvironmentCommand()
var workspaceCmd = NewWorkspaceCommand()

Expand Down Expand Up @@ -303,6 +306,12 @@ func initSubCommands() {
unregisterRecipeCmd, _ := recipe_unregister.NewCommand(framework)
recipeCmd.AddCommand(unregisterRecipeCmd)

listRecipePackCmd, _ := recipe_pack_list.NewCommand(framework)
recipePackCmd.AddCommand(listRecipePackCmd)

showRecipePackCmd, _ := recipe_pack_show.NewCommand(framework)
recipePackCmd.AddCommand(showRecipePackCmd)

providerCmd := credential.NewCommand(framework)
RootCmd.AddCommand(providerCmd)

Expand Down
10 changes: 10 additions & 0 deletions pkg/cli/clients/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

"github.com/radius-project/radius/pkg/cli/clients_new/generated"
corerp "github.com/radius-project/radius/pkg/corerp/api/v20231001preview"
radiuscore "github.com/radius-project/radius/pkg/corerp/api/v20250801preview"
ucp_v20231001preview "github.com/radius-project/radius/pkg/ucp/api/v20231001preview"
ucpresources "github.com/radius-project/radius/pkg/ucp/resources"
)
Expand Down Expand Up @@ -201,6 +202,15 @@ type ApplicationsManagementClient interface {
// ListEnvironmentsAll lists all environments across resource groups.
ListEnvironmentsAll(ctx context.Context) ([]corerp.EnvironmentResource, error)

// ListRecipePacksInResourceGroup lists all recipe packs in the configured scope (assumes configured scope is a resource group).
ListRecipePacksInResourceGroup(ctx context.Context) ([]radiuscore.RecipePackResource, error)

// ListRecipePacks lists all recipe packs in all resource groups.
ListRecipePacks(ctx context.Context) ([]radiuscore.RecipePackResource, error)

// GetRecipePack retrieves a recipe pack by its name (in the configured scope) or resource ID.
GetRecipePack(ctx context.Context, recipePackNameOrID string) (radiuscore.RecipePackResource, error)

// GetEnvironment retrieves an environment by its name (in the configured scope) or resource ID.
GetEnvironment(ctx context.Context, environmentNameOrID string) (corerp.EnvironmentResource, error)

Expand Down
86 changes: 86 additions & 0 deletions pkg/cli/clients/management.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
aztoken "github.com/radius-project/radius/pkg/azure/tokencredentials"
"github.com/radius-project/radius/pkg/cli/clients_new/generated"
corerpv20231001 "github.com/radius-project/radius/pkg/corerp/api/v20231001preview"
corerpv20250801 "github.com/radius-project/radius/pkg/corerp/api/v20250801preview"
ucpv20231001 "github.com/radius-project/radius/pkg/ucp/api/v20231001preview"
"github.com/radius-project/radius/pkg/ucp/resources"
resources_radius "github.com/radius-project/radius/pkg/ucp/resources/radius"
Expand All @@ -43,6 +44,7 @@ type UCPApplicationsManagementClient struct {
genericResourceClientFactory func(scope string, resourceType string) (genericResourceClient, error)
applicationResourceClientFactory func(scope string) (applicationResourceClient, error)
environmentResourceClientFactory func(scope string) (environmentResourceClient, error)
recipePackResourceClientFactory func(scope string) (recipePackResourceClient, error)
resourceGroupClientFactory func() (resourceGroupClient, error)
resourceProviderClientFactory func() (resourceProviderClient, error)
resourceTypeClientFactory func() (resourceTypeClient, error)
Expand Down Expand Up @@ -402,6 +404,63 @@ func (amc *UCPApplicationsManagementClient) DeleteApplication(ctx context.Contex
return response.StatusCode != 204, nil
}

// ListRecipePacksInResourceGroup lists all recipe packs in the configured scope (assumes configured scope is a resource group).
func (amc *UCPApplicationsManagementClient) ListRecipePacksInResourceGroup(ctx context.Context) ([]corerpv20250801.RecipePackResource, error) {
client, err := amc.createRecipePackClient(amc.RootScope)
if err != nil {
return nil, err
}

result := []corerpv20250801.RecipePackResource{}
pager := client.NewListByScopePager(&corerpv20250801.RecipePacksClientListByScopeOptions{})
for pager.More() {
page, err := pager.NextPage(ctx)
if err != nil {
return nil, err
}
for _, rp := range page.RecipePackResourceListResult.Value {
result = append(result, *rp)
}
}

return result, nil
}

// ListRecipePacks lists all recipe packs in all resource groups.
func (amc *UCPApplicationsManagementClient) ListRecipePacks(ctx context.Context) ([]corerpv20250801.RecipePackResource, error) {
scope, err := resources.ParseScope(amc.RootScope)
if err != nil {
return []corerpv20250801.RecipePackResource{}, err
}

// Query at plane scope, not resource group scope. We don't enforce the exact structure of the scope, so handle both cases.
//
// - /planes/radius/local
// - /planes/radius/local/resourceGroups/my-group
if scope.FindScope(resources_radius.ScopeResourceGroups) != "" {
scope = scope.Truncate()
}

client, err := amc.createRecipePackClient(scope.String())
if err != nil {
return nil, err
}

result := []corerpv20250801.RecipePackResource{}
pager := client.NewListByScopePager(&corerpv20250801.RecipePacksClientListByScopeOptions{})
for pager.More() {
page, err := pager.NextPage(ctx)
if err != nil {
return nil, err
}
for _, rp := range page.RecipePackResourceListResult.Value {
result = append(result, *rp)
}
}

return result, nil
}

// ListEnvironments lists all environments in the configured scope (assumes configured scope is a resource group).
func (amc *UCPApplicationsManagementClient) ListEnvironments(ctx context.Context) ([]corerpv20231001.EnvironmentResource, error) {
client, err := amc.createEnvironmentClient(amc.RootScope)
Expand Down Expand Up @@ -481,6 +540,26 @@ func (amc *UCPApplicationsManagementClient) GetEnvironment(ctx context.Context,
return response.EnvironmentResource, nil
}

// GetRecipePack retrieves a recipe pack by name (in the configured scope) or full resource ID.
func (amc *UCPApplicationsManagementClient) GetRecipePack(ctx context.Context, recipePackNameOrID string) (corerpv20250801.RecipePackResource, error) {
scope, name, err := amc.extractScopeAndName(recipePackNameOrID)
if err != nil {
return corerpv20250801.RecipePackResource{}, err
}

client, err := amc.createRecipePackClient(scope)
if err != nil {
return corerpv20250801.RecipePackResource{}, err
}

resp, err := client.Get(ctx, name, &corerpv20250801.RecipePacksClientGetOptions{})
if err != nil {
return corerpv20250801.RecipePackResource{}, err
}

return resp.RecipePackResource, nil
}

// GetRecipeMetadata shows recipe details including list of all parameters for a given recipe registered to an environment.
func (amc *UCPApplicationsManagementClient) GetRecipeMetadata(ctx context.Context, environmentNameOrID string, recipeMetadata corerpv20231001.RecipeGetMetadata) (corerpv20231001.RecipeGetMetadataResponse, error) {
scope, name, err := amc.extractScopeAndName(environmentNameOrID)
Expand Down Expand Up @@ -1107,6 +1186,13 @@ func (amc *UCPApplicationsManagementClient) createApplicationClient(scope string
return amc.applicationResourceClientFactory(scope)
}

func (amc *UCPApplicationsManagementClient) createRecipePackClient(scope string) (recipePackResourceClient, error) {
if amc.recipePackResourceClientFactory == nil {
return corerpv20250801.NewRecipePacksClient(strings.TrimPrefix(scope, resources.SegmentSeparator), &aztoken.AnonymousCredential{}, amc.ClientOptions)
}
return amc.recipePackResourceClientFactory(scope)
}

func (amc *UCPApplicationsManagementClient) createEnvironmentClient(scope string) (environmentResourceClient, error) {
if amc.environmentResourceClientFactory == nil {
// Generated client doesn't like the leading '/' in the scope.
Expand Down
11 changes: 10 additions & 1 deletion pkg/cli/clients/management_mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
"github.com/radius-project/radius/pkg/cli/clients_new/generated"
corerpv20231001 "github.com/radius-project/radius/pkg/corerp/api/v20231001preview"
corerpv20250801 "github.com/radius-project/radius/pkg/corerp/api/v20250801preview"
ucpv20231001 "github.com/radius-project/radius/pkg/ucp/api/v20231001preview"
)

Expand All @@ -34,7 +35,7 @@ import (
// Because these interfaces are non-exported, they MUST be defined in their own file
// and we MUST use -source on mockgen to generate mocks for them.

//go:generate mockgen -typed -source=./management_mocks.go -destination=./mock_management_wrapped_clients.go -package=clients -self_package github.com/radius-project/radius/pkg/cli/clients github.com/radius-project/radius/pkg/cli/clients genericResourceClient,applicationResourceClient,environmentResourceClient,resourceGroupClient,resourceProviderClient,resourceTypeClient,apiVersonClient,locationClient
//go:generate mockgen -typed -source=./management_mocks.go -destination=./mock_management_wrapped_clients.go -package=clients -self_package github.com/radius-project/radius/pkg/cli/clients github.com/radius-project/radius/pkg/cli/clients genericResourceClient,applicationResourceClient,environmentResourceClient,resourceGroupClient,resourceProviderClient,resourceTypeClient,apiVersonClient,locationClient,recipePackResourceClient

// genericResourceClient is an interface for mocking the generated SDK client for any resource.
type genericResourceClient interface {
Expand Down Expand Up @@ -97,3 +98,11 @@ type apiVersionClient interface {
type locationClient interface {
BeginCreateOrUpdate(ctx context.Context, planeName string, resourceProviderName string, locationName string, resource ucpv20231001.LocationResource, options *ucpv20231001.LocationsClientBeginCreateOrUpdateOptions) (*runtime.Poller[ucpv20231001.LocationsClientCreateOrUpdateResponse], error)
}

// recipePackResourceClient is an interface for mocking the generated SDK client for recipePack resources.
type recipePackResourceClient interface {
CreateOrUpdate(ctx context.Context, recipePackName string, resource corerpv20250801.RecipePackResource, options *corerpv20250801.RecipePacksClientCreateOrUpdateOptions) (corerpv20250801.RecipePacksClientCreateOrUpdateResponse, error)
Delete(ctx context.Context, recipePackName string, options *corerpv20250801.RecipePacksClientDeleteOptions) (corerpv20250801.RecipePacksClientDeleteResponse, error)
Get(ctx context.Context, recipePackName string, options *corerpv20250801.RecipePacksClientGetOptions) (corerpv20250801.RecipePacksClientGetResponse, error)
NewListByScopePager(options *corerpv20250801.RecipePacksClientListByScopeOptions) *runtime.Pager[corerpv20250801.RecipePacksClientListByScopeResponse]
}
118 changes: 118 additions & 0 deletions pkg/cli/clients/mock_applicationsclient.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading