Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of Dapr Building Block: Configuration Store #7906

Merged
merged 18 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
932702a
feat(daprrp): Support for Configuration Building Block
SoTrx Sep 6, 2024
b8c0a64
test(pubsub): fix minor error in Dapr PubSub broker test
SoTrx Sep 9, 2024
1a5dbec
style(typespec): Linting
SoTrx Sep 9, 2024
3bdec76
Update pkg/daprrp/api/v20231001preview/configurationstore_conversion.go
SoTrx Sep 10, 2024
e095aa3
Update pkg/daprrp/api/v20231001preview/configurationstore_conversion_…
SoTrx Sep 10, 2024
cbabbc7
Update pkg/daprrp/api/v20231001preview/configurationstore_conversion_…
SoTrx Sep 10, 2024
d772c6e
Update pkg/daprrp/frontend/controller/types.go
SoTrx Sep 10, 2024
78250b7
Update pkg/daprrp/datamodel/daprconfigurationstore.go
SoTrx Sep 10, 2024
d0154fd
Update pkg/daprrp/datamodel/daprconfigurationstore.go
SoTrx Sep 10, 2024
fcb6814
Update pkg/daprrp/datamodel/daprconfigurationstore.go
SoTrx Sep 10, 2024
0f54526
Update pkg/daprrp/datamodel/daprconfigurationstore.go
SoTrx Sep 10, 2024
bb80dc1
Update pkg/daprrp/datamodel/daprconfigurationstore.go
SoTrx Sep 10, 2024
60282a8
style: adjust spacing and rename variables for consistency
SoTrx Sep 10, 2024
46bce26
test: Updating Dapr conflict prompt with new building block Configura…
SoTrx Sep 10, 2024
b53c88d
test: Updating Dapr conflict prompt with new building block Configura…
SoTrx Sep 10, 2024
31aebcc
Update pkg/portableresources/handlers/util.go
SoTrx Sep 11, 2024
726a587
test: Updating Dapr conflict prompt with new building block Configura…
SoTrx Sep 11, 2024
e655e73
test: Updating Dapr conflict prompt with new building block Configura…
SoTrx Sep 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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{
SoTrx marked this conversation as resolved.
Show resolved Hide resolved
UpdatedAPIVersion: Version,
AsyncProvisioningState: toProvisioningStateDataModel(src.Properties.ProvisioningState),
}

converted := &datamodel.DaprConfigurationStore{}
SoTrx marked this conversation as resolved.
Show resolved Hide resolved
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