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

Redesign plane resource types #7499

Merged
merged 1 commit into from
May 6, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ ucp:
| Key | Description | Example |
|-----|-------------|---------|
| id | The ID of the UCP plane | `/planes/radius/local` |
| type | The type of UCP plane | `System.Planes/radius` |
rynowak marked this conversation as resolved.
Show resolved Hide resolved
| type | The type of UCP plane | `System.Radius/planes` |
| name | The name of the UCP plane | `ucp` |
| properties | The properties specified on the plane | [**See below**](#properties) |

Expand Down
8 changes: 4 additions & 4 deletions pkg/cli/clients/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ type ApplicationsManagementClient interface {
ListEnvironmentsAll(ctx context.Context) ([]corerp.EnvironmentResource, error)
GetEnvDetails(ctx context.Context, envName string) (corerp.EnvironmentResource, error)
DeleteEnv(ctx context.Context, envName string) (bool, error)
CreateUCPGroup(ctx context.Context, planeType string, planeName string, resourceGroupName string, resourceGroup ucp_v20231001preview.ResourceGroupResource) error
rynowak marked this conversation as resolved.
Show resolved Hide resolved
DeleteUCPGroup(ctx context.Context, planeType string, planeName string, resourceGroupName string) (bool, error)
ShowUCPGroup(ctx context.Context, planeType string, planeName string, resourceGroupName string) (ucp_v20231001preview.ResourceGroupResource, error)
ListUCPGroup(ctx context.Context, planeType string, planeName string) ([]ucp_v20231001preview.ResourceGroupResource, error)
CreateUCPGroup(ctx context.Context, planeName string, resourceGroupName string, resourceGroup ucp_v20231001preview.ResourceGroupResource) error
DeleteUCPGroup(ctx context.Context, planeName string, resourceGroupName string) (bool, error)
ShowUCPGroup(ctx context.Context, planeName string, resourceGroupName string) (ucp_v20231001preview.ResourceGroupResource, error)
ListUCPGroup(ctx context.Context, planeName string) ([]ucp_v20231001preview.ResourceGroupResource, error)

// ShowRecipe shows recipe details including list of all parameters for a given recipe registered to an environment
ShowRecipe(ctx context.Context, environmentName string, recipe corerp.RecipeGetMetadata) (corerp.RecipeGetMetadataResponse, error)
Expand Down
18 changes: 9 additions & 9 deletions pkg/cli/clients/management.go
Original file line number Diff line number Diff line change
Expand Up @@ -551,14 +551,14 @@ func (amc *UCPApplicationsManagementClient) DeleteEnv(ctx context.Context, envNa

// CreateUCPGroup creates a new resource group in the specified plane type and plane name using the provided resource
// group resource and returns an error if one occurs.
func (amc *UCPApplicationsManagementClient) CreateUCPGroup(ctx context.Context, planeType string, planeName string, resourceGroupName string, resourceGroup ucpv20231001.ResourceGroupResource) error {
func (amc *UCPApplicationsManagementClient) CreateUCPGroup(ctx context.Context, planeName string, resourceGroupName string, resourceGroup ucpv20231001.ResourceGroupResource) error {
var resourceGroupOptions *ucpv20231001.ResourceGroupsClientCreateOrUpdateOptions
resourcegroupClient, err := ucpv20231001.NewResourceGroupsClient(&aztoken.AnonymousCredential{}, amc.ClientOptions)
if err != nil {
return err
}

_, err = resourcegroupClient.CreateOrUpdate(ctx, planeType, planeName, resourceGroupName, resourceGroup, resourceGroupOptions)
_, err = resourcegroupClient.CreateOrUpdate(ctx, planeName, resourceGroupName, resourceGroup, resourceGroupOptions)
if err != nil {
return err
}
Expand All @@ -568,7 +568,7 @@ func (amc *UCPApplicationsManagementClient) CreateUCPGroup(ctx context.Context,

// DeleteUCPGroup attempts to delete a UCP resource group using the provided plane type, plane name and resource group
// name, and returns a boolean indicating success or failure and an error if one occurs.
func (amc *UCPApplicationsManagementClient) DeleteUCPGroup(ctx context.Context, planeType string, planeName string, resourceGroupName string) (bool, error) {
func (amc *UCPApplicationsManagementClient) DeleteUCPGroup(ctx context.Context, planeName string, resourceGroupName string) (bool, error) {
var resourceGroupOptions *ucpv20231001.ResourceGroupsClientDeleteOptions
resourcegroupClient, err := ucpv20231001.NewResourceGroupsClient(&aztoken.AnonymousCredential{}, amc.ClientOptions)

Expand All @@ -578,7 +578,7 @@ func (amc *UCPApplicationsManagementClient) DeleteUCPGroup(ctx context.Context,
return false, err
}

_, err = resourcegroupClient.Delete(ctxWithResp, planeType, planeName, resourceGroupName, resourceGroupOptions)
_, err = resourcegroupClient.Delete(ctxWithResp, planeName, resourceGroupName, resourceGroupOptions)
if err != nil {
return false, err
}
Expand All @@ -587,16 +587,16 @@ func (amc *UCPApplicationsManagementClient) DeleteUCPGroup(ctx context.Context,

}

// ShowUCPGroup is a function that retrieves a resource group from the Azure Resource Manager using the given plane type,
// ShowUCPGroup is a function that retrieves a resource group from the UCP API using the given plane type,
// plane name and resource group name, and returns the resource group resource or an error if one occurs.
func (amc *UCPApplicationsManagementClient) ShowUCPGroup(ctx context.Context, planeType string, planeName string, resourceGroupName string) (ucpv20231001.ResourceGroupResource, error) {
func (amc *UCPApplicationsManagementClient) ShowUCPGroup(ctx context.Context, planeName string, resourceGroupName string) (ucpv20231001.ResourceGroupResource, error) {
var resourceGroupOptions *ucpv20231001.ResourceGroupsClientGetOptions
resourcegroupClient, err := ucpv20231001.NewResourceGroupsClient(&aztoken.AnonymousCredential{}, amc.ClientOptions)
if err != nil {
return ucpv20231001.ResourceGroupResource{}, err
}

resp, err := resourcegroupClient.Get(ctx, planeType, planeName, resourceGroupName, resourceGroupOptions)
resp, err := resourcegroupClient.Get(ctx, planeName, resourceGroupName, resourceGroupOptions)
if err != nil {
return ucpv20231001.ResourceGroupResource{}, err
}
Expand All @@ -606,15 +606,15 @@ func (amc *UCPApplicationsManagementClient) ShowUCPGroup(ctx context.Context, pl

// ListUCPGroup is a function that retrieves a list of resource groups from the UCP API and returns them as a slice of
// ResourceGroupResource objects. It may return an error if there is an issue with the API request.
func (amc *UCPApplicationsManagementClient) ListUCPGroup(ctx context.Context, planeType string, planeName string) ([]ucpv20231001.ResourceGroupResource, error) {
func (amc *UCPApplicationsManagementClient) ListUCPGroup(ctx context.Context, planeName string) ([]ucpv20231001.ResourceGroupResource, error) {
var resourceGroupOptions *ucpv20231001.ResourceGroupsClientListOptions
resourceGroupResources := []ucpv20231001.ResourceGroupResource{}
resourcegroupClient, err := ucpv20231001.NewResourceGroupsClient(&aztoken.AnonymousCredential{}, amc.ClientOptions)
if err != nil {
return resourceGroupResources, err
}

pager := resourcegroupClient.NewListPager(planeType, planeName, resourceGroupOptions)
pager := resourcegroupClient.NewListPager(planeName, resourceGroupOptions)

for pager.More() {
resp, err := pager.NextPage(ctx)
Expand Down
32 changes: 16 additions & 16 deletions pkg/cli/clients/mock_applicationsclient.go

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

2 changes: 1 addition & 1 deletion pkg/cli/cmd/env/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (r *Runner) Validate(cmd *cobra.Command, args []string) error {
}
r.ResourceGroupName = scopeId.FindScope(resources_radius.ScopeResourceGroups)

_, err = client.ShowUCPGroup(cmd.Context(), "radius", "local", r.ResourceGroupName)
_, err = client.ShowUCPGroup(cmd.Context(), "local", r.ResourceGroupName)
if clients.Is404Error(err) {
return clierrors.Message("Resource group %q could not be found.", r.ResourceGroupName)
} else if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/cmd/env/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,13 +283,13 @@ func createValidateNamespaceError(namespaceClient *namespace.MockInterface) {

func createShowUCPSuccess(appManagementClient *clients.MockApplicationsManagementClient, testResourceGroup v20231001preview.ResourceGroupResource) {
appManagementClient.EXPECT().
ShowUCPGroup(gomock.Any(), gomock.Any(), gomock.Any(), "test-resource-group").
ShowUCPGroup(gomock.Any(), gomock.Any(), "test-resource-group").
Return(testResourceGroup, nil).Times(1)
}

func createShowUCPError(appManagementClient *clients.MockApplicationsManagementClient, testResourceGroup v20231001preview.ResourceGroupResource) {
appManagementClient.EXPECT().
ShowUCPGroup(gomock.Any(), gomock.Any(), gomock.Any(), "invalidresourcegroup").
ShowUCPGroup(gomock.Any(), gomock.Any(), "invalidresourcegroup").
Return(testResourceGroup, clierrors.Message("The resource group %q could not be found.", "invalidresourcegroup")).Times(1)

}
2 changes: 1 addition & 1 deletion pkg/cli/cmd/group/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func (r *Runner) Run(ctx context.Context) error {

r.Output.LogInfo("creating resource group %q in workspace %q...\n", r.UCPResourceGroupName, r.Workspace.Name)

err = client.CreateUCPGroup(ctx, "radius", "local", r.UCPResourceGroupName, v20231001preview.ResourceGroupResource{
err = client.CreateUCPGroup(ctx, "local", r.UCPResourceGroupName, v20231001preview.ResourceGroupResource{
Location: to.Ptr(v1.LocationGlobal),
})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/cmd/group/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func Test_Run(t *testing.T) {
defer ctrl.Finish()

appManagementClient := clients.NewMockApplicationsManagementClient(ctrl)
appManagementClient.EXPECT().CreateUCPGroup(gomock.Any(), "radius", "local", "testrg", gomock.Any()).Return(nil).Times(1)
appManagementClient.EXPECT().CreateUCPGroup(gomock.Any(), "local", "testrg", gomock.Any()).Return(nil).Times(1)

workspace := &workspaces.Workspace{
Connection: map[string]any{
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/cmd/group/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (r *Runner) Run(ctx context.Context) error {
return err
}

deleted, err := client.DeleteUCPGroup(ctx, "radius", "local", r.UCPResourceGroupName)
deleted, err := client.DeleteUCPGroup(ctx, "local", r.UCPResourceGroupName)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/cmd/group/delete/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func Test_Run(t *testing.T) {
ctrl := gomock.NewController(t)

appManagementClient := clients.NewMockApplicationsManagementClient(ctrl)
appManagementClient.EXPECT().DeleteUCPGroup(gomock.Any(), "radius", "local", "testrg").Return(true, nil).Times(1)
appManagementClient.EXPECT().DeleteUCPGroup(gomock.Any(), "local", "testrg").Return(true, nil).Times(1)

outputSink := &output.MockOutput{}

Expand Down Expand Up @@ -108,7 +108,7 @@ func Test_Run(t *testing.T) {
ctrl := gomock.NewController(t)

appManagementClient := clients.NewMockApplicationsManagementClient(ctrl)
appManagementClient.EXPECT().DeleteUCPGroup(gomock.Any(), "radius", "local", "testrg").Return(false, nil).Times(1)
appManagementClient.EXPECT().DeleteUCPGroup(gomock.Any(), "local", "testrg").Return(false, nil).Times(1)

outputSink := &output.MockOutput{}

Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/cmd/group/groupswitch/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (r *Runner) Run(ctx context.Context) error {
return err
}

_, err = client.ShowUCPGroup(ctx, "radius", "local", r.UCPResourceGroupName)
_, err = client.ShowUCPGroup(ctx, "local", r.UCPResourceGroupName)
if err != nil {
return clierrors.Message("The resource group %q does not exist. Run `rad group create` or `rad init` and try again.", r.UCPResourceGroupName)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/cmd/group/groupswitch/switch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func Test_Run(t *testing.T) {
defer ctrl.Finish()

appManagementClient := clients.NewMockApplicationsManagementClient(ctrl)
appManagementClient.EXPECT().ShowUCPGroup(gomock.Any(), gomock.Any(), gomock.Any(), "a").Return(testResourceGroup, nil)
appManagementClient.EXPECT().ShowUCPGroup(gomock.Any(), gomock.Any(), "a").Return(testResourceGroup, nil)

workspace := &workspaces.Workspace{
Name: "b",
Expand Down Expand Up @@ -209,7 +209,7 @@ func Test_Run(t *testing.T) {
defer ctrl.Finish()

appManagementClient := clients.NewMockApplicationsManagementClient(ctrl)
appManagementClient.EXPECT().ShowUCPGroup(gomock.Any(), gomock.Any(), gomock.Any(), "c").Return(testResourceGroup, errors.New("resource group doesnt exist"))
appManagementClient.EXPECT().ShowUCPGroup(gomock.Any(), gomock.Any(), "c").Return(testResourceGroup, errors.New("resource group doesnt exist"))

workspace := &workspaces.Workspace{
Name: "b",
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/cmd/group/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func (r *Runner) Run(ctx context.Context) error {
return err
}

resourceGroupDetails, err := client.ListUCPGroup(ctx, "radius", "local")
resourceGroupDetails, err := client.ListUCPGroup(ctx, "local")
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/cmd/group/list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func Test_Run(t *testing.T) {
}

appManagementClient := clients.NewMockApplicationsManagementClient(ctrl)
appManagementClient.EXPECT().ListUCPGroup(gomock.Any(), gomock.Any(), gomock.Any()).Return(resourceGroups, nil).Times(1)
appManagementClient.EXPECT().ListUCPGroup(gomock.Any(), gomock.Any()).Return(resourceGroups, nil).Times(1)

workspace := &workspaces.Workspace{
Connection: map[string]any{
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/cmd/group/show/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func (r *Runner) Run(ctx context.Context) error {
return err
}

resourceGroup, err := client.ShowUCPGroup(ctx, "radius", "local", r.UCPResourceGroupName)
resourceGroup, err := client.ShowUCPGroup(ctx, "local", r.UCPResourceGroupName)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/cmd/group/show/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func Test_Run(t *testing.T) {
defer ctrl.Finish()

appManagementClient := clients.NewMockApplicationsManagementClient(ctrl)
appManagementClient.EXPECT().ShowUCPGroup(gomock.Any(), gomock.Any(), gomock.Any(), "testrg").Return(testResourceGroup, nil)
appManagementClient.EXPECT().ShowUCPGroup(gomock.Any(), gomock.Any(), "testrg").Return(testResourceGroup, nil)

workspace := &workspaces.Workspace{
Connection: map[string]any{
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/cmd/radinit/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (r *Runner) CreateEnvironment(ctx context.Context) error {
return err
}

err = client.CreateUCPGroup(ctx, "radius", "local", r.Options.Environment.Name, ucp.ResourceGroupResource{
err = client.CreateUCPGroup(ctx, "local", r.Options.Environment.Name, ucp.ResourceGroupResource{
Location: to.Ptr(v1.LocationGlobal),
})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/cmd/radinit/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ func Test_Run_InstallAndCreateEnvironment(t *testing.T) {

appManagementClient := clients.NewMockApplicationsManagementClient(ctrl)
appManagementClient.EXPECT().
CreateUCPGroup(context.Background(), "radius", "local", "default", gomock.Any()).
CreateUCPGroup(context.Background(), "local", "default", gomock.Any()).
Return(nil).
Times(1)

Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/cmd/workspace/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func (r *Runner) Validate(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
_, err := client.ShowUCPGroup(cmd.Context(), "radius", "local", group)
_, err := client.ShowUCPGroup(cmd.Context(), "local", group)
if err != nil {
return clierrors.Message("The resource group %q does not exist. Run `rad env create` try again.", r.Workspace.Scope)
}
Expand Down
Loading