From 27c1633311f5128e9ac44b143e63761f85f6000a Mon Sep 17 00:00:00 2001 From: vinayada1 <28875764+vinayada1@users.noreply.github.com> Date: Fri, 9 Feb 2024 15:34:23 -0800 Subject: [PATCH] Do not try to load recipes for a simulated environment --- pkg/recipes/driver/bicep.go | 5 ----- pkg/recipes/driver/terraform.go | 5 ----- pkg/recipes/engine/engine.go | 27 ++++++++++++++++++++------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/pkg/recipes/driver/bicep.go b/pkg/recipes/driver/bicep.go index c1478dad033..85d1267a364 100644 --- a/pkg/recipes/driver/bicep.go +++ b/pkg/recipes/driver/bicep.go @@ -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 { - logger.Info("simulated environment enabled, skipping deployment") - return nil, nil - } - poller, err := d.DeploymentClient.CreateOrUpdate( ctx, clients.Deployment{ diff --git a/pkg/recipes/driver/terraform.go b/pkg/recipes/driver/terraform.go index b5514955977..6557e987166 100644 --- a/pkg/recipes/driver/terraform.go +++ b/pkg/recipes/driver/terraform.go @@ -85,11 +85,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 - } - tfState, err := d.terraformExecutor.Deploy(ctx, terraform.Options{ RootDir: requestDirPath, EnvConfig: &opts.Configuration, diff --git a/pkg/recipes/engine/engine.go b/pkg/recipes/engine/engine.go index c875cb8750d..fc587ebccde 100644 --- a/pkg/recipes/engine/engine.go +++ b/pkg/recipes/engine/engine.go @@ -27,6 +27,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. @@ -71,14 +72,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 { + 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 } res, err := driver.Execute(ctx, recipedriver.ExecuteOptions{ @@ -119,14 +128,18 @@ 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) + 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 { + 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{