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

Merged
merged 37 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
fca5327
cleanup #1
nithyatsu Jan 21, 2025
f9c00bc
wip
nithyatsu Jan 22, 2025
96022f4
cleanup tests
nithyatsu Jan 23, 2025
d168be9
fix tests
nithyatsu Jan 23, 2025
82e6fa5
fix mocks
nithyatsu Jan 24, 2025
ce3f0b5
fix show tests
nithyatsu Jan 24, 2025
0405bd4
fix test to not depend on order of list of resources
nithyatsu Jan 24, 2025
125e977
wip
nithyatsu Jan 24, 2025
9d02fca
wip
nithyatsu Jan 24, 2025
bae2603
wip
nithyatsu Jan 24, 2025
a4e31b6
refactor
nithyatsu Jan 24, 2025
90476a1
wip
nithyatsu Jan 24, 2025
fc95b34
lint fix
nithyatsu Jan 24, 2025
4b003d8
edit UI texts to show fully qualified resource names
nithyatsu Jan 24, 2025
07ebde6
revert launch.json
nithyatsu Jan 24, 2025
b9ae158
wip
nithyatsu Jan 24, 2025
1f02561
nit
nithyatsu Jan 24, 2025
b7d1165
review comments
nithyatsu Jan 29, 2025
ad8998e
wip
nithyatsu Jan 29, 2025
c267f01
wip
nithyatsu Jan 30, 2025
70ea583
renaming nits
nithyatsu Jan 30, 2025
b5df7a8
add RequireFullyQualifiedResourceType function
nithyatsu Jan 30, 2025
cb61af2
refactor rad resource-type to use new clivalidations
nithyatsu Jan 30, 2025
a904352
update commands to use new functions
nithyatsu Jan 30, 2025
5853c52
add method
nithyatsu Jan 30, 2025
613ef3f
add a non existant resource type test
nithyatsu Jan 30, 2025
262cfb1
nit
nithyatsu Jan 30, 2025
5715133
wip
nithyatsu Jan 30, 2025
497b5fa
remove unused function
nithyatsu Jan 30, 2025
de72485
nit
nithyatsu Jan 31, 2025
98b53bd
wip
nithyatsu Jan 31, 2025
0ed2a55
refactors
nithyatsu Feb 6, 2025
75f7105
update scope
nithyatsu Feb 6, 2025
cd38119
nit
nithyatsu Feb 7, 2025
063f88c
add comment
nithyatsu Feb 7, 2025
370c181
nits
nithyatsu Feb 11, 2025
860efd6
refactor
nithyatsu Feb 11, 2025
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
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
Loading