Skip to content

Commit

Permalink
Do not try to load recipes for a simulated environment
Browse files Browse the repository at this point in the history
  • Loading branch information
vinayada1 committed Feb 9, 2024
1 parent f26db73 commit 27c1633
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
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 {
logger.Info("simulated environment enabled, skipping deployment")
return nil, nil
}

poller, err := d.DeploymentClient.CreateOrUpdate(
ctx,
clients.Deployment{
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 @@ -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,
Expand Down
27 changes: 20 additions & 7 deletions pkg/recipes/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 27c1633

Please sign in to comment.