From 07f18036ee4eb1b1fdc1857dc9b772d0c2dd95bf Mon Sep 17 00:00:00 2001 From: lakshmimsft Date: Fri, 10 Jan 2025 00:35:28 -0800 Subject: [PATCH] enable register manifest Signed-off-by: lakshmimsft --- build/docker.mk | 7 +++ cmd/ucpd/ucp-dev.yaml | 2 +- deploy/Chart/templates/ucp/configmaps.yaml | 2 +- deploy/images/ucpd/Dockerfile | 3 ++ .../dev/applications_core.yaml | 4 +- .../dev/applications_dapr.yaml | 4 +- .../dev/applications_datastores.yaml | 4 +- .../dev/applications_messaging.yaml | 4 +- .../dev/microsoft_resources.yaml | 4 +- .../self-hosted/applications_core.yaml | 6 +-- .../self-hosted/applications_dapr.yaml | 12 ++--- .../self-hosted/applications_datastores.yaml | 10 ++-- .../self-hosted/applications_messaging.yaml | 6 +-- .../self-hosted/microsoft_resources.yaml | 4 +- .../create/testdata/valid.yaml | 3 ++ .../resourcetype/create/testdata/valid.yaml | 4 +- pkg/cli/manifest/manifest.go | 3 ++ pkg/cli/manifest/manifest_test.go | 3 ++ pkg/cli/manifest/registermanifest.go | 50 ++++++++++++++++--- .../testdata/missing-required-field.json | 2 +- .../resourceprovider-valid1.yaml | 3 ++ .../resourceprovider-valid2.yaml | 3 ++ pkg/cli/manifest/testdata/valid.yaml | 3 ++ .../manifests/resourceprovider-valid1.yaml | 3 ++ 24 files changed, 107 insertions(+), 42 deletions(-) diff --git a/build/docker.mk b/build/docker.mk index 7adcdcaa6b..9ff0c6348a 100644 --- a/build/docker.mk +++ b/build/docker.mk @@ -17,6 +17,7 @@ DOCKER_REGISTRY?=$(shell whoami) DOCKER_TAG_VERSION?=latest IMAGE_SRC?=https://github.com/radius-project/radius +MANIFEST_DIR?=deploy/manifest/built-in-providers/self-hosted ##@ Docker Images @@ -31,6 +32,8 @@ ifeq ($(strip $(4)),go) docker-build-$(1): build-$(1)-linux-amd64 @echo "$(ARROW) Building Go image $(DOCKER_REGISTRY)/$(1):$(DOCKER_TAG_VERSION)" @cp -v $(3) $(OUT_DIR)/Dockerfile-$(1) + @mkdir -p $(OUT_DIR)/manifest/built-in-providers/ + @cp -v $(MANIFEST_DIR)/* $(OUT_DIR)/manifest/built-in-providers/ cd $(OUT_DIR) && docker build $(2) -f ./Dockerfile-$(1) \ --platform linux/amd64 \ @@ -60,6 +63,8 @@ define generateDockerMultiArches docker-multi-arch-build-$(1): build-$(1)-linux-arm64 build-$(1)-linux-amd64 build-$(1)-linux-arm @echo "$(ARROW) Building Go image $(DOCKER_REGISTRY)/$(1):$(DOCKER_TAG_VERSION)" @cp -v $(3) $(OUT_DIR)/Dockerfile-$(1) + @mkdir -p $(OUT_DIR)/manifest/built-in-providers/ + @cp -v $(MANIFEST_DIR)/* $(OUT_DIR)/manifest/built-in-providers/ cd $(OUT_DIR) && docker buildx build -f ./Dockerfile-$(1) \ --platform linux/amd64,linux/arm64,linux/arm \ @@ -74,6 +79,8 @@ docker-multi-arch-build-$(1): build-$(1)-linux-arm64 build-$(1)-linux-amd64 buil docker-multi-arch-push-$(1): build-$(1)-linux-arm64 build-$(1)-linux-amd64 build-$(1)-linux-arm @echo "$(ARROW) Building and pushing Go image $(DOCKER_REGISTRY)/$(1):$(DOCKER_TAG_VERSION)" @cp -v $(3) $(OUT_DIR)/Dockerfile-$(1) + @mkdir -p $(OUT_DIR)/manifest/built-in-providers/ + @cp -v $(MANIFEST_DIR)/* $(OUT_DIR)/manifest/built-in-providers/ # Building and pushing in one step is more efficient with buildx, so we duplicate the command # to build and add --push. diff --git a/cmd/ucpd/ucp-dev.yaml b/cmd/ucpd/ucp-dev.yaml index ddabe6bb0b..ae0da2ff5e 100644 --- a/cmd/ucpd/ucp-dev.yaml +++ b/cmd/ucpd/ucp-dev.yaml @@ -53,7 +53,7 @@ initialization: Microsoft.Resources: "http://localhost:5017" kind: "UCPNative" # This is the directory location which contains manifests to be registered. - manifestDirectory: "" + manifestDirectory: "manifest/built-in-providers/" identity: authMethod: default diff --git a/deploy/Chart/templates/ucp/configmaps.yaml b/deploy/Chart/templates/ucp/configmaps.yaml index 2047e006a8..4b29bfdb47 100644 --- a/deploy/Chart/templates/ucp/configmaps.yaml +++ b/deploy/Chart/templates/ucp/configmaps.yaml @@ -50,7 +50,7 @@ data: - id: "/planes/aws/aws" properties: kind: "AWS" - manifestDirectory: "" + manifestDirectory: "/manifest/built-in-providers" identity: authMethod: UCPCredential diff --git a/deploy/images/ucpd/Dockerfile b/deploy/images/ucpd/Dockerfile index 44ff6e5be3..b2243c39ad 100644 --- a/deploy/images/ucpd/Dockerfile +++ b/deploy/images/ucpd/Dockerfile @@ -10,6 +10,9 @@ WORKDIR / # Copy the application binary for the specified architecture COPY ./linux_${TARGETARCH:-amd64}/release/ucpd / +# Copy the manifest files for the built-in providers +COPY ./manifest/built-in-providers/ /manifest/built-in-providers/ + # Set the user to non-root (65532:65532 is the default non-root user in distroless) USER 65532:65532 diff --git a/deploy/manifest/built-in-providers/dev/applications_core.yaml b/deploy/manifest/built-in-providers/dev/applications_core.yaml index 6e8d34f65e..48fa2c996c 100644 --- a/deploy/manifest/built-in-providers/dev/applications_core.yaml +++ b/deploy/manifest/built-in-providers/dev/applications_core.yaml @@ -1,7 +1,7 @@ name: Applications.Core -locations: +location: global: - address: "http://localhost:8080" + "http://localhost:8080" types: containers: apiVersions: diff --git a/deploy/manifest/built-in-providers/dev/applications_dapr.yaml b/deploy/manifest/built-in-providers/dev/applications_dapr.yaml index 11cd13567e..57b4c9d6dc 100644 --- a/deploy/manifest/built-in-providers/dev/applications_dapr.yaml +++ b/deploy/manifest/built-in-providers/dev/applications_dapr.yaml @@ -1,7 +1,7 @@ name: Applications.Dapr -locations: +location: global: - address: "http://localhost:8080" + "http://localhost:8080" types: configurationStores: apiVersions: diff --git a/deploy/manifest/built-in-providers/dev/applications_datastores.yaml b/deploy/manifest/built-in-providers/dev/applications_datastores.yaml index 767ed81ca1..30c78a5641 100644 --- a/deploy/manifest/built-in-providers/dev/applications_datastores.yaml +++ b/deploy/manifest/built-in-providers/dev/applications_datastores.yaml @@ -1,7 +1,7 @@ name: Applications.Datastores -locations: +location: global: - address: "http://localhost:8080" + "http://localhost:8080" types: mongoDatabases: apiVersions: diff --git a/deploy/manifest/built-in-providers/dev/applications_messaging.yaml b/deploy/manifest/built-in-providers/dev/applications_messaging.yaml index 10db9242da..ba41b3a11b 100644 --- a/deploy/manifest/built-in-providers/dev/applications_messaging.yaml +++ b/deploy/manifest/built-in-providers/dev/applications_messaging.yaml @@ -1,7 +1,7 @@ name: Applications.Messaging -locations: +location: global: - address: "http://localhost:8080" + "http://localhost:8080" types: rabbitMQQueues: apiVersions: diff --git a/deploy/manifest/built-in-providers/dev/microsoft_resources.yaml b/deploy/manifest/built-in-providers/dev/microsoft_resources.yaml index f5f13a7b9f..ff1a86548c 100644 --- a/deploy/manifest/built-in-providers/dev/microsoft_resources.yaml +++ b/deploy/manifest/built-in-providers/dev/microsoft_resources.yaml @@ -1,7 +1,7 @@ name: Microsoft.Resources -locations: +location: global: - address: "http://localhost:5017" + "http://localhost:5017" types: deployments: apiVersions: diff --git a/deploy/manifest/built-in-providers/self-hosted/applications_core.yaml b/deploy/manifest/built-in-providers/self-hosted/applications_core.yaml index 8700134816..e7038d710d 100644 --- a/deploy/manifest/built-in-providers/self-hosted/applications_core.yaml +++ b/deploy/manifest/built-in-providers/self-hosted/applications_core.yaml @@ -1,7 +1,7 @@ name: Applications.Core -locations: +location: global: - address: "http://applications-rp.radius-system:5443" + "http://applications-rp.radius-system:5443" types: containers: apiVersions: @@ -32,7 +32,7 @@ types: apiVersions: "2023-10-01-preview": schema: {} - capabilities: ["Recipes"] + capabilities: ["SupportsRecipes"] volumes: apiVersions: "2023-10-01-preview": diff --git a/deploy/manifest/built-in-providers/self-hosted/applications_dapr.yaml b/deploy/manifest/built-in-providers/self-hosted/applications_dapr.yaml index daaa4fd33d..01e0400565 100644 --- a/deploy/manifest/built-in-providers/self-hosted/applications_dapr.yaml +++ b/deploy/manifest/built-in-providers/self-hosted/applications_dapr.yaml @@ -1,25 +1,25 @@ name: Applications.Dapr -locations: +location: global: - address: "http://applications-rp.radius-system:5443" + "http://applications-rp.radius-system:5443" types: configurationStores: apiVersions: "2023-10-01-preview": schema: {} - capabilities: ["Recipes"] + capabilities: ["SupportsRecipes"] pubSubBrokers: apiVersions: "2023-10-01-preview": schema: {} - capabilities: ["Recipes"] + capabilities: ["SupportsRecipes"] secretStores: apiVersions: "2023-10-01-preview": schema: {} - capabilities: ["Recipes"] + capabilities: ["SupportsRecipes"] stateStores: apiVersions: "2023-10-01-preview": schema: {} - capabilities: ["Recipes"] + capabilities: ["SupportsRecipes"] diff --git a/deploy/manifest/built-in-providers/self-hosted/applications_datastores.yaml b/deploy/manifest/built-in-providers/self-hosted/applications_datastores.yaml index 5d40939fe6..80a6b24a4b 100644 --- a/deploy/manifest/built-in-providers/self-hosted/applications_datastores.yaml +++ b/deploy/manifest/built-in-providers/self-hosted/applications_datastores.yaml @@ -1,20 +1,20 @@ name: Applications.Datastores -locations: +location: global: - address: "http://applications-rp.radius-system:5443" + "http://applications-rp.radius-system:5443" types: mongoDatabases: apiVersions: "2023-10-01-preview": schema: {} - capabilities: ["Recipes"] + capabilities: ["SupportsRecipes"] sqlDatabases: apiVersions: "2023-10-01-preview": schema: {} - capabilities: ["Recipes"] + capabilities: ["SupportsRecipes"] redisCaches: apiVersions: "2023-10-01-preview": schema: {} - capabilities: ["Recipes"] + capabilities: ["SupportsRecipes"] diff --git a/deploy/manifest/built-in-providers/self-hosted/applications_messaging.yaml b/deploy/manifest/built-in-providers/self-hosted/applications_messaging.yaml index 8cb7c16206..b00483559f 100644 --- a/deploy/manifest/built-in-providers/self-hosted/applications_messaging.yaml +++ b/deploy/manifest/built-in-providers/self-hosted/applications_messaging.yaml @@ -1,10 +1,10 @@ name: Applications.Messaging -locations: +location: global: - address: "http://applications-rp.radius-system:5443" + "http://applications-rp.radius-system:5443" types: rabbitMQQueues: apiVersions: "2023-10-01-preview": schema: {} - capabilities: ["Recipes"] + capabilities: ["SupportsRecipes"] diff --git a/deploy/manifest/built-in-providers/self-hosted/microsoft_resources.yaml b/deploy/manifest/built-in-providers/self-hosted/microsoft_resources.yaml index f041b89f90..6cb7ee870c 100644 --- a/deploy/manifest/built-in-providers/self-hosted/microsoft_resources.yaml +++ b/deploy/manifest/built-in-providers/self-hosted/microsoft_resources.yaml @@ -1,7 +1,7 @@ name: Microsoft.Resources -locations: +location: global: - address: "http://bicep-de.radius-system:6443" + "http://bicep-de.radius-system:6443" types: deployments: apiVersions: diff --git a/pkg/cli/cmd/resourceprovider/create/testdata/valid.yaml b/pkg/cli/cmd/resourceprovider/create/testdata/valid.yaml index a6f26f7fb4..f2eee239d6 100644 --- a/pkg/cli/cmd/resourceprovider/create/testdata/valid.yaml +++ b/pkg/cli/cmd/resourceprovider/create/testdata/valid.yaml @@ -1,4 +1,7 @@ name: MyCompany.Resources +location: + global: + 'http://localhost:8080' types: testResources: apiVersions: diff --git a/pkg/cli/cmd/resourcetype/create/testdata/valid.yaml b/pkg/cli/cmd/resourcetype/create/testdata/valid.yaml index 220799cc23..8cc818fd7f 100644 --- a/pkg/cli/cmd/resourcetype/create/testdata/valid.yaml +++ b/pkg/cli/cmd/resourcetype/create/testdata/valid.yaml @@ -4,9 +4,9 @@ types: apiVersions: '2023-10-01-preview': schema: {} - capabilities: ["Recipes"] + capabilities: ["SupportsRecipes"] coolResources: apiVersions: '2023-10-01-preview': schema: {} - capabilities: ["Recipes"] \ No newline at end of file + capabilities: ["SupportsRecipes"] \ No newline at end of file diff --git a/pkg/cli/manifest/manifest.go b/pkg/cli/manifest/manifest.go index d7a8a5855e..b2f25dc268 100644 --- a/pkg/cli/manifest/manifest.go +++ b/pkg/cli/manifest/manifest.go @@ -21,6 +21,9 @@ type ResourceProvider struct { // Name is the resource provider name. This is also the namespace of the types defined by the resource provider. Name string `yaml:"name" validate:"required,resourceProviderNamespace"` + // Locations is a map of location names to addresses in the resource provider. + Location map[string]string `yaml:"location,omitempty"` + // Types is a map of resource types in the resource provider. Types map[string]*ResourceType `yaml:"types" validate:"dive,keys,resourceType,endkeys,required"` } diff --git a/pkg/cli/manifest/manifest_test.go b/pkg/cli/manifest/manifest_test.go index 23c11de187..431ed1fc40 100644 --- a/pkg/cli/manifest/manifest_test.go +++ b/pkg/cli/manifest/manifest_test.go @@ -25,6 +25,9 @@ import ( func TestReadFileYAML(t *testing.T) { expected := &ResourceProvider{ Name: "MyCompany.Resources", + Location: map[string]string{ + "global": "http://localhost:8080", + }, Types: map[string]*ResourceType{ "testResources": { APIVersions: map[string]*ResourceTypeAPIVersion{ diff --git a/pkg/cli/manifest/registermanifest.go b/pkg/cli/manifest/registermanifest.go index 2c2a54fb72..29d652ccb7 100644 --- a/pkg/cli/manifest/registermanifest.go +++ b/pkg/cli/manifest/registermanifest.go @@ -38,9 +38,21 @@ func RegisterFile(ctx context.Context, clientFactory *v20231001preview.ClientFac return err } - logIfEnabled(logger, "Creating resource provider %s", resourceProvider.Name) + var locationName string + var address string + + if resourceProvider.Location == nil { + locationName = v1.LocationGlobal + } else { + for locationKey, locationValue := range resourceProvider.Location { + locationName = locationKey + address = locationValue + } + } + + logIfEnabled(logger, "Creating resource provider %s at location %s", resourceProvider.Name, locationName) resourceProviderPoller, err := clientFactory.NewResourceProvidersClient().BeginCreateOrUpdate(ctx, planeName, resourceProvider.Name, v20231001preview.ResourceProviderResource{ - Location: to.Ptr(v1.LocationGlobal), + Location: to.Ptr(locationName), Properties: &v20231001preview.ResourceProviderProperties{}, }, nil) if err != nil { @@ -101,8 +113,12 @@ func RegisterFile(ctx context.Context, clientFactory *v20231001preview.ClientFac locationResource.Properties.ResourceTypes[resourceTypeName] = locationResourceType } - logIfEnabled(logger, "Creating location %s/%s", resourceProvider.Name, v1.LocationGlobal) - locationPoller, err := clientFactory.NewLocationsClient().BeginCreateOrUpdate(ctx, planeName, resourceProvider.Name, v1.LocationGlobal, locationResource, nil) + if address != "" { + locationResource.Properties.Address = to.Ptr(address) + } + + logIfEnabled(logger, "Creating location %s/%s/%s", resourceProvider.Name, locationName, address) + locationPoller, err := clientFactory.NewLocationsClient().BeginCreateOrUpdate(ctx, planeName, resourceProvider.Name, locationName, locationResource, nil) if err != nil { return err } @@ -167,9 +183,21 @@ func RegisterType(ctx context.Context, clientFactory *v20231001preview.ClientFac return err } + var locationName string + var address string + + if resourceProvider.Location == nil { + locationName = v1.LocationGlobal + } else { + for locationKey, locationValue := range resourceProvider.Location { + locationName = locationKey + address = locationValue + } + } + resourceType, ok := resourceProvider.Types[typeName] if !ok { - return fmt.Errorf("Type %s not found in manifest file %s", typeName, filePath) + return fmt.Errorf("type %s not found in manifest file %s", typeName, filePath) } logIfEnabled(logger, "Creating resource type %s/%s", resourceProvider.Name, typeName) @@ -188,7 +216,7 @@ func RegisterType(ctx context.Context, clientFactory *v20231001preview.ClientFac } // get the existing location resource and update it with new resource type. We have to revisit this code once schema is finalized and validated. - locationResourceGetResponse, err := clientFactory.NewLocationsClient().Get(ctx, planeName, resourceProvider.Name, v1.LocationGlobal, nil) + locationResourceGetResponse, err := clientFactory.NewLocationsClient().Get(ctx, planeName, resourceProvider.Name, locationName, nil) if err != nil { return err } @@ -199,15 +227,21 @@ func RegisterType(ctx context.Context, clientFactory *v20231001preview.ClientFac } else { defaultAPIVersion = *resourceType.DefaultAPIVersion } + locationResource := locationResourceGetResponse.LocationResource + + if address != "" { + locationResource.Properties.Address = to.Ptr(address) + } + locationResource.Properties.ResourceTypes[typeName] = &v20231001preview.LocationResourceType{ APIVersions: map[string]map[string]any{ defaultAPIVersion: {}, }, } - logIfEnabled(logger, "Updating location %s/%s with new resource type", resourceProvider.Name, v1.LocationGlobal) - locationPoller, err := clientFactory.NewLocationsClient().BeginCreateOrUpdate(ctx, planeName, resourceProvider.Name, v1.LocationGlobal, locationResource, nil) + logIfEnabled(logger, "Updating location %s/%s with new resource type", resourceProvider.Name, locationName) + locationPoller, err := clientFactory.NewLocationsClient().BeginCreateOrUpdate(ctx, planeName, resourceProvider.Name, locationName, locationResource, nil) if err != nil { return err } diff --git a/pkg/cli/manifest/testdata/missing-required-field.json b/pkg/cli/manifest/testdata/missing-required-field.json index c6ef38a2f2..8a200cbec9 100644 --- a/pkg/cli/manifest/testdata/missing-required-field.json +++ b/pkg/cli/manifest/testdata/missing-required-field.json @@ -4,7 +4,7 @@ "apiVersions": { "2025-01-01-preview": { "schema": {}, - "capabilities": ["Recipes"] + "capabilities": ["SupportsRecipes"] } } } diff --git a/pkg/cli/manifest/testdata/registerdirectory/resourceprovider-valid1.yaml b/pkg/cli/manifest/testdata/registerdirectory/resourceprovider-valid1.yaml index 0fa92d2251..cd99c151d0 100644 --- a/pkg/cli/manifest/testdata/registerdirectory/resourceprovider-valid1.yaml +++ b/pkg/cli/manifest/testdata/registerdirectory/resourceprovider-valid1.yaml @@ -1,4 +1,7 @@ name: MyCompany.CompanyName +location: + global: + 'http://localhost:8080' types: testResource1: apiVersions: diff --git a/pkg/cli/manifest/testdata/registerdirectory/resourceprovider-valid2.yaml b/pkg/cli/manifest/testdata/registerdirectory/resourceprovider-valid2.yaml index a2ffd310e7..0b70586ad3 100644 --- a/pkg/cli/manifest/testdata/registerdirectory/resourceprovider-valid2.yaml +++ b/pkg/cli/manifest/testdata/registerdirectory/resourceprovider-valid2.yaml @@ -1,4 +1,7 @@ name: MyCompany2.CompanyName2 +location: + global: + 'http://localhost:8080' types: testResource3: apiVersions: diff --git a/pkg/cli/manifest/testdata/valid.yaml b/pkg/cli/manifest/testdata/valid.yaml index a6f26f7fb4..f2eee239d6 100644 --- a/pkg/cli/manifest/testdata/valid.yaml +++ b/pkg/cli/manifest/testdata/valid.yaml @@ -1,4 +1,7 @@ name: MyCompany.Resources +location: + global: + 'http://localhost:8080' types: testResources: apiVersions: diff --git a/pkg/ucp/integrationtests/resourceproviders/testdata/manifests/resourceprovider-valid1.yaml b/pkg/ucp/integrationtests/resourceproviders/testdata/manifests/resourceprovider-valid1.yaml index 4523f045df..02118b74c2 100644 --- a/pkg/ucp/integrationtests/resourceproviders/testdata/manifests/resourceprovider-valid1.yaml +++ b/pkg/ucp/integrationtests/resourceproviders/testdata/manifests/resourceprovider-valid1.yaml @@ -1,4 +1,7 @@ name: TestProvider.TestCompany +location: + global: + 'http://localhost:8080' types: testResourcesAbc: apiVersions: