Skip to content

Commit

Permalink
Fixing the applyDeploymentOuput for DaprStateStore (#5394)
Browse files Browse the repository at this point in the history
# Description
While making the DaprStateStore use generic async controllers,
ApplyDeploymentOutput function changes were not added. This PR addresses
that.

## Issue reference
Fixes: #5375 

## Checklist

Please make sure you've completed the relevant tasks for this PR, out of
the following list:

* [x] Code compiles correctly
* [x] Adds necessary unit tests for change
* [ ] Adds necessary E2E tests for change
* [x] Unit tests passing
* [x] Extended the documentation / Created issue for it
  • Loading branch information
ytimocin authored Apr 3, 2023
1 parent 4b4e433 commit 1f54f09
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 1 deletion.
1 change: 0 additions & 1 deletion pkg/corerp/renderers/container/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ func (r Renderer) makeDeployment(ctx context.Context, applicationName string, op
Protocol: corev1.ProtocolTCP,
})
}

}

container := corev1.Container{
Expand Down
6 changes: 6 additions & 0 deletions pkg/linkrp/datamodel/daprstatestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package datamodel
import (
v1 "github.com/project-radius/radius/pkg/armrpc/api/v1"
"github.com/project-radius/radius/pkg/linkrp"
"github.com/project-radius/radius/pkg/linkrp/renderers"
rpv1 "github.com/project-radius/radius/pkg/rp/v1"
)

Expand All @@ -25,6 +26,11 @@ type DaprStateStore struct {
// ApplyDeploymentOutput applies the properties changes based on the deployment output.
func (r *DaprStateStore) ApplyDeploymentOutput(do rpv1.DeploymentOutput) error {
r.Properties.Status.OutputResources = do.DeployedOutputResources
r.ComputedValues = do.ComputedValues
r.SecretValues = do.SecretValues
if cn, ok := do.ComputedValues[renderers.ComponentNameKey].(string); ok {
r.Properties.ComponentName = cn
}
return nil
}

Expand Down
108 changes: 108 additions & 0 deletions pkg/linkrp/datamodel/daprstatestore_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// ------------------------------------------------------------

package datamodel

import (
"testing"

"github.com/project-radius/radius/pkg/linkrp/renderers"
"github.com/project-radius/radius/pkg/resourcekinds"
"github.com/project-radius/radius/pkg/resourcemodel"
rpv1 "github.com/project-radius/radius/pkg/rp/v1"
"github.com/project-radius/radius/pkg/to"
"github.com/stretchr/testify/require"
)

func TestDaprStateStore_ApplyDeploymentOutput(t *testing.T) {
tests := []struct {
name string
dss *DaprStateStore
do *rpv1.DeploymentOutput
wantErr bool
}{
{
name: "with component name",
dss: &DaprStateStore{},
do: &rpv1.DeploymentOutput{
DeployedOutputResources: []rpv1.OutputResource{
{
LocalID: rpv1.LocalIDDaprStateStoreAzureStorage,
ResourceType: resourcemodel.ResourceType{
Type: resourcekinds.DaprStateStoreAzureStorage,
Provider: resourcemodel.ProviderAzure,
},
Identity: resourcemodel.ResourceIdentity{
ResourceType: &resourcemodel.ResourceType{
Type: resourcekinds.DaprStateStoreAzureStorage,
Provider: resourcemodel.ProviderAzure,
},
Data: resourcemodel.ARMIdentity{},
},
RadiusManaged: to.Ptr(true),
Dependencies: []rpv1.Dependency{
{
LocalID: "",
},
},
},
},
ComputedValues: map[string]any{
renderers.ComponentNameKey: "dapr-state-store-test",
},
},
wantErr: false,
},
{
name: "without component name",
dss: &DaprStateStore{},
do: &rpv1.DeploymentOutput{
DeployedOutputResources: []rpv1.OutputResource{
{
LocalID: rpv1.LocalIDDaprStateStoreAzureStorage,
ResourceType: resourcemodel.ResourceType{
Type: resourcekinds.DaprStateStoreAzureStorage,
Provider: resourcemodel.ProviderAzure,
},
Identity: resourcemodel.ResourceIdentity{
ResourceType: &resourcemodel.ResourceType{
Type: resourcekinds.DaprStateStoreAzureStorage,
Provider: resourcemodel.ProviderAzure,
},
Data: resourcemodel.ARMIdentity{},
},
RadiusManaged: to.Ptr(true),
Dependencies: []rpv1.Dependency{
{
LocalID: "",
},
},
},
},
ComputedValues: map[string]any{},
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := tt.dss.ApplyDeploymentOutput(*tt.do); (err != nil) != tt.wantErr {
t.Errorf("DaprStateStore.ApplyDeploymentOutput() error = %v, wantErr %v", err, tt.wantErr)
}

if !tt.wantErr {
require.EqualValues(t, tt.do.DeployedOutputResources, tt.dss.Properties.Status.OutputResources)
require.EqualValues(t, tt.do.ComputedValues, tt.dss.ComputedValues)
require.EqualValues(t, tt.do.SecretValues, tt.dss.SecretValues)
require.Condition(t, func() bool {
if tt.do.ComputedValues[renderers.ComponentNameKey] != nil {
return tt.dss.Properties.ComponentName == tt.do.ComputedValues[renderers.ComponentNameKey]
}
return tt.dss.Properties.ComponentName == ""
}, "component name should be equal")
}
})
}
}
2 changes: 2 additions & 0 deletions test/functional/corerp/resources/mongodb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ func Test_MongoDBUserSecrets(t *testing.T) {
// the creation of a mongoDB from recipe
// container using the mongoDB link to connect to the mongoDB resource
func Test_MongoDB_Recipe(t *testing.T) {
t.Skipf("Enable this test once test flakiness is fixed. - https://github.com/project-radius/radius/issues/5053")

template := "testdata/corerp-resources-mongodb-recipe.bicep"
name := "corerp-resources-mongodb-recipe"
appNamespace := "corerp-resources-mongodb-recipe-app"
Expand Down

0 comments on commit 1f54f09

Please sign in to comment.