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

remove hardcoded list of resource types from cli. #8286

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
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
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
3 changes: 3 additions & 0 deletions pkg/cli/clients/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ type ApplicationsManagementClient interface {
// DeleteResourceType deletes a resource type in the configured scope.
DeleteResourceType(ctx context.Context, planeName string, providerNamespace string, resourceTypeName string) (bool, error)

// ListAllResourceTypesNames lists the names of all resource types in the configured scope.
ListAllResourceTypesNames(ctx context.Context, planeName string) ([]string, error)
nithyatsu marked this conversation as resolved.
Show resolved Hide resolved

// 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
138 changes: 78 additions & 60 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,20 +52,13 @@ type UCPApplicationsManagementClient struct {

var _ ApplicationsManagementClient = (*UCPApplicationsManagementClient)(nil)

// ExcludedResourceTypesList is a list of resource types that should be excluded from the list of application resources
// to be displayed to the user.
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,
ExcludedResourceTypesList = []string{
"Microsoft.Resources/deployments",
"Applications.Core/applications",
"Applications.Core/environments",
}
)

Expand Down Expand Up @@ -141,45 +129,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 +634,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.
nithyatsu marked this conversation as resolved.
Show resolved Hide resolved
func (amc *UCPApplicationsManagementClient) ListResourceProviders(ctx context.Context, planeName string) ([]ucpv20231001.ResourceProviderResource, error) {
client, err := amc.createResourceProviderClient()
if err != nil {
Expand Down Expand Up @@ -804,6 +753,75 @@ func (amc *UCPApplicationsManagementClient) GetResourceProviderSummary(ctx conte
return response.ResourceProviderSummary, nil
}

// ListAllResourceTypesNames lists all resource types in all resource providers in the configured scope.
func (amc *UCPApplicationsManagementClient) ListAllResourceTypesNames(ctx context.Context, planeName string) ([]string, error) {
nithyatsu marked this conversation as resolved.
Show resolved Hide resolved
nithyatsu marked this conversation as resolved.
Show resolved Hide resolved
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, 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 scope.
func (amc *UCPApplicationsManagementClient) CreateOrUpdateResourceType(ctx context.Context, planeName string, resourceProviderName string, resourceTypeName string, resource *ucpv20231001.ResourceTypeResource) (ucpv20231001.ResourceTypeResource, error) {
client, err := amc.createResourceTypeClient()
Expand Down
Loading
Loading