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 10, 2025
1 parent e004485 commit e7ff53c
Show file tree
Hide file tree
Showing 24 changed files with 109 additions and 44 deletions.
7 changes: 7 additions & 0 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 All @@ -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 \
Expand Down Expand Up @@ -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 \
Expand All @@ -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.
Expand Down
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,10 @@
name: Microsoft.Resources
locations:
location:
global:
address: "http://localhost:5017"
"http://localhost:5017"
types:
deployments:
apiVersions:
"2023-10-01-preview":
"2020-10-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,10 @@
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: {}
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
50 changes: 42 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 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 {
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 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)
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,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
}
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
3 changes: 3 additions & 0 deletions pkg/cli/manifest/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
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
name: TestProvider.TestCompany
location:
global:
'http://localhost:8080'
types:
testResourcesAbc:
apiVersions:
Expand Down

0 comments on commit e7ff53c

Please sign in to comment.