Skip to content

Commit

Permalink
enable register manifest
Browse files Browse the repository at this point in the history
Signed-off-by: lakshmimsft <[email protected]>
  • Loading branch information
lakshmimsft committed Jan 14, 2025
1 parent 09988ca commit 3a0e87d
Show file tree
Hide file tree
Showing 28 changed files with 126 additions and 55 deletions.
18 changes: 15 additions & 3 deletions build/docker.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -106,6 +107,17 @@ APPS_MAP := ucpd:./deploy/images/ucpd \
testrp:./test/testrp \
magpiego:./test/magpiego

# copy_manifests copies the manifests to the output directory
.PHONY: copy-manifests
copy-manifests:
@if [ ! -d "$(MANIFEST_DIR)" ] || [ -z "$$(ls -A $(MANIFEST_DIR))" ]; then \
echo "MANIFEST_DIR '$(MANIFEST_DIR)' does not exist or is empty"; \
exit 1; \
fi
@mkdir -p $(OUT_DIR)/manifest/built-in-providers/
@echo "Copying manifests from $(MANIFEST_DIR) to $(OUT_DIR)/manifest/built-in-providers/"
@cp -v $(MANIFEST_DIR)/* $(OUT_DIR)/manifest/built-in-providers/

# Function to extract the name and the directory of the Dockerfile from the app string
define parseApp
$(eval NAME := $(shell echo $(1) | cut -d: -f1))
Expand All @@ -132,15 +144,15 @@ DOCKER_PUSH_MULTI_TARGETS := $(foreach APP,$(APPS_MAP),$(eval $(call parseApp,$(

# targets to build development images
.PHONY: docker-build
docker-build: $(DOCKER_BUILD_TARGETS) ## Builds all Docker images.
docker-build: copy-manifests $(DOCKER_BUILD_TARGETS) ## Builds all Docker images.

.PHONY: docker-push
docker-push: $(DOCKER_PUSH_TARGETS) ## Pushes all Docker images (without building).

# targets to build and push multi arch images. If you run this target in your machine,
# ensure you have qemu and buildx installed by running make configure-buildx.
.PHONY: docker-multi-arch-build
docker-multi-arch-build: $(DOCKER_BUILD_MULTI_TARGETS) ## Builds all docker images for multiple architectures.
docker-multi-arch-build: copy-manifests $(DOCKER_BUILD_MULTI_TARGETS) ## Builds all docker images for multiple architectures.

.PHONY: docker-multi-arch-push
docker-multi-arch-push: $(DOCKER_PUSH_MULTI_TARGETS) ## Pushes all docker images for multiple architectures after building.
docker-multi-arch-push: copy-manifests $(DOCKER_PUSH_MULTI_TARGETS) ## Pushes all docker images for multiple architectures after building.
2 changes: 1 addition & 1 deletion cmd/ucpd/ucp-dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion deploy/Chart/templates/ucp/configmaps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ data:
- id: "/planes/aws/aws"
properties:
kind: "AWS"
manifestDirectory: ""
manifestDirectory: "/manifest/built-in-providers"
identity:
authMethod: UCPCredential
Expand Down
3 changes: 3 additions & 0 deletions deploy/images/ucpd/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions deploy/manifest/built-in-providers/dev/applications_core.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Applications.Core
locations:
location:
global:
address: "http://localhost:8080"
"http://localhost:8080"
types:
containers:
apiVersions:
Expand Down
4 changes: 2 additions & 2 deletions deploy/manifest/built-in-providers/dev/applications_dapr.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Applications.Dapr
locations:
location:
global:
address: "http://localhost:8080"
"http://localhost:8080"
types:
configurationStores:
apiVersions:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Applications.Datastores
locations:
location:
global:
address: "http://localhost:8080"
"http://localhost:8080"
types:
mongoDatabases:
apiVersions:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Applications.Messaging
locations:
location:
global:
address: "http://localhost:8080"
"http://localhost:8080"
types:
rabbitMQQueues:
apiVersions:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
name: Microsoft.Resources
locations:
location:
global:
address: "http://localhost:5017"
"http://localhost:5017"
types:
deployments:
apiVersions:
"2023-10-01-preview":
"2020-10-01":
schema: {}
"2022-09-01":
schema: {}
capabilities: []
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -32,7 +32,7 @@ types:
apiVersions:
"2023-10-01-preview":
schema: {}
capabilities: ["Recipes"]
capabilities: ["SupportsRecipes"]
volumes:
apiVersions:
"2023-10-01-preview":
Expand Down
Original file line number Diff line number Diff line change
@@ -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"]
Original file line number Diff line number Diff line change
@@ -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"]
Original file line number Diff line number Diff line change
@@ -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"]
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
name: Microsoft.Resources
locations:
location:
global:
address: "http://bicep-de.radius-system:6443"
"http://bicep-de.radius-system:6443"
types:
deployments:
apiVersions:
"2023-10-01-preview":
"2020-10-01":
schema: {}
"2022-09-01":
schema: {}
capabilities: []
3 changes: 3 additions & 0 deletions pkg/cli/cmd/resourceprovider/create/testdata/valid.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
name: MyCompany.Resources
location:
global:
'http://localhost:8080'
types:
testResources:
apiVersions:
Expand Down
4 changes: 2 additions & 2 deletions pkg/cli/cmd/resourcetype/create/testdata/valid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ types:
apiVersions:
'2023-10-01-preview':
schema: {}
capabilities: ["Recipes"]
capabilities: ["SupportsRecipes"]
coolResources:
apiVersions:
'2023-10-01-preview':
schema: {}
capabilities: ["Recipes"]
capabilities: ["SupportsRecipes"]
3 changes: 3 additions & 0 deletions pkg/cli/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/cli/manifest/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
49 changes: 41 additions & 8 deletions pkg/cli/manifest/registermanifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 locationName, address = range resourceProvider.Location {
// We support one location per resourceProvider
break
}
}

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 {
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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 locationName, address = range resourceProvider.Location {
// We support one location per resourceProvider
break
}
}

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)
Expand All @@ -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
}
Expand All @@ -199,15 +227,20 @@ 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
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/cli/manifest/testdata/missing-required-field.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"apiVersions": {
"2025-01-01-preview": {
"schema": {},
"capabilities": ["Recipes"]
"capabilities": ["SupportsRecipes"]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
name: MyCompany.CompanyName
location:
global:
'http://localhost:8080'
types:
testResource1:
apiVersions:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
name: MyCompany2.CompanyName2
location:
global:
'http://localhost:8080'
types:
testResource3:
apiVersions:
Expand Down
Loading

0 comments on commit 3a0e87d

Please sign in to comment.