Skip to content

Commit

Permalink
remove hardcoded list of resource types from cli. (#8286)
Browse files Browse the repository at this point in the history
# Description

Since we now register resource provider manifests at startup and are in
process of enabling UDT end to end, we should not use static resource
type lists.

This PR removes static resource type lists in cli code. 

## Type of change

- This pull request adds or changes features of Radius and has an
approved issue (issue link required).

Part of #6688

## 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
    - [X ] Not applicable
- A design document PR is created in the [design-notes
repository](https://github.com/radius-project/design-notes/), if new
APIs are being introduced.
    - [ ] Yes
    - [X ] Not applicable
- The design document has been reviewed and approved by Radius
maintainers/approvers.
    - [ ] Yes
    - [ X] Not applicable
- A PR for the [samples
repository](https://github.com/radius-project/samples) is created, if
existing samples are affected by the changes in this PR.
    - [ ] Yes
    - [X ] Not applicable
- A PR for the [documentation
repository](https://github.com/radius-project/docs) is created, if the
changes in this PR affect the documentation or any user facing updates
are made.
    - [ ] Yes
    - [X ] Not applicable
- A PR for the [recipes
repository](https://github.com/radius-project/recipes) is created, if
existing recipes are affected by the changes in this PR.
    - [ ] Yes
    - [ X] Not applicable
  • Loading branch information
nithyatsu authored Feb 11, 2025
1 parent ea992df commit d0246d7
Show file tree
Hide file tree
Showing 21 changed files with 983 additions and 746 deletions.
2 changes: 1 addition & 1 deletion cmd/rad/cmd/resourceExpose.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
const (
LevenshteinCutoff = 2

ContainerType = "containers"
ContainerType = "Applications.Core/containers"
)

var resourceExposeCmd = &cobra.Command{
Expand Down
7 changes: 5 additions & 2 deletions pkg/cli/clients/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,15 @@ type ApplicationsManagementClient interface {
// GetResourceProviderSummary gets the resource provider summary with the specified name in the configured scope.
GetResourceProviderSummary(ctx context.Context, planeName string, providerNamespace string) (ucp_v20231001preview.ResourceProviderSummary, error)

// CreateOrUpdateResourceType creates or updates a resource type in the configured scope.
// CreateOrUpdateResourceType creates or updates a resource type in the configured plane.
CreateOrUpdateResourceType(ctx context.Context, planeName string, providerNamespace string, resourceTypeName string, resource *ucp_v20231001preview.ResourceTypeResource) (ucp_v20231001preview.ResourceTypeResource, error)

// DeleteResourceType deletes a resource type in the configured scope.
// DeleteResourceType deletes a resource type in the configured plane.
DeleteResourceType(ctx context.Context, planeName string, providerNamespace string, resourceTypeName string) (bool, error)

// ListAllResourceTypesNames lists the names of all resource types in the configured plane.
ListAllResourceTypesNames(ctx context.Context, planeName string) ([]string, error)

// CreateOrUpdateAPIVersion creates or updates an API version in the configured scope.
CreateOrUpdateAPIVersion(ctx context.Context, planeName string, providerNamespace string, resourceTypeName string, apiVersionName string, resource *ucp_v20231001preview.APIVersionResource) (ucp_v20231001preview.APIVersionResource, error)

Expand Down
150 changes: 84 additions & 66 deletions pkg/cli/clients/management.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ package clients

import (
"context"
"fmt"
"net/http"
"slices"
"strings"

"github.com/Azure/azure-sdk-for-go/sdk/azcore/arm"
Expand All @@ -29,13 +31,6 @@ 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"
cntr_ctrl "github.com/radius-project/radius/pkg/corerp/frontend/controller/containers"
ext_ctrl "github.com/radius-project/radius/pkg/corerp/frontend/controller/extenders"
gtwy_ctrl "github.com/radius-project/radius/pkg/corerp/frontend/controller/gateways"
sstr_ctrl "github.com/radius-project/radius/pkg/corerp/frontend/controller/secretstores"
dapr_ctrl "github.com/radius-project/radius/pkg/daprrp/frontend/controller"
ds_ctrl "github.com/radius-project/radius/pkg/datastoresrp/frontend/controller"
msg_ctrl "github.com/radius-project/radius/pkg/messagingrp/frontend/controller"
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 @@ -57,23 +52,6 @@ type UCPApplicationsManagementClient struct {

var _ ApplicationsManagementClient = (*UCPApplicationsManagementClient)(nil)

var (
ResourceTypesList = []string{
ds_ctrl.MongoDatabasesResourceType,
msg_ctrl.RabbitMQQueuesResourceType,
ds_ctrl.RedisCachesResourceType,
ds_ctrl.SqlDatabasesResourceType,
dapr_ctrl.DaprStateStoresResourceType,
dapr_ctrl.DaprSecretStoresResourceType,
dapr_ctrl.DaprPubSubBrokersResourceType,
dapr_ctrl.DaprConfigurationStoresResourceType,
ext_ctrl.ResourceTypeName,
gtwy_ctrl.ResourceTypeName,
cntr_ctrl.ResourceTypeName,
sstr_ctrl.ResourceTypeName,
}
)

// ListResourcesOfType lists all resources of a given type in the configured scope.
func (amc *UCPApplicationsManagementClient) ListResourcesOfType(ctx context.Context, resourceType string) ([]generated.GenericResource, error) {
client, err := amc.createGenericClient(amc.RootScope, resourceType)
Expand Down Expand Up @@ -141,45 +119,6 @@ func (amc *UCPApplicationsManagementClient) ListResourcesOfTypeInEnvironment(ctx
return results, nil
}

// ListResourcesInApplication lists all resources in a given application in the configured scope.
func (amc *UCPApplicationsManagementClient) ListResourcesInApplication(ctx context.Context, applicationNameOrID string) ([]generated.GenericResource, error) {
applicationID, err := amc.fullyQualifyID(applicationNameOrID, "Applications.Core/applications")
if err != nil {
return nil, err
}

results := []generated.GenericResource{}
for _, resourceType := range ResourceTypesList {
resources, err := amc.ListResourcesOfTypeInApplication(ctx, applicationID, resourceType)
if err != nil {
return nil, err
}

results = append(results, resources...)
}

return results, nil
}

// ListResourcesInEnvironment lists all resources in a given environment in the configured scope.
func (amc *UCPApplicationsManagementClient) ListResourcesInEnvironment(ctx context.Context, environmentNameOrID string) ([]generated.GenericResource, error) {
environmentID, err := amc.fullyQualifyID(environmentNameOrID, "Applications.Core/environments")
if err != nil {
return nil, err
}

results := []generated.GenericResource{}
for _, resourceType := range ResourceTypesList {
resources, err := amc.ListResourcesOfTypeInEnvironment(ctx, environmentID, resourceType)
if err != nil {
return nil, err
}
results = append(results, resources...)
}

return results, nil
}

// GetResource retrieves a resource by its type and name (or id).
func (amc *UCPApplicationsManagementClient) GetResource(ctx context.Context, resourceType string, resourceNameOrID string) (generated.GenericResource, error) {
scope, name, err := amc.extractScopeAndName(resourceNameOrID)
Expand Down Expand Up @@ -685,7 +624,7 @@ func (amc *UCPApplicationsManagementClient) DeleteResourceGroup(ctx context.Cont
return response.StatusCode != 204, nil
}

// ListResourceProviders lists all resource providers in the configured scope.
// ListResourceProviders lists all resource providers in the configured plane.
func (amc *UCPApplicationsManagementClient) ListResourceProviders(ctx context.Context, planeName string) ([]ucpv20231001.ResourceProviderResource, error) {
client, err := amc.createResourceProviderClient()
if err != nil {
Expand Down Expand Up @@ -804,7 +743,86 @@ func (amc *UCPApplicationsManagementClient) GetResourceProviderSummary(ctx conte
return response.ResourceProviderSummary, nil
}

// CreateOrUpdateResourceType creates or updates a resource type in the configured scope.
// ListAllResourceTypesNames lists the names of all resource types in all resource providers in the configured plane.
func (amc *UCPApplicationsManagementClient) ListAllResourceTypesNames(ctx context.Context, planeName string) ([]string, error) {
// excludedResourceTypesList is a list of resource types that should be excluded from the list of application resources
// to be displayed to the user.
// Lowercase is used to avoid case sensitivity issues.
excludedResourceTypesList := []string{
"microsoft.resources/deployments",
"applications.core/applications",
"applications.core/environments",
}

resourceProviderSummaries, err := amc.ListResourceProviderSummaries(ctx, planeName)
if err != nil {
return nil, fmt.Errorf("failed to list resource provider summaries: %v", err)
}

resourceTypeNames := []string{}
for _, resourceProvider := range resourceProviderSummaries {
resourceProviderName := *resourceProvider.Name
for typeName, _ := range resourceProvider.ResourceTypes {
fullResourceName := resourceProviderName + "/" + typeName
if !slices.Contains(excludedResourceTypesList, strings.ToLower(fullResourceName)) {
resourceTypeNames = append(resourceTypeNames, fullResourceName)
}
}
}

return resourceTypeNames, nil
}

// ListResourcesInApplication lists all resources in a given application in the configured scope.
func (amc *UCPApplicationsManagementClient) ListResourcesInApplication(ctx context.Context, applicationNameOrID string) ([]generated.GenericResource, error) {
applicationID, err := amc.fullyQualifyID(applicationNameOrID, "Applications.Core/applications")
if err != nil {
return nil, err
}

resourceTypesList, err := amc.ListAllResourceTypesNames(ctx, "local")
if err != nil {
return nil, err
}

results := []generated.GenericResource{}
for _, resourceType := range resourceTypesList {
resources, err := amc.ListResourcesOfTypeInApplication(ctx, applicationID, resourceType)
if err != nil {
return nil, err
}

results = append(results, resources...)
}

return results, nil
}

// ListResourcesInEnvironment lists all resources in a given environment in the configured scope.
func (amc *UCPApplicationsManagementClient) ListResourcesInEnvironment(ctx context.Context, environmentNameOrID string) ([]generated.GenericResource, error) {
environmentID, err := amc.fullyQualifyID(environmentNameOrID, "Applications.Core/environments")
if err != nil {
return nil, err
}

results := []generated.GenericResource{}
resourceTypesList, err := amc.ListAllResourceTypesNames(ctx, "local")
if err != nil {
return nil, err
}

for _, resourceType := range resourceTypesList {
resources, err := amc.ListResourcesOfTypeInEnvironment(ctx, environmentID, resourceType)
if err != nil {
return nil, err
}
results = append(results, resources...)
}

return results, nil
}

// CreateOrUpdateResourceType creates or updates a resource type in the configured plane.
func (amc *UCPApplicationsManagementClient) CreateOrUpdateResourceType(ctx context.Context, planeName string, resourceProviderName string, resourceTypeName string, resource *ucpv20231001.ResourceTypeResource) (ucpv20231001.ResourceTypeResource, error) {
client, err := amc.createResourceTypeClient()
if err != nil {
Expand All @@ -824,7 +842,7 @@ func (amc *UCPApplicationsManagementClient) CreateOrUpdateResourceType(ctx conte
return response.ResourceTypeResource, nil
}

// DeleteResourceType deletes a resource type in the configured scope.
// DeleteResourceType deletes a resource type in the configured plane.
func (amc *UCPApplicationsManagementClient) DeleteResourceType(ctx context.Context, planeName string, resourceProviderName string, resourceTypeName string) (bool, error) {
client, err := amc.createResourceTypeClient()
if err != nil {
Expand Down
Loading

0 comments on commit d0246d7

Please sign in to comment.