diff --git a/.github/workflows/functional-test.yaml b/.github/workflows/functional-test.yaml index 8c39239d2bb..d117acfb00c 100644 --- a/.github/workflows/functional-test.yaml +++ b/.github/workflows/functional-test.yaml @@ -576,6 +576,28 @@ jobs: with: name: ${{ matrix.name }}_container_logs path: ./${{ env.RADIUS_CONTAINER_LOG_BASE }} + - name: Get Terraform recipe publishing logs + if: always() + run: | + # Create pod-logs directory + mkdir -p recipes/pod-logs + # Get pod logs and save to file + namespace="radius-test-tf-module-server" + label="app.kubernetes.io/name=tf-module-server" + pod_names=($(kubectl get pods -l $label -n $namespace -o jsonpath='{.items[*].metadata.name}')) + for pod_name in "${pod_names[@]}"; do + kubectl logs $pod_name -n $namespace > recipes/pod-logs/${pod_name}.txt + done + echo "Pod logs saved to recipes/pod-logs/" + # Get kubernetes events and save to file + kubectl get events -n $namespace > recipes/pod-logs/events.txt + - name: Upload Terraform recipe publishing logs + uses: actions/upload-artifact@v3 + if: always() + with: + name: recipes-pod-logs + path: recipes/pod-logs + if-no-files-found: error - uses: marocchino/sticky-pull-request-comment@v2 if: success() && env.PR_NUMBER != '' continue-on-error: true diff --git a/test/functional/datastoresrp/resources/mongodb_test.go b/test/functional/datastoresrp/resources/mongodb_test.go index a9995f2d8ea..beed65f745b 100644 --- a/test/functional/datastoresrp/resources/mongodb_test.go +++ b/test/functional/datastoresrp/resources/mongodb_test.go @@ -17,7 +17,6 @@ limitations under the License. package resource_test import ( - "os" "testing" "github.com/radius-project/radius/test/functional" @@ -117,58 +116,3 @@ func Test_MongoDB_Recipe(t *testing.T) { test.Test(t) } - -// Test_MongoDB_Recipe_ContextParameter validates creation of a mongoDB from -// a default recipe using the context parameter generated and set by DatastoresRP, -// and container using the mongoDatabases portable resource to connect to the underlying mongoDB resource. -func Test_MongoDB_Recipe_ContextParameter(t *testing.T) { - t.Skip("Skipping test as creating/deleting cosmosdb resource is unreliable - https://github.com/radius-project/radius/issues/5929") - - template := "testdata/datastoresrp-resources-mongodb-recipe-context.bicep" - name := "dsrp-resources-mongodb-recipe-context" - appNamespace := "dsrp-resources-mongodb-recipe-context-app" - rg := os.Getenv("INTEGRATION_TEST_RESOURCE_GROUP_NAME") - // Error the test if INTEGRATION_TEST_RESOURCE_GROUP_NAME is not set - // for running locally set the INTEGRATION_TEST_RESOURCE_GROUP_NAME with the test resourceGroup - if rg == "" { - t.Error("This test needs the env variable INTEGRATION_TEST_RESOURCE_GROUP_NAME to be set") - } - - test := shared.NewRPTest(t, name, []shared.TestStep{ - { - Executor: step.NewDeployExecutor(template, functional.GetMagpieImage(), functional.GetBicepRecipeRegistry(), functional.GetBicepRecipeVersion()), - RPResources: &validation.RPResourceSet{ - Resources: []validation.RPResource{ - { - Name: "dsrp-resources-env-recipes-context-env", - Type: validation.EnvironmentsResource, - }, - { - Name: name, - Type: validation.ApplicationsResource, - App: name, - }, - { - Name: "mdb-ctx-ctnr", - Type: validation.ContainersResource, - App: name, - }, - { - Name: "mdb-ctx", - Type: validation.MongoDatabasesResource, - App: name, - }, - }, - }, - K8sObjects: &validation.K8sObjectSet{ - Namespaces: map[string][]validation.K8sObject{ - appNamespace: { - validation.NewK8sPodForResource(name, "mdb-ctx-ctnr").ValidateLabels(false), - }, - }, - }, - }, - }) - - test.Test(t) -} diff --git a/test/functional/shared/resources/recipe_bicep_test.go b/test/functional/shared/resources/recipe_bicep_test.go index 3141f40f70b..59b4adc26e8 100644 --- a/test/functional/shared/resources/recipe_bicep_test.go +++ b/test/functional/shared/resources/recipe_bicep_test.go @@ -110,6 +110,53 @@ func Test_BicepRecipe_ParametersAndOutputs(t *testing.T) { test.Test(t) } +// This test validates that the recipe context parameter is populated as expected. +func Test_BicepRecipe_ContextParameter(t *testing.T) { + template := "testdata/corerp-resources-recipe-bicep.bicep" + name := "corerp-resources-recipe-bicep-contextparameter" + + parameters := []string{ + functional.GetBicepRecipeRegistry(), + functional.GetBicepRecipeVersion(), + fmt.Sprintf("basename=%s", name), + fmt.Sprintf("recipe=%s", "context-parameter"), + } + + test := shared.NewRPTest(t, name, []shared.TestStep{ + { + Executor: step.NewDeployExecutor(template, parameters...), + RPResources: &validation.RPResourceSet{ + Resources: []validation.RPResource{ + { + Name: name, + Type: validation.ApplicationsResource, + }, + { + Name: name, + Type: validation.ExtendersResource, + }, + }, + }, + K8sObjects: &validation.K8sObjectSet{}, + PostStepVerify: func(ctx context.Context, t *testing.T, test shared.RPTest) { + resource, err := test.Options.ManagementClient.ShowResource(ctx, "Applications.Core/extenders", name) + require.NoError(t, err) + + text, err := json.MarshalIndent(resource, "", " ") + require.NoError(t, err) + t.Logf("resource data:\n %s", text) + + require.Equal(t, name, resource.Properties["environment"]) + require.Equal(t, name, resource.Properties["application"]) + require.Equal(t, name, resource.Properties["resource"]) + require.Equal(t, name+"-app", resource.Properties["namespace"]) + require.Equal(t, name+"-env", resource.Properties["envNamespace"]) + }, + }, + }) + test.Test(t) +} + // This test actually creates a Radius resource using a recipe (yeah, not a real user scenario). // // The purpose of this test is to test creation and behavior of **output resources**. This way we diff --git a/test/functional/shared/resources/testdata/recipes/test-bicep-recipes/context-parameter.bicep b/test/functional/shared/resources/testdata/recipes/test-bicep-recipes/context-parameter.bicep new file mode 100644 index 00000000000..b961d8acdc0 --- /dev/null +++ b/test/functional/shared/resources/testdata/recipes/test-bicep-recipes/context-parameter.bicep @@ -0,0 +1,12 @@ +// A simple Bicep recipe that tests context parameter is applied. It doesn't provision any resources. +param context object + +output result object = { + values: { + environment: context.environment.Name + application: context.application.Name + resource: context.resource.Name + namespace: context.runtime.kubernetes.namespace + envNamespace: context.runtime.kubernetes.environmentNamespace + } +}