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

[Do Not Merge] Populate Terraform recipe deployed resource IDs in recipe output #6280

Closed
2 changes: 1 addition & 1 deletion pkg/corerp/processors/extenders/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (p *Processor) Delete(ctx context.Context, resource *datamodel.Extender, op
return nil
}

func mergeOutputValues(properties map[string]any, recipeOutput *recipes.RecipeOutput, secret bool) map[string]any {
func mergeOutputValues(properties map[string]any, recipeOutput *recipes.RecipeOutputResponse, secret bool) map[string]any {
values := make(map[string]any)
for k, val := range properties {
values[k] = val
Expand Down
56 changes: 41 additions & 15 deletions pkg/corerp/processors/extenders/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"github.com/radius-project/radius/pkg/portableresources/processors"
"github.com/radius-project/radius/pkg/recipes"
rpv1 "github.com/radius-project/radius/pkg/rp/v1"
"github.com/radius-project/radius/pkg/to"
"github.com/radius-project/radius/pkg/ucp/resources"
"github.com/stretchr/testify/require"
)

Expand All @@ -37,11 +39,19 @@ func Test_Process(t *testing.T) {
processor := Processor{}
t.Run("success - recipe", func(t *testing.T) {
resource := &datamodel.Extender{}
outputResources := []rpv1.OutputResource{}
for _, resource := range []string{extenderResourceID1} {
id, err := resources.ParseResource(resource)
require.NoError(t, err)
result := rpv1.OutputResource{
ID: id,
RadiusManaged: to.Ptr(true),
}
outputResources = append(outputResources, result)
}
options := processors.Options{
RecipeOutput: &recipes.RecipeOutput{
Resources: []string{
extenderResourceID1,
},
RecipeOutput: &recipes.RecipeOutputResponse{
OutputResources: outputResources,
Values: map[string]any{
"bucketName": "myBucket",
"region": "westus",
Expand Down Expand Up @@ -74,7 +84,7 @@ func Test_Process(t *testing.T) {
},
}

expectedOutputResources, err := processors.GetOutputResourcesFromRecipe(options.RecipeOutput)
expectedOutputResources := options.RecipeOutput.OutputResources
require.NoError(t, err)

require.Equal(t, expectedValues, resource.ComputedValues)
Expand Down Expand Up @@ -123,11 +133,19 @@ func Test_Process(t *testing.T) {
},
},
}
outputResources := []rpv1.OutputResource{}
for _, resource := range []string{extenderResourceID2} {
id, err := resources.ParseResource(resource)
require.NoError(t, err)
result := rpv1.OutputResource{
ID: id,
RadiusManaged: to.Ptr(true),
}
outputResources = append(outputResources, result)
}
options := processors.Options{
RecipeOutput: &recipes.RecipeOutput{
Resources: []string{
extenderResourceID2,
},
RecipeOutput: &recipes.RecipeOutputResponse{
OutputResources: outputResources,
// Values and secrets will be overridden by the resource.
Values: map[string]any{
"bucketName": "myBucket2",
Expand Down Expand Up @@ -155,7 +173,7 @@ func Test_Process(t *testing.T) {

expectedOutputResources := []rpv1.OutputResource{}

recipeOutputResources, err := processors.GetOutputResourcesFromRecipe(options.RecipeOutput)
recipeOutputResources := options.RecipeOutput.OutputResources
require.NoError(t, err)
expectedOutputResources = append(expectedOutputResources, recipeOutputResources...)

Expand All @@ -172,7 +190,7 @@ func Test_Process(t *testing.T) {
},
},
}
options := processors.Options{RecipeOutput: &recipes.RecipeOutput{}}
options := processors.Options{RecipeOutput: &recipes.RecipeOutputResponse{}}

err := processor.Process(context.Background(), resource, options)
require.Error(t, err)
Expand All @@ -196,11 +214,19 @@ func Test_MergeOutputValues(t *testing.T) {
secretsMap := mergeOutputValues(resource.Properties.Secrets, nil, true)
require.Equal(t, resource.Properties.Secrets, secretsMap)

outputResources := []rpv1.OutputResource{}
for _, resource := range []string{extenderResourceID1} {
id, err := resources.ParseResource(resource)
require.NoError(t, err)
result := rpv1.OutputResource{
ID: id,
RadiusManaged: to.Ptr(true),
}
outputResources = append(outputResources, result)
}
options := processors.Options{
RecipeOutput: &recipes.RecipeOutput{
Resources: []string{
extenderResourceID1,
},
RecipeOutput: &recipes.RecipeOutputResponse{
OutputResources: outputResources,
Values: map[string]any{
"region": "westus",
},
Expand Down
45 changes: 29 additions & 16 deletions pkg/daprrp/processors/pubsubbrokers/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/radius-project/radius/pkg/recipes"
rpv1 "github.com/radius-project/radius/pkg/rp/v1"
"github.com/radius-project/radius/pkg/to"
"github.com/radius-project/radius/pkg/ucp/resources"
"github.com/radius-project/radius/test/k8sutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -41,7 +42,6 @@ import (

func Test_Process(t *testing.T) {
const externalResourceID1 = "/subscriptions/0000/resourceGroups/test-group/providers/Microsoft.Cache/redis/myredis1"
const externalResourceID2 = "/subscriptions/0000/resourceGroups/test-group/providers/Microsoft.Cache/redis/myredis2"
const kubernetesResource = "/planes/kubernetes/local/namespaces/test-namespace/providers/dapr.io/Component/test-component"
const appID = "/planes/radius/local/resourceGroups/test-rg/providers/Applications.Core/applications/test-app"
const envID = "/planes/radius/local/resourceGroups/test-rg/providers/Applications.Core/environments/test-env"
Expand All @@ -67,20 +67,27 @@ func Test_Process(t *testing.T) {
},
},
}
outputResources := []rpv1.OutputResource{}
for _, resource := range []string{externalResourceID1, kubernetesResource} {
id, err := resources.ParseResource(resource)
require.NoError(t, err)
result := rpv1.OutputResource{
ID: id,
RadiusManaged: to.Ptr(true),
}
outputResources = append(outputResources, result)
}

options := processors.Options{
RuntimeConfiguration: recipes.RuntimeConfiguration{
Kubernetes: &recipes.KubernetesRuntime{
Namespace: "test-namespace",
},
},
RecipeOutput: &recipes.RecipeOutput{
Resources: []string{
externalResourceID1,
kubernetesResource,
},
Values: map[string]any{}, // Component name will be computed for resource name.
Secrets: map[string]any{},
RecipeOutput: &recipes.RecipeOutputResponse{
OutputResources: outputResources,
Values: map[string]any{}, // Component name will be computed for resource name.
Secrets: map[string]any{},
},
}

Expand All @@ -94,7 +101,7 @@ func Test_Process(t *testing.T) {
}
expectedSecrets := map[string]rpv1.SecretValueReference{}

expectedOutputResources, err := processors.GetOutputResourcesFromRecipe(options.RecipeOutput)
expectedOutputResources := options.RecipeOutput.OutputResources
require.NoError(t, err)

require.Equal(t, expectedValues, resource.ComputedValues)
Expand Down Expand Up @@ -222,18 +229,24 @@ func Test_Process(t *testing.T) {
},
},
}

outputResources := []rpv1.OutputResource{}
for _, resource := range []string{externalResourceID1, kubernetesResource} {
id, err := resources.ParseResource(resource)
require.NoError(t, err)
result := rpv1.OutputResource{
ID: id,
RadiusManaged: to.Ptr(true),
}
outputResources = append(outputResources, result)
}
options := processors.Options{
RuntimeConfiguration: recipes.RuntimeConfiguration{
Kubernetes: &recipes.KubernetesRuntime{
Namespace: "test-namespace",
},
},
RecipeOutput: &recipes.RecipeOutput{
Resources: []string{
externalResourceID2,
kubernetesResource,
},
RecipeOutput: &recipes.RecipeOutputResponse{
OutputResources: outputResources,

// Values and secrets will be overridden by the resource.
Values: map[string]any{
Expand All @@ -254,7 +267,7 @@ func Test_Process(t *testing.T) {
expectedSecrets := map[string]rpv1.SecretValueReference{}
expectedOutputResources := []rpv1.OutputResource{}

recipeOutputResources, err := processors.GetOutputResourcesFromRecipe(options.RecipeOutput)
recipeOutputResources := options.RecipeOutput.OutputResources
require.NoError(t, err)
expectedOutputResources = append(expectedOutputResources, recipeOutputResources...)

Expand Down
41 changes: 29 additions & 12 deletions pkg/daprrp/processors/secretstores/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/radius-project/radius/pkg/recipes"
rpv1 "github.com/radius-project/radius/pkg/rp/v1"
"github.com/radius-project/radius/pkg/to"
"github.com/radius-project/radius/pkg/ucp/resources"
"github.com/radius-project/radius/test/k8sutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -64,18 +65,26 @@ func Test_Process(t *testing.T) {
},
},
}
outputResources := []rpv1.OutputResource{}
for _, resource := range []string{kubernetesResource} {
id, err := resources.ParseResource(resource)
require.NoError(t, err)
result := rpv1.OutputResource{
ID: id,
RadiusManaged: to.Ptr(true),
}
outputResources = append(outputResources, result)
}
options := processors.Options{
RuntimeConfiguration: recipes.RuntimeConfiguration{
Kubernetes: &recipes.KubernetesRuntime{
Namespace: "test-namespace",
},
},
RecipeOutput: &recipes.RecipeOutput{
Resources: []string{
kubernetesResource,
},
Values: map[string]any{}, // Component name will be computed for resource name.
Secrets: map[string]any{},
RecipeOutput: &recipes.RecipeOutputResponse{
OutputResources: outputResources,
Values: map[string]any{}, // Component name will be computed for resource name.
Secrets: map[string]any{},
},
}

Expand All @@ -89,7 +98,7 @@ func Test_Process(t *testing.T) {
}
expectedSecrets := map[string]rpv1.SecretValueReference{}

expectedOutputResources, err := processors.GetOutputResourcesFromRecipe(options.RecipeOutput)
expectedOutputResources := options.RecipeOutput.OutputResources
require.NoError(t, err)

require.Equal(t, expectedValues, resource.ComputedValues)
Expand Down Expand Up @@ -206,16 +215,24 @@ func Test_Process(t *testing.T) {
},
},
}
outputResources := []rpv1.OutputResource{}
for _, resource := range []string{kubernetesResource} {
id, err := resources.ParseResource(resource)
require.NoError(t, err)
result := rpv1.OutputResource{
ID: id,
RadiusManaged: to.Ptr(true),
}
outputResources = append(outputResources, result)
}
options := processors.Options{
RuntimeConfiguration: recipes.RuntimeConfiguration{
Kubernetes: &recipes.KubernetesRuntime{
Namespace: "test-namespace",
},
},
RecipeOutput: &recipes.RecipeOutput{
Resources: []string{
kubernetesResource,
},
RecipeOutput: &recipes.RecipeOutputResponse{
OutputResources: outputResources,

// Values and secrets will be overridden by the resource.
Values: map[string]any{
Expand All @@ -237,7 +254,7 @@ func Test_Process(t *testing.T) {

expectedOutputResources := []rpv1.OutputResource{}

recipeOutputResources, err := processors.GetOutputResourcesFromRecipe(options.RecipeOutput)
recipeOutputResources := options.RecipeOutput.OutputResources
require.NoError(t, err)
expectedOutputResources = append(expectedOutputResources, recipeOutputResources...)
require.Equal(t, expectedValues, resource.ComputedValues)
Expand Down
Loading