diff --git a/pkg/cli/cmd/resourceprovider/create/create.go b/pkg/cli/cmd/resourceprovider/create/create.go index b5c55b775f..771a409af3 100644 --- a/pkg/cli/cmd/resourceprovider/create/create.go +++ b/pkg/cli/cmd/resourceprovider/create/create.go @@ -19,8 +19,8 @@ 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" @@ -28,8 +28,7 @@ import ( "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" ) @@ -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 } diff --git a/pkg/cli/cmd/utils.go b/pkg/cli/cmd/utils.go index e13b1243a2..58541acd4f 100644 --- a/pkg/cli/cmd/utils.go +++ b/pkg/cli/cmd/utils.go @@ -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" ) @@ -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 +} diff --git a/pkg/ucp/api/v20231001preview/locations_fake_test.go b/pkg/ucp/api/v20231001preview/locations_fake_test.go deleted file mode 100644 index df5426505c..0000000000 --- a/pkg/ucp/api/v20231001preview/locations_fake_test.go +++ /dev/null @@ -1,149 +0,0 @@ -package v20231001preview_test - -import ( - "context" - "net/http" - "testing" - - armpolicy "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/policy" - azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" - "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" - "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" - "github.com/stretchr/testify/require" - - v20231001preview "github.com/radius-project/radius/pkg/ucp/api/v20231001preview" - "github.com/radius-project/radius/pkg/ucp/api/v20231001preview/fake" -) - -func TestLocationsServer(t *testing.T) { - // Initialize the fake LocationsServer with method implementations. - srv := &fake.LocationsServer{ - BeginCreateOrUpdate: func( - ctx context.Context, - planeName string, - resourceProviderName string, - locationName string, - resource v20231001preview.LocationResource, - options *v20231001preview.LocationsClientBeginCreateOrUpdateOptions, - ) (resp azfake.PollerResponder[v20231001preview.LocationsClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) { - // Create the response object. - result := v20231001preview.LocationsClientCreateOrUpdateResponse{ - LocationResource: resource, - } - - // Create a PollerResponder to simulate a long-running operation (LRO). - resp.AddNonTerminalResponse(http.StatusCreated, nil) - resp.SetTerminalResponse(http.StatusOK, result, nil) - - return - }, - Get: func( - ctx context.Context, - planeName string, - resourceProviderName string, - locationName string, - options *v20231001preview.LocationsClientGetOptions, - ) (resp azfake.Responder[v20231001preview.LocationsClientGetResponse], errResp azfake.ErrorResponder) { - response := v20231001preview.LocationsClientGetResponse{ - LocationResource: v20231001preview.LocationResource{ - Name: to.Ptr(locationName), - }, - } - resp.SetResponse(http.StatusOK, response, nil) - return - }, - BeginDelete: func( - ctx context.Context, - planeName string, - resourceProviderName string, - locationName string, - options *v20231001preview.LocationsClientBeginDeleteOptions, - ) (resp azfake.PollerResponder[v20231001preview.LocationsClientDeleteResponse], errResp azfake.ErrorResponder) { - // Create the response object. - result := v20231001preview.LocationsClientDeleteResponse{} - - resp.AddNonTerminalResponse(http.StatusNoContent, nil) - resp.SetTerminalResponse(http.StatusOK, result, nil) - return - }, - NewListPager: func( - planeName string, - resourceProviderName string, - options *v20231001preview.LocationsClientListOptions, - ) (resp azfake.PagerResponder[v20231001preview.LocationsClientListResponse]) { - // Simulate paging with two pages of results. - page1 := v20231001preview.LocationsClientListResponse{ - LocationResourceListResult: v20231001preview.LocationResourceListResult{ - Value: []*v20231001preview.LocationResource{ - {Name: to.Ptr("location1")}, - {Name: to.Ptr("location2")}, - }, - NextLink: to.Ptr("nextPageLink"), - }, - } - page2 := v20231001preview.LocationsClientListResponse{ - LocationResourceListResult: v20231001preview.LocationResourceListResult{ - Value: []*v20231001preview.LocationResource{ - {Name: to.Ptr("location3")}, - }, - }, - } - resp.AddPage(http.StatusOK, page1, nil) - resp.AddPage(http.StatusOK, page2, nil) - return - }, - } - - // Create a fake transport using the LocationsServer. - transport := fake.NewLocationsServerTransport(srv) - - // Set up client options with the fake transport. - clientOptions := &armpolicy.ClientOptions{ - ClientOptions: policy.ClientOptions{ - Transport: transport, - }, - } - - // Create the LocationsClient with the fake transport and mock credential. - client, err := v20231001preview.NewLocationsClient(&azfake.TokenCredential{}, clientOptions) - require.NoError(t, err) - - ctx := context.Background() - planeName := "testPlane" - resourceProviderName := "testResourceProvider" - locationName := "testLocation" - resource := v20231001preview.LocationResource{ - Name: to.Ptr(locationName), - } - - // Call BeginCreateOrUpdate and poll until completion. - pollerResp, err := client.BeginCreateOrUpdate(ctx, planeName, resourceProviderName, locationName, resource, nil) - require.NoError(t, err) - finalResp, err := pollerResp.PollUntilDone(ctx, nil) - require.NoError(t, err) - require.Equal(t, locationName, *finalResp.Name) - - // Call Get. - getResp, err := client.Get(ctx, planeName, resourceProviderName, locationName, nil) - require.NoError(t, err) - require.Equal(t, locationName, *getResp.Name) - - // Call BeginDelete and poll until completion. - deletePollerResp, err := client.BeginDelete(ctx, planeName, resourceProviderName, locationName, nil) - require.NoError(t, err) - _, err = deletePollerResp.PollUntilDone(ctx, nil) - require.NoError(t, err) - - // Call NewListPager. - pager := client.NewListPager(planeName, resourceProviderName, nil) - var locations []*v20231001preview.LocationResource - for pager.More() { - page, err := pager.NextPage(ctx) - require.NoError(t, err) - locations = append(locations, page.Value...) - } - require.Len(t, locations, 3) - require.Equal(t, "location1", *locations[0].Name) - require.Equal(t, "location2", *locations[1].Name) - require.Equal(t, "location3", *locations[2].Name) -} diff --git a/pkg/ucp/api/v20231001preview/resourceproviders_fakes_test.go b/pkg/ucp/api/v20231001preview/resourceproviders_fakes_test.go deleted file mode 100644 index 3cc5f0d063..0000000000 --- a/pkg/ucp/api/v20231001preview/resourceproviders_fakes_test.go +++ /dev/null @@ -1,159 +0,0 @@ -package v20231001preview_test - -import ( - "context" - "net/http" - "testing" - - armpolicy "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/policy" - azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" - "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" - "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" - "github.com/stretchr/testify/require" - - v20231001preview "github.com/radius-project/radius/pkg/ucp/api/v20231001preview" - "github.com/radius-project/radius/pkg/ucp/api/v20231001preview/fake" -) - -func TestResourceProvidersServer(t *testing.T) { - // Initialize the fake ResourceProvidersServer with method implementations. - srv := &fake.ResourceProvidersServer{ - BeginCreateOrUpdate: func( - ctx context.Context, - planeName string, - resourceProviderName string, - resource v20231001preview.ResourceProviderResource, - options *v20231001preview.ResourceProvidersClientBeginCreateOrUpdateOptions, - ) (resp azfake.PollerResponder[v20231001preview.ResourceProvidersClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) { - result := v20231001preview.ResourceProvidersClientCreateOrUpdateResponse{ - ResourceProviderResource: resource, - } - - // resp.AddNonTerminalResponse(http.StatusCreated, nil) - resp.SetTerminalResponse(http.StatusOK, result, nil) - - return - }, - Get: func( - ctx context.Context, - planeName string, - resourceProviderName string, - options *v20231001preview.ResourceProvidersClientGetOptions, - ) (resp azfake.Responder[v20231001preview.ResourceProvidersClientGetResponse], errResp azfake.ErrorResponder) { - response := v20231001preview.ResourceProvidersClientGetResponse{ - ResourceProviderResource: v20231001preview.ResourceProviderResource{ - Name: to.Ptr(resourceProviderName), - }, - } - resp.SetResponse(http.StatusOK, response, nil) - return - }, - BeginDelete: func( - ctx context.Context, - planeName string, - resourceProviderName string, - options *v20231001preview.ResourceProvidersClientBeginDeleteOptions, - ) (resp azfake.PollerResponder[v20231001preview.ResourceProvidersClientDeleteResponse], errResp azfake.ErrorResponder) { - // Simulate a delete operation with a final response. - result := v20231001preview.ResourceProvidersClientDeleteResponse{} - - // resp.AddNonTerminalResponse(http.StatusCreated, nil) - resp.SetTerminalResponse(http.StatusOK, result, nil) - return - }, - // Updated NewListPager method - NewListPager: func( - planeName string, - options *v20231001preview.ResourceProvidersClientListOptions, - ) (resp azfake.PagerResponder[v20231001preview.ResourceProvidersClientListResponse]) { - // Simulate paging with two pages of results. - page1 := v20231001preview.ResourceProvidersClientListResponse{ - ResourceProviderResourceListResult: v20231001preview.ResourceProviderResourceListResult{ - Value: []*v20231001preview.ResourceProviderResource{ - {Name: to.Ptr("resourceProvider1")}, - {Name: to.Ptr("resourceProvider2")}, - }, - NextLink: to.Ptr("nextPageLink"), - }, - } - page2 := v20231001preview.ResourceProvidersClientListResponse{ - ResourceProviderResourceListResult: v20231001preview.ResourceProviderResourceListResult{ - Value: []*v20231001preview.ResourceProviderResource{ - {Name: to.Ptr("resourceProvider3")}, - }, - }, - } - resp.AddPage(http.StatusOK, page1, nil) - resp.AddPage(http.StatusOK, page2, nil) - return - }, - GetProviderSummary: func( - ctx context.Context, - planeName string, - resourceProviderName string, - options *v20231001preview.ResourceProvidersClientGetProviderSummaryOptions, - ) (resp azfake.Responder[v20231001preview.ResourceProvidersClientGetProviderSummaryResponse], errResp azfake.ErrorResponder) { - response := v20231001preview.ResourceProvidersClientGetProviderSummaryResponse{ - ResourceProviderSummary: v20231001preview.ResourceProviderSummary{ - Name: to.Ptr(resourceProviderName), - }, - } - resp.SetResponse(http.StatusOK, response, nil) - return - }, - } - - // Create a fake transport using the ResourceProvidersServer. - transport := fake.NewResourceProvidersServerTransport(srv) - clientOptions := &armpolicy.ClientOptions{ClientOptions: policy.ClientOptions{ - Transport: transport, - }} - - // Create the ResourceProvidersClient with the fake transport. - client, err := v20231001preview.NewResourceProvidersClient(&azfake.TokenCredential{}, clientOptions) - require.NoError(t, err) - - ctx := context.Background() - planeName := "local" - resourceProviderName := "testResourceProvider" - resource := v20231001preview.ResourceProviderResource{ - Name: to.Ptr(resourceProviderName), - } - - // Call BeginCreateOrUpdate and poll until completion. - pollerResp, err := client.BeginCreateOrUpdate(ctx, planeName, resourceProviderName, resource, nil) - require.NoError(t, err) - _, err = pollerResp.PollUntilDone(ctx, nil) - require.NoError(t, err) - - // Call Get. - getResp, err := client.Get(ctx, planeName, resourceProviderName, nil) - require.NoError(t, err) - require.Equal(t, resourceProviderName, *getResp.Name) - - // Call BeginDelete and poll until completion. - deletePollerResp, err := client.BeginDelete(ctx, planeName, resourceProviderName, nil) - require.NoError(t, err) - _, err = deletePollerResp.PollUntilDone(ctx, nil) - require.NoError(t, err) - - // Call NewListPager. - pager := client.NewListPager(planeName, nil) - var resources []*v20231001preview.ResourceProviderResource - - for pager.More() { - page, err := pager.NextPage(ctx) - require.NoError(t, err) - resources = append(resources, page.Value...) - } - - require.Len(t, resources, 3) - require.Equal(t, "resourceProvider1", *resources[0].Name) - require.Equal(t, "resourceProvider2", *resources[1].Name) - require.Equal(t, "resourceProvider3", *resources[2].Name) - - // Call GetProviderSummary. - summaryResp, err := client.GetProviderSummary(ctx, planeName, resourceProviderName, nil) - require.NoError(t, err) - require.Equal(t, resourceProviderName, *summaryResp.Name) -} diff --git a/pkg/ucp/api/v20231001preview/resourcetypes_fake_test.go b/pkg/ucp/api/v20231001preview/resourcetypes_fake_test.go deleted file mode 100644 index ff69d41eae..0000000000 --- a/pkg/ucp/api/v20231001preview/resourcetypes_fake_test.go +++ /dev/null @@ -1,148 +0,0 @@ -package v20231001preview_test - -import ( - "context" - "net/http" - "testing" - - armpolicy "github.com/Azure/azure-sdk-for-go/sdk/azcore/arm/policy" - azfake "github.com/Azure/azure-sdk-for-go/sdk/azcore/fake" - "github.com/Azure/azure-sdk-for-go/sdk/azcore/policy" - "github.com/Azure/azure-sdk-for-go/sdk/azcore/to" - "github.com/stretchr/testify/require" - - v20231001preview "github.com/radius-project/radius/pkg/ucp/api/v20231001preview" - "github.com/radius-project/radius/pkg/ucp/api/v20231001preview/fake" -) - -func TestResourceTypesServer(t *testing.T) { - // Initialize the fake ResourceTypesServer with method implementations. - srv := &fake.ResourceTypesServer{ - BeginCreateOrUpdate: func( - ctx context.Context, - planeName string, - resourceProviderName string, - resourceTypeName string, - resource v20231001preview.ResourceTypeResource, - options *v20231001preview.ResourceTypesClientBeginCreateOrUpdateOptions, - ) (resp azfake.PollerResponder[v20231001preview.ResourceTypesClientCreateOrUpdateResponse], errResp azfake.ErrorResponder) { - result := v20231001preview.ResourceTypesClientCreateOrUpdateResponse{ - ResourceTypeResource: resource, - } - - // Create a PollerResponder to simulate a long-running operation (LRO) - resp.SetTerminalResponse(http.StatusOK, result, nil) - - return - }, - Get: func( - ctx context.Context, - planeName string, - resourceProviderName string, - resourceTypeName string, - options *v20231001preview.ResourceTypesClientGetOptions, - ) (resp azfake.Responder[v20231001preview.ResourceTypesClientGetResponse], errResp azfake.ErrorResponder) { - response := v20231001preview.ResourceTypesClientGetResponse{ - ResourceTypeResource: v20231001preview.ResourceTypeResource{ - Name: to.Ptr(resourceTypeName), - }, - } - resp.SetResponse(http.StatusOK, response, nil) - return - }, - BeginDelete: func( - ctx context.Context, - planeName string, - resourceProviderName string, - resourceTypeName string, - options *v20231001preview.ResourceTypesClientBeginDeleteOptions, - ) (resp azfake.PollerResponder[v20231001preview.ResourceTypesClientDeleteResponse], errResp azfake.ErrorResponder) { - // Create the response object - result := v20231001preview.ResourceTypesClientDeleteResponse{} - // Create a PollerResponder to simulate a long-running operation (LRO) - resp.AddNonTerminalResponse(http.StatusAccepted, nil) - resp.SetTerminalResponse(http.StatusNoContent, result, nil) - - return - }, - NewListPager: func( - planeName string, - resourceProviderName string, - options *v20231001preview.ResourceTypesClientListOptions, - ) (resp azfake.PagerResponder[v20231001preview.ResourceTypesClientListResponse]) { - // Simulate paging with two pages of results. - page1 := v20231001preview.ResourceTypesClientListResponse{ - ResourceTypeResourceListResult: v20231001preview.ResourceTypeResourceListResult{ - Value: []*v20231001preview.ResourceTypeResource{ - {Name: to.Ptr("resourceType1")}, - {Name: to.Ptr("resourceType2")}, - }, - NextLink: to.Ptr("nextPageLink"), - }, - } - page2 := v20231001preview.ResourceTypesClientListResponse{ - ResourceTypeResourceListResult: v20231001preview.ResourceTypeResourceListResult{ - Value: []*v20231001preview.ResourceTypeResource{ - {Name: to.Ptr("resourceType3")}, - }, - }, - } - resp.AddPage(http.StatusOK, page1, nil) - resp.AddPage(http.StatusOK, page2, nil) - return - }, - } - - // Create a fake transport using the ResourceTypesServer. - transport := fake.NewResourceTypesServerTransport(srv) - - // Set up client options with the fake transport. - clientOptions := &armpolicy.ClientOptions{ - ClientOptions: policy.ClientOptions{ - Transport: transport, - }, - } - - // Create the ResourceTypesClient with the fake transport and mock credential. - client, err := v20231001preview.NewResourceTypesClient(&azfake.TokenCredential{}, clientOptions) - require.NoError(t, err) - - ctx := context.Background() - planeName := "local" - resourceProviderName := "testResourceProvider" - resourceTypeName := "testResourceType" - resource := v20231001preview.ResourceTypeResource{ - Name: to.Ptr(resourceTypeName), - } - - // Call BeginCreateOrUpdate and poll until completion. - pollerResp, err := client.BeginCreateOrUpdate(ctx, planeName, resourceProviderName, resourceTypeName, resource, nil) - require.NoError(t, err) - finalResp, err := pollerResp.PollUntilDone(ctx, nil) - require.NoError(t, err) - require.Equal(t, resourceTypeName, *finalResp.Name) - - // Call Get. - getResp, err := client.Get(ctx, planeName, resourceProviderName, resourceTypeName, nil) - require.NoError(t, err) - require.Equal(t, resourceTypeName, *getResp.Name) - - // Call BeginDelete and poll until completion. - deletePollerResp, err := client.BeginDelete(ctx, planeName, resourceProviderName, resourceTypeName, nil) - require.NoError(t, err) - _, err = deletePollerResp.PollUntilDone(ctx, nil) - require.NoError(t, err) - - // Call NewListPager. - pager := client.NewListPager(planeName, resourceProviderName, nil) - var resources []*v20231001preview.ResourceTypeResource - for pager.More() { - page, err := pager.NextPage(ctx) - require.NoError(t, err) - resources = append(resources, page.Value...) - } - require.Len(t, resources, 3) - require.Equal(t, "resourceType1", *resources[0].Name) - require.Equal(t, "resourceType2", *resources[1].Name) - require.Equal(t, "resourceType3", *resources[2].Name) -} diff --git a/pkg/ucp/ucpclient/locations_fake_test.go b/pkg/ucp/ucpclient/locations_fake_test_notneeded.go similarity index 100% rename from pkg/ucp/ucpclient/locations_fake_test.go rename to pkg/ucp/ucpclient/locations_fake_test_notneeded.go diff --git a/pkg/ucp/ucpclient/registermanifests.go b/pkg/ucp/ucpclient/registermanifests.go index e86f60fefe..cc0b447fe5 100644 --- a/pkg/ucp/ucpclient/registermanifests.go +++ b/pkg/ucp/ucpclient/registermanifests.go @@ -83,9 +83,10 @@ func (u *UCPClient) RegisterManifests(ctx context.Context, manifestDirectory str // Iterate over each file in the directory for _, fileInfo := range files { if fileInfo.IsDir() { - continue // Skip directories - check if want to include subdirectories + continue // Skip directories - TBD: check if want to include subdirectories } filePath := filepath.Join(manifestDirectory, fileInfo.Name()) + // Read the manifest file resourceProvider, err := manifest.ReadFile(filePath) if err != nil { diff --git a/pkg/ucp/ucpclient/registermanifests_test.go b/pkg/ucp/ucpclient/registermanifests_test.go index d27a23a754..ab4beb540a 100644 --- a/pkg/ucp/ucpclient/registermanifests_test.go +++ b/pkg/ucp/ucpclient/registermanifests_test.go @@ -9,52 +9,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -package ucpclient - -/* -import ( - "context" - "testing" - - "github.com/radius-project/radius/pkg/ucp/hostoptions" - "github.com/radius-project/radius/pkg/ucp/server" - "github.com/stretchr/testify/require" -) - -func TestRegisterManifests(t *testing.T) { - ctx := context.Background() - - // Setup temporary manifest directory and files - manifestDir := "testdata" - - // Create sample manifest files in manifestDir - // ... - options := &server.Options{ - Config: &hostoptions.UCPConfig{ - Manifests: hostoptions.ManifestConfig{ - ManifestDirectory: manifestDir, - }, - }, - } - - // Setup fake UCP client with fake servers - fakeUCPClient, err := NewFakeUCPClient() - require.NoError(t, err) - - -} -*/ -/* -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ +package ucpclient import ( "context" @@ -79,20 +35,6 @@ type FakeUCPServer struct { LocationsServer *ucpfake.LocationsServer } -/* -type MultiTransport struct { - transports map[string]http.RoundTripper -} - -func (mt *MultiTransport) RoundTrip(req *http.Request) (*http.Response, error) { - for prefix, transport := range mt.transports { - if strings.HasPrefix(req.URL.Path, prefix) { - return transport.RoundTrip(req) - } - } - return nil, fmt.Errorf("no transport found for request path: %s", req.URL.Path) -}*/ - func NewFakeUCPServer() (*FakeUCPServer, error) { // Create fake servers for each client @@ -229,42 +171,6 @@ func NewTestUCPClient(server *FakeUCPServer) (*UCPClient, error) { apiVersionsTransport := ucpfake.NewAPIVersionsServerTransport(server.APIVersionsServer) locationsTransport := ucpfake.NewLocationsServerTransport(server.LocationsServer) - /* - // Create the ServerFactory - serverFactory := &ucpfake.ServerFactory{} - - // Register your fake servers with the ServerFactory - serverFactory.ResourceProvidersServer = *resourceProvidersServer - serverFactory.ResourceTypesServer = *resourceTypesServer - serverFactory.APIVersionsServer = *apiVersionsServer - serverFactory.LocationsServer = *locationsServer - //locTransporter := ucpfake.ServerFactoryTransport(locationsServer) - - serverFactoryTransport := ucpfake.NewServerFactoryTransport(serverFactory) - */ - - //clientOptions := &policy.ClientOptions{Transport: serverFactoryTransport} - - // Assuming you have a UCPConnection or can use a fake one for testing - //ucpConnection, err := sdk.NewDirectConnection("") // Replace with a valid implementation - /* - // Create the server.Options instance - serverOptions := &server.Options{ - UCPConnection: ucpConnection, - } - - httpClient:= http.Client{ - Transport: serverFactoryTransport, - } - - ucpConnection.Client() = httpClient - */ - // Instantiate UCPClientImpl with the unified ClientOptions - //ucpClient, err := NewUCPClient(ucpConnection) - /*if err != nil { - return nil, fmt.Errorf("failed to create UCP client: %w", err) - }*/ - // Configure client options with respective transports resourceProvidersOptions := &armpolicy.ClientOptions{ ClientOptions: policy.ClientOptions{ diff --git a/pkg/ucp/ucpclient/resourceproviders_fakes_test.go b/pkg/ucp/ucpclient/resourceproviders_fakes_test_notneeded.go similarity index 100% rename from pkg/ucp/ucpclient/resourceproviders_fakes_test.go rename to pkg/ucp/ucpclient/resourceproviders_fakes_test_notneeded.go diff --git a/pkg/ucp/ucpclient/resourcetypes_fake_test.go b/pkg/ucp/ucpclient/resourcetypes_fake_test_notneeded.go similarity index 100% rename from pkg/ucp/ucpclient/resourcetypes_fake_test.go rename to pkg/ucp/ucpclient/resourcetypes_fake_test_notneeded.go diff --git a/pkg/ucp/ucpclient/ucpclient.go b/pkg/ucp/ucpclient/ucpclient.go index 03de4be03e..0e1efa2e8d 100644 --- a/pkg/ucp/ucpclient/ucpclient.go +++ b/pkg/ucp/ucpclient/ucpclient.go @@ -18,30 +18,6 @@ import ( ucpv20231001 "github.com/radius-project/radius/pkg/ucp/api/v20231001preview" ) -/* -// UCPClient is a client for interacting with the UCP API. -type UCPClient interface { - // CreateOrUpdateResourceProvider creates or updates a resource provider in the configured scope. - CreateOrUpdateResourceProvider(ctx context.Context, planeName string, providerNamespace string, resource *ucpv20231001.ResourceProviderResource) (ucpv20231001.ResourceProviderResource, error) - - // CreateOrUpdateResourceType creates or updates a resource type in the configured scope. - GetResourceProvider(ctx context.Context, planeName string, resourceProviderName string) (ucpv20231001.ResourceProviderResource, error) - - // CreateOrUpdateResourceType creates or updates a resource type in the configured scope. - CreateOrUpdateResourceType(ctx context.Context, planeName string, providerNamespace string, resourceTypeName string, resource *ucpv20231001.ResourceTypeResource) (ucpv20231001.ResourceTypeResource, error) - - // CreateOrUpdateAPIVersion creates or updates an API version in the configured scope. - CreateOrUpdateAPIVersion(ctx context.Context, planeName string, resourceProviderName string, resourceTypeName string, apiVersionName string, resource *ucpv20231001.APIVersionResource) (ucpv20231001.APIVersionResource, error) - - // CreateOrUpdateLocation creates or updates a resource provider location in the configured scope. - CreateOrUpdateLocation(ctx context.Context, planeName string, resourceProviderName string, locationName string, resource *ucpv20231001.LocationResource) (ucpv20231001.LocationResource, error) - - RegisterManifests(ctx context.Context) error - - // ... Add other methods as needed ... -} -*/ - const planeName = "local" // UCPClient holds instances of each specific client. @@ -53,8 +29,6 @@ type UCPClient struct { // Add other clients as needed } -//var _ UCPClient = (*UCPClientFactory)(nil) - // CreateOrUpdateResourceProvider creates or updates a resource provider in the configured scope. func (u *UCPClient) CreateOrUpdateResourceProvider(ctx context.Context, planeName string, resourceProviderName string, resource *ucpv20231001.ResourceProviderResource) (ucpv20231001.ResourceProviderResource, error) { if u.ResourceProvidersClient == nil {