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 try to load recipes for a simulated environment #7157

Merged
merged 3 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 24 additions & 0 deletions pkg/recipes/configloader/environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,30 @@ func TestGetConfiguration(t *testing.T) {
Providers: createAWSProvider(),
},
},
{
// Add test here for the simulated flag
name: "simulated env",
envResource: &model.EnvironmentResource{
Properties: &model.EnvironmentProperties{
Compute: &model.KubernetesCompute{
Kind: to.Ptr(kind),
Namespace: to.Ptr(envNamespace),
ResourceID: to.Ptr(envResourceId),
},
Simulated: to.Ptr(true),
},
},
appResource: nil,
expectedConfig: &recipes.Configuration{
Runtime: recipes.RuntimeConfiguration{
Kubernetes: &recipes.KubernetesRuntime{
Namespace: "default",
EnvironmentNamespace: envNamespace,
},
},
Simulated: true,
},
},
{
name: "invalid app resource",
envResource: &model.EnvironmentResource{
Expand Down
5 changes: 0 additions & 5 deletions pkg/recipes/driver/bicep.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,6 @@ func (d *bicepDriver) Execute(ctx context.Context, opts ExecuteOptions) (*recipe
logger.Info("using Azure provider", "deploymentID", deploymentID, "scope", providerConfig.Az.Value.Scope)
}

if opts.Configuration.Simulated {
vinayada1 marked this conversation as resolved.
Show resolved Hide resolved
logger.Info("simulated environment enabled, skipping deployment")
return nil, nil
}

poller, err := d.DeploymentClient.CreateOrUpdate(
ctx,
clients.Deployment{
Expand Down
34 changes: 0 additions & 34 deletions pkg/recipes/driver/bicep_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,40 +378,6 @@ func Test_Bicep_PrepareRecipeResponse_EmptyResult(t *testing.T) {
require.Equal(t, expectedResponse, actualResponse)
}

func Test_Bicep_Execute_SimulatedEnvironment(t *testing.T) {
ts := registrytest.NewFakeRegistryServer(t)
t.Cleanup(ts.CloseServer)

opts := ExecuteOptions{
BaseOptions: BaseOptions{
Configuration: recipes.Configuration{
Runtime: recipes.RuntimeConfiguration{
Kubernetes: &recipes.KubernetesRuntime{
Namespace: "test-namespace",
},
},
Simulated: true,
},
Recipe: recipes.ResourceMetadata{
EnvironmentID: "/subscriptions/test-sub/resourceGroups/test-group/providers/Applications.Core/environments/test-env",
Name: "test-recipe",
ResourceID: "/subscriptions/test-sub/resourceGroups/test-group/providers/Applications.Datastores/mongoDatabases/test-db",
},
Definition: recipes.EnvironmentDefinition{
Name: "test-recipe",
Driver: recipes.TemplateKindBicep,
TemplatePath: ts.TestImageURL,
ResourceType: "Applications.Datastores/mongoDatabases",
},
},
}
ctx := testcontext.New(t)
d := &bicepDriver{RegistryClient: ts.TestServer.Client()}
recipesOutput, err := d.Execute(ctx, opts)
require.NoError(t, err)
require.Nil(t, recipesOutput)
}

func setupDeleteInputs(t *testing.T) (bicepDriver, *processors.MockResourceClient) {
ctrl := gomock.NewController(t)
client := processors.NewMockResourceClient(ctrl)
Expand Down
5 changes: 0 additions & 5 deletions pkg/recipes/driver/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@ func (d *terraformDriver) Execute(ctx context.Context, opts ExecuteOptions) (*re
}
}()

if opts.Configuration.Simulated {
logger.Info("simulated environment is set to true, skipping deployment")
return nil, nil
}

// Add credential information to .gitconfig if module source is of type git.
if strings.HasPrefix(opts.Definition.TemplatePath, "git::") && !reflect.DeepEqual(opts.BaseOptions.Secrets, v20231001preview.SecretStoresClientListSecretsResponse{}) {
err := addSecretsToGitConfig(opts.BaseOptions.Secrets, &opts.Recipe, opts.Definition.TemplatePath)
Expand Down
22 changes: 0 additions & 22 deletions pkg/recipes/driver/terraform_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,28 +307,6 @@ func Test_Terraform_Execute_MissingARMRequestContext_Panics(t *testing.T) {
})
}

func Test_Terraform_Execute_SimulatedEnvironment(t *testing.T) {
ctx := testcontext.New(t)
armCtx := &v1.ARMRequestContext{
OperationID: uuid.New(),
}
ctx = v1.WithARMRequestContext(ctx, armCtx)

_, driver := setup(t)
envConfig, recipeMetadata, envRecipe := buildTestInputs()
envConfig.Simulated = true

recipeOutput, err := driver.Execute(ctx, ExecuteOptions{
BaseOptions: BaseOptions{
Configuration: envConfig,
Recipe: recipeMetadata,
Definition: envRecipe,
},
})
require.NoError(t, err)
require.Nil(t, recipeOutput)
}

func TestTerraformDriver_GetRecipeMetadata_Success(t *testing.T) {
ctx := testcontext.New(t)
armCtx := &v1.ARMRequestContext{
Expand Down
29 changes: 22 additions & 7 deletions pkg/recipes/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
recipedriver "github.com/radius-project/radius/pkg/recipes/driver"
"github.com/radius-project/radius/pkg/recipes/util"
rpv1 "github.com/radius-project/radius/pkg/rp/v1"
"github.com/radius-project/radius/pkg/ucp/ucplog"
)

// NewEngine creates a new Engine to deploy recipe.
Expand Down Expand Up @@ -73,14 +74,22 @@ func (e *engine) Execute(ctx context.Context, opts ExecuteOptions) (*recipes.Rec
// executeCore function is the core logic of the Execute function.
// Any changes to the core logic of the Execute function should be made here.
func (e *engine) executeCore(ctx context.Context, recipe recipes.ResourceMetadata, prevState []string) (*recipes.RecipeOutput, *recipes.EnvironmentDefinition, error) {
definition, driver, err := e.getDriver(ctx, recipe)
logger := ucplog.FromContextOrDiscard(ctx)

configuration, err := e.options.ConfigurationLoader.LoadConfiguration(ctx, recipe)
if err != nil {
return nil, nil, err
return nil, nil, recipes.NewRecipeError(recipes.RecipeConfigurationFailure, err.Error(), util.RecipeSetupError, recipes.GetErrorDetails(err))
}

configuration, err := e.options.ConfigurationLoader.LoadConfiguration(ctx, recipe)
// No need to try executing the recipe if it's a simulated environment.
if configuration.Simulated {
vinayada1 marked this conversation as resolved.
Show resolved Hide resolved
logger.Info("simulated environment enabled, skipping deployment")
return nil, nil, nil
}

definition, driver, err := e.getDriver(ctx, recipe)
if err != nil {
return nil, definition, recipes.NewRecipeError(recipes.RecipeConfigurationFailure, err.Error(), util.RecipeSetupError, recipes.GetErrorDetails(err))
return nil, nil, err
}

// Retrieves the secret store id from the recipes configuration for the terraform module source of type git.
Expand Down Expand Up @@ -138,14 +147,20 @@ func (e *engine) Delete(ctx context.Context, opts DeleteOptions) error {
// deleteCore function is the core logic of the Delete function.
// Any changes to the core logic of the Delete function should be made here.
func (e *engine) deleteCore(ctx context.Context, recipe recipes.ResourceMetadata, outputResources []rpv1.OutputResource) (*recipes.EnvironmentDefinition, error) {
definition, driver, err := e.getDriver(ctx, recipe)
logger := ucplog.FromContextOrDiscard(ctx)
configuration, err := e.options.ConfigurationLoader.LoadConfiguration(ctx, recipe)
if err != nil {
return nil, err
}

configuration, err := e.options.ConfigurationLoader.LoadConfiguration(ctx, recipe)
if configuration.Simulated {
vinayada1 marked this conversation as resolved.
Show resolved Hide resolved
logger.Info("simulated environment enabled, skipping deleting resources")
return nil, nil
}

definition, driver, err := e.getDriver(ctx, recipe)
if err != nil {
return definition, err
return nil, err
}

err = driver.Delete(ctx, recipedriver.DeleteOptions{
Expand Down
Loading
Loading