Skip to content

Commit

Permalink
still draft
Browse files Browse the repository at this point in the history
Signed-off-by: lakshmimsft <[email protected]>
  • Loading branch information
lakshmimsft committed Dec 16, 2024
1 parent 1e20af2 commit 15bf5c0
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 630 deletions.
61 changes: 9 additions & 52 deletions pkg/cli/cmd/resourceprovider/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,16 @@ package create
import (
"context"

v1 "github.com/radius-project/radius/pkg/armrpc/api/v1"
"github.com/radius-project/radius/pkg/cli"
"github.com/radius-project/radius/pkg/cli/cmd"
"github.com/radius-project/radius/pkg/cli/cmd/commonflags"
"github.com/radius-project/radius/pkg/cli/cmd/resourceprovider/common"
"github.com/radius-project/radius/pkg/cli/connections"
"github.com/radius-project/radius/pkg/cli/framework"
"github.com/radius-project/radius/pkg/cli/manifest"
"github.com/radius-project/radius/pkg/cli/output"
"github.com/radius-project/radius/pkg/cli/workspaces"
"github.com/radius-project/radius/pkg/to"
"github.com/radius-project/radius/pkg/ucp/api/v20231001preview"
"github.com/radius-project/radius/pkg/ucp/ucpclient"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -114,65 +113,23 @@ func (r *Runner) Validate(cmd *cobra.Command, args []string) error {

// Run runs the `rad resource-provider create` command.
func (r *Runner) Run(ctx context.Context) error {
client, err := r.ConnectionFactory.CreateApplicationsManagementClient(ctx, *r.Workspace)

connection, err := cmd.GetConnection(ctx, r.Workspace)
if err != nil {
return err
}

r.Output.LogInfo("Creating resource provider %s", r.ResourceProvider.Name)
_, err = client.CreateOrUpdateResourceProvider(ctx, "local", r.ResourceProvider.Name, &v20231001preview.ResourceProviderResource{
Location: to.Ptr(v1.LocationGlobal),
Properties: &v20231001preview.ResourceProviderProperties{},
})
ucpclient, err := ucpclient.NewUCPClient(connection)
if err != nil {
return err
}

// The location resource contains references to all of the resource types and API versions that the resource provider supports.
// We're instantiating the struct here so we can update it as we loop.
locationResource := v20231001preview.LocationResource{
Properties: &v20231001preview.LocationProperties{
ResourceTypes: map[string]*v20231001preview.LocationResourceType{},
},
}

for resourceTypeName, resourceType := range r.ResourceProvider.Types {
r.Output.LogInfo("Creating resource type %s/%s", r.ResourceProvider.Name, resourceTypeName)
_, err := client.CreateOrUpdateResourceType(ctx, "local", r.ResourceProvider.Name, resourceTypeName, &v20231001preview.ResourceTypeResource{
Properties: &v20231001preview.ResourceTypeProperties{
DefaultAPIVersion: resourceType.DefaultAPIVersion,
},
})
if err != nil {
return err
}

locationResourceType := &v20231001preview.LocationResourceType{
APIVersions: map[string]map[string]any{},
}

for apiVersionName := range resourceType.APIVersions {
r.Output.LogInfo("Creating API Version %s/%s@%s", r.ResourceProvider.Name, resourceTypeName, apiVersionName)
_, err := client.CreateOrUpdateAPIVersion(ctx, "local", r.ResourceProvider.Name, resourceTypeName, apiVersionName, &v20231001preview.APIVersionResource{
Properties: &v20231001preview.APIVersionProperties{},
})
if err != nil {
return err
}

locationResourceType.APIVersions[apiVersionName] = map[string]any{}
}

locationResource.Properties.ResourceTypes[resourceTypeName] = locationResourceType
}

r.Output.LogInfo("Creating location %s/%s", r.ResourceProvider.Name, v1.LocationGlobal)
_, err = client.CreateOrUpdateLocation(ctx, "local", r.ResourceProvider.Name, v1.LocationGlobal, &locationResource)
if err != nil {
return err
// Proceed with registering manifests
if err := ucpclient.RegisterManifests(ctx, r.ResourceProviderManifestFilePath); err != nil {
return nil
}

response, err := client.GetResourceProvider(ctx, "local", r.ResourceProvider.Name)
response, err := ucpclient.GetResourceProvider(ctx, "local", r.ResourceProvider.Name)
if err != nil {
return err
}
Expand Down
20 changes: 20 additions & 0 deletions pkg/cli/cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ package cmd

import (
"context"
"errors"
"fmt"

"github.com/radius-project/radius/pkg/cli/aws"
"github.com/radius-project/radius/pkg/cli/azure"
"github.com/radius-project/radius/pkg/cli/clients"
"github.com/radius-project/radius/pkg/cli/clierrors"
"github.com/radius-project/radius/pkg/cli/workspaces"
corerp "github.com/radius-project/radius/pkg/corerp/api/v20231001preview"
"github.com/radius-project/radius/pkg/sdk"
"github.com/radius-project/radius/pkg/to"
)

Expand Down Expand Up @@ -94,3 +97,20 @@ func CheckIfRecipeExists(ctx context.Context, client clients.ApplicationsManagem

return envResource, recipeProperties, nil
}

// GetConnection from Workspace.
func GetConnection(ctx context.Context, workspace *workspaces.Workspace) (sdk.Connection, error) {
connection, err := workspace.Connect()
if err != nil {
return nil, err
}

err = sdk.TestConnection(ctx, connection)
if errors.Is(err, &sdk.ErrRadiusNotInstalled{}) {
return nil, clierrors.MessageWithCause(err, "Could not connect to Radius.")
} else if err != nil {
return nil, err
}

return connection, nil
}
149 changes: 0 additions & 149 deletions pkg/ucp/api/v20231001preview/locations_fake_test.go

This file was deleted.

Loading

0 comments on commit 15bf5c0

Please sign in to comment.