Skip to content

Commit

Permalink
Implementation of Dapr Building Block: Configuration Store (radius-pr…
Browse files Browse the repository at this point in the history
…oject#7906)

# Description

Hey,

This PR adds support for Dapr Configuration Building block

## Type of change

- This pull request adds or changes features of Radius and has an
approved issue (issue link required).

Fixes: radius-project#7889

---------

Signed-off-by: SoTrx <[email protected]>
Co-authored-by: Yetkin Timocin <[email protected]>
  • Loading branch information
SoTrx and ytimocin authored Sep 18, 2024
1 parent a5e97c3 commit a17f9cf
Show file tree
Hide file tree
Showing 61 changed files with 4,778 additions and 62 deletions.

Large diffs are not rendered by default.

9 changes: 6 additions & 3 deletions hack/bicep-types-radius/generated/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,17 @@
"Applications.Core/volumes@2023-10-01-preview": {
"$ref": "applications/applications.core/2023-10-01-preview/types.json#/274"
},
"Applications.Dapr/pubSubBrokers@2023-10-01-preview": {
"Applications.Dapr/configurationStores@2023-10-01-preview": {
"$ref": "applications/applications.dapr/2023-10-01-preview/types.json#/48"
},
"Applications.Dapr/pubSubBrokers@2023-10-01-preview": {
"$ref": "applications/applications.dapr/2023-10-01-preview/types.json#/67"
},
"Applications.Dapr/secretStores@2023-10-01-preview": {
"$ref": "applications/applications.dapr/2023-10-01-preview/types.json#/66"
"$ref": "applications/applications.dapr/2023-10-01-preview/types.json#/85"
},
"Applications.Dapr/stateStores@2023-10-01-preview": {
"$ref": "applications/applications.dapr/2023-10-01-preview/types.json#/85"
"$ref": "applications/applications.dapr/2023-10-01-preview/types.json#/104"
},
"Applications.Datastores/mongoDatabases@2023-10-01-preview": {
"$ref": "applications/applications.datastores/2023-10-01-preview/types.json#/48"
Expand Down
1 change: 1 addition & 0 deletions pkg/cli/clients/management.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ var (
dapr_ctrl.DaprStateStoresResourceType,
dapr_ctrl.DaprSecretStoresResourceType,
dapr_ctrl.DaprPubSubBrokersResourceType,
dapr_ctrl.DaprConfigurationStoresResourceType,
ext_ctrl.ResourceTypeName,
gtwy_ctrl.ResourceTypeName,
cntr_ctrl.ResourceTypeName,
Expand Down
6 changes: 6 additions & 0 deletions pkg/corerp/backend/deployment/deploymentprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,12 @@ func (dp *deploymentProcessor) getResourceDataByID(ctx context.Context, resource
return ResourceData{}, fmt.Errorf(errMsg, resourceID.String(), err)
}
return dp.buildResourceDependency(resourceID, obj.Properties.Application, obj, obj.Properties.Status.OutputResources, obj.ComputedValues, obj.SecretValues, portableresources.RecipeData{})
case strings.ToLower(dapr_ctrl.DaprConfigurationStoresResourceType):
obj := &dapr_dm.DaprConfigurationStore{}
if err = resource.As(obj); err != nil {
return ResourceData{}, fmt.Errorf(errMsg, resourceID.String(), err)
}
return dp.buildResourceDependency(resourceID, obj.Properties.Application, obj, obj.Properties.Status.OutputResources, obj.ComputedValues, obj.SecretValues, portableresources.RecipeData{})
default:
return ResourceData{}, fmt.Errorf("unsupported resource type: %q for resource ID: %q", resourceType, resourceID.String())
}
Expand Down
149 changes: 149 additions & 0 deletions pkg/daprrp/api/v20231001preview/configurationstore_conversion.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
/*
Copyright 2023 The Radius Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
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 v20231001preview

import (
"fmt"
"reflect"
"strings"

v1 "github.com/radius-project/radius/pkg/armrpc/api/v1"
"github.com/radius-project/radius/pkg/daprrp/datamodel"
"github.com/radius-project/radius/pkg/portableresources"
rpv1 "github.com/radius-project/radius/pkg/rp/v1"
"github.com/radius-project/radius/pkg/to"
)

// ConvertTo converts a versioned DaprConfigurationStoreResource to a version-agnostic DaprConfigurationStore. It returns an error
// if the mode is not specified or if the required properties for the mode are not specified.
func (src *DaprConfigurationStoreResource) ConvertTo() (v1.DataModelInterface, error) {
daprConfigurationStoreProperties := datamodel.DaprConfigurationStoreProperties{
BasicResourceProperties: rpv1.BasicResourceProperties{
Environment: to.String(src.Properties.Environment),
Application: to.String(src.Properties.Application),
},
}

trackedResource := v1.TrackedResource{
ID: to.String(src.ID),
Name: to.String(src.Name),
Type: to.String(src.Type),
Location: to.String(src.Location),
Tags: to.StringMap(src.Tags),
}

internalMetadata := v1.InternalMetadata{
UpdatedAPIVersion: Version,
AsyncProvisioningState: toProvisioningStateDataModel(src.Properties.ProvisioningState),
}

converted := &datamodel.DaprConfigurationStore{}
converted.TrackedResource = trackedResource
converted.InternalMetadata = internalMetadata
converted.Properties = daprConfigurationStoreProperties

var err error
converted.Properties.ResourceProvisioning, err = toResourceProvisiongDataModel(src.Properties.ResourceProvisioning)
if err != nil {
return nil, err
}

converted.Properties.Resources = toResourcesDataModel(src.Properties.Resources)
converted.Properties.Auth = toAuthDataModel(src.Properties.Auth)

// Note: The metadata, type, and version fields cannot be specified when using recipes since
// the recipe is expected to create the Dapr Component manifest. However, they are required
// when resourceProvisioning is set to manual.
msgs := []string{}
if converted.Properties.ResourceProvisioning == portableresources.ResourceProvisioningManual {
if src.Properties.Recipe != nil && (!reflect.ValueOf(*src.Properties.Recipe).IsZero()) {
msgs = append(msgs, "recipe details cannot be specified when resourceProvisioning is set to manual")
}
if src.Properties.Metadata == nil || len(src.Properties.Metadata) == 0 {
msgs = append(msgs, "metadata must be specified when resourceProvisioning is set to manual")
}
if src.Properties.Type == nil || *src.Properties.Type == "" {
msgs = append(msgs, "type must be specified when resourceProvisioning is set to manual")
}
if src.Properties.Version == nil || *src.Properties.Version == "" {
msgs = append(msgs, "version must be specified when resourceProvisioning is set to manual")
}
converted.Properties.Metadata = toMetadataDataModel(src.Properties.Metadata)
converted.Properties.Type = to.String(src.Properties.Type)
converted.Properties.Version = to.String(src.Properties.Version)
} else {
if src.Properties.Metadata != nil && (!reflect.ValueOf(src.Properties.Metadata).IsZero()) {
msgs = append(msgs, "metadata cannot be specified when resourceProvisioning is set to recipe (default)")
}
if src.Properties.Type != nil && (!reflect.ValueOf(*src.Properties.Type).IsZero()) {
msgs = append(msgs, "type cannot be specified when resourceProvisioning is set to recipe (default)")
}
if src.Properties.Version != nil && (!reflect.ValueOf(*src.Properties.Version).IsZero()) {
msgs = append(msgs, "version cannot be specified when resourceProvisioning is set to recipe (default)")
}

converted.Properties.Recipe = toRecipeDataModel(src.Properties.Recipe)
}
if len(msgs) > 0 {
return nil, &v1.ErrClientRP{
Code: v1.CodeInvalid,
Message: fmt.Sprintf("error(s) found:\n\t%v", strings.Join(msgs, "\n\t")),
}
}

return converted, nil
}

// ConvertFrom converts from version-agnostic datamodel to the versioned DaprConfigurationStore resource.
// If the DataModelInterface is not of the correct type, an error is returned.
func (dst *DaprConfigurationStoreResource) ConvertFrom(src v1.DataModelInterface) error {
daprConfigstore, ok := src.(*datamodel.DaprConfigurationStore)
if !ok {
return v1.ErrInvalidModelConversion
}

dst.ID = to.Ptr(daprConfigstore.ID)
dst.Name = to.Ptr(daprConfigstore.Name)
dst.Type = to.Ptr(daprConfigstore.Type)
dst.SystemData = fromSystemDataModel(daprConfigstore.SystemData)
dst.Location = to.Ptr(daprConfigstore.Location)
dst.Tags = *to.StringMapPtr(daprConfigstore.Tags)

dst.Properties = &DaprConfigurationStoreProperties{
Environment: to.Ptr(daprConfigstore.Properties.Environment),
Application: to.Ptr(daprConfigstore.Properties.Application),
ResourceProvisioning: fromResourceProvisioningDataModel(daprConfigstore.Properties.ResourceProvisioning),
Resources: fromResourcesDataModel(daprConfigstore.Properties.Resources),
ComponentName: to.Ptr(daprConfigstore.Properties.ComponentName),
ProvisioningState: fromProvisioningStateDataModel(daprConfigstore.InternalMetadata.AsyncProvisioningState),
Status: &ResourceStatus{
OutputResources: toOutputResources(daprConfigstore.Properties.Status.OutputResources),
Recipe: fromRecipeStatus(daprConfigstore.Properties.Status.Recipe),
},
Auth: fromAuthDataModel(daprConfigstore.Properties.Auth),
}

if daprConfigstore.Properties.ResourceProvisioning == portableresources.ResourceProvisioningManual {
dst.Properties.Metadata = fromMetadataDataModel(daprConfigstore.Properties.Metadata)
dst.Properties.Type = to.Ptr(daprConfigstore.Properties.Type)
dst.Properties.Version = to.Ptr(daprConfigstore.Properties.Version)
} else {
dst.Properties.Recipe = fromRecipeDataModel(daprConfigstore.Properties.Recipe)
}

return nil
}
Loading

0 comments on commit a17f9cf

Please sign in to comment.