Skip to content

Commit

Permalink
use disable instead of enable to use default value
Browse files Browse the repository at this point in the history
Signed-off-by: Pulak Kanti Bhowmick <[email protected]>
  • Loading branch information
pkbhowmick committed Nov 3, 2024
1 parent 7251afc commit 3cade8f
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 11 deletions.
5 changes: 5 additions & 0 deletions internal/exec/helmfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ func ExecuteHelmfile(info schema.ConfigAndStacksInfo) error {
return errors.New("stack must be specified")
}

if info.ComponentIsDisabled {
u.LogInfo(cliConfig, "component is disabled and skipped")
return nil
}

err = checkHelmfileConfig(cliConfig)
if err != nil {
return err
Expand Down
12 changes: 6 additions & 6 deletions internal/exec/stack_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ func BuildTerraformWorkspace(cliConfig schema.CliConfiguration, configAndStacksI
return strings.Replace(workspace, "/", "-", -1), nil
}

// ProcessComponentMetadata processes component metadata and returns a base component (if any) and whether the component is real or abstract and whether the component is enabled or not
// ProcessComponentMetadata processes component metadata and returns a base component (if any) and whether the component is real or abstract and whether the component is disabled or not
func ProcessComponentMetadata(
component string,
componentSection map[string]any,
) (map[string]any, string, bool, bool) {
baseComponentName := ""
componentIsAbstract := false
componentIsEnabled := true
componentIsDisabled := false
var componentMetadata map[string]any

// Find base component in the `component` attribute
Expand All @@ -76,9 +76,9 @@ func ProcessComponentMetadata(
componentIsAbstract = true
}
}
if enabledValue, exists := componentMetadata["enabled"]; exists {
if enabled, ok := enabledValue.(bool); ok && !enabled {
componentIsEnabled = false
if disabledValue, exists := componentMetadata["disabled"]; exists {
if disabled, ok := disabledValue.(bool); ok && disabled {
componentIsDisabled = true
}
}
// Find base component in the `metadata.component` attribute
Expand All @@ -93,7 +93,7 @@ func ProcessComponentMetadata(
baseComponentName = ""
}

return componentMetadata, baseComponentName, componentIsAbstract, componentIsEnabled
return componentMetadata, baseComponentName, componentIsAbstract, componentIsDisabled
}

// BuildDependentStackNameFromDependsOnLegacy builds the dependent stack name from "settings.spacelift.depends_on" config
Expand Down
5 changes: 5 additions & 0 deletions internal/exec/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ func ExecuteTerraform(info schema.ConfigAndStacksInfo) error {
return errors.New("stack must be specified")
}

if info.ComponentIsDisabled {
u.LogInfo(cliConfig, "component is disabled and skipped")
return nil
}

err = checkTerraformConfig(cliConfig)
if err != nil {
return err
Expand Down
7 changes: 4 additions & 3 deletions internal/exec/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ func ProcessComponentConfig(
}

// Process component metadata and find a base component (if any) and whether the component is real or abstract
componentMetadata, baseComponentName, componentIsAbstract, componentIsEnabled := ProcessComponentMetadata(component, componentSection)
if !componentIsEnabled {
componentMetadata, baseComponentName, componentIsAbstract, componentIsDisabled := ProcessComponentMetadata(component, componentSection)
if componentIsDisabled {
return nil
}

Expand Down Expand Up @@ -576,8 +576,9 @@ func ProcessStacks(
configAndStacksInfo.ComponentEnvList = u.ConvertEnvVars(configAndStacksInfo.ComponentEnvSection)

// Process component metadata
_, baseComponentName, _, _ := ProcessComponentMetadata(configAndStacksInfo.ComponentFromArg, configAndStacksInfo.ComponentSection)
_, baseComponentName, _, componentIsDisabled := ProcessComponentMetadata(configAndStacksInfo.ComponentFromArg, configAndStacksInfo.ComponentSection)
configAndStacksInfo.BaseComponentPath = baseComponentName
configAndStacksInfo.ComponentIsDisabled = componentIsDisabled

// Process component path and name
configAndStacksInfo.ComponentFolderPrefix = ""
Expand Down
1 change: 1 addition & 0 deletions pkg/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ type ConfigAndStacksInfo struct {
ComponentImportsSection []string
NeedHelp bool
ComponentIsAbstract bool
ComponentIsDisabled bool
ComponentMetadataSection AtmosSectionMapType
TerraformWorkspace string
JsonSchemaDir string
Expand Down
4 changes: 2 additions & 2 deletions pkg/spacelift/spacelift_stack_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ func TransformStackConfigToSpaceliftStacks(
}

// Process component metadata and find a base component (if any) and whether the component is real or abstract
componentMetadata, baseComponentName, componentIsAbstract, ComponentIsEnabled := e.ProcessComponentMetadata(component, componentMap)
componentMetadata, baseComponentName, componentIsAbstract, componentIsDisabled := e.ProcessComponentMetadata(component, componentMap)

if componentIsAbstract || !ComponentIsEnabled {
if componentIsAbstract || componentIsDisabled {
continue
}

Expand Down

0 comments on commit 3cade8f

Please sign in to comment.