Skip to content

Commit 88ffda3

Browse files
authored
[spacelift_stack_processor]: Add explicit labels to Spacelift stacks defined in YAML configs (#42)
1 parent 1ecaf39 commit 88ffda3

File tree

6 files changed

+24
-6
lines changed

6 files changed

+24
-6
lines changed

examples/data-sources/utils_spacelift_stack_config/stacks/uw2-dev.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ components:
7676
autodeploy: true
7777
branch: "dev"
7878
triggers: []
79+
labels:
80+
- "deps:config/secrets/dev-internal-secrets.yml"
7981
env:
8082
ENV_TEST_1: test1_override2
8183
ENV_TEST_2: test2_override2

examples/data-sources/utils_spacelift_stack_config/stacks/uw2-prod.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ components:
8686
autodeploy: true
8787
branch: ""
8888
triggers: []
89+
labels:
90+
- "deps:config/secrets/prod-internal-secrets.yml"
8991
env:
9092
ENV_TEST_1: test1_override2
9193
ENV_TEST_2: test2_override2

examples/data-sources/utils_spacelift_stack_config/stacks/uw2-staging.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ components:
8686
autodeploy: true
8787
branch: ""
8888
triggers: []
89+
labels:
90+
- "deps:config/secrets/staging-internal-secrets.yml"
8991
env:
9092
ENV_TEST_1: test1_override2
9193
ENV_TEST_2: test2_override2

examples/data-sources/utils_spacelift_stack_config/stacks/uw2-uat.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ components:
9595
autodeploy: true
9696
branch: "test4"
9797
triggers: ["7", "8", "9"]
98+
labels:
99+
- "deps:config/secrets/uat-internal-secrets.yml"
98100
env:
99101
ENV_TEST_1: test1_override2
100102
ENV_TEST_2: test2_override2

internal/spacelift/spacelift_stack_processor.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,20 +53,27 @@ func TransformStackConfigToSpaceliftStacks(
5353
componentSettings = i.(map[interface{}]interface{})
5454
}
5555

56+
spaceliftSettings := map[interface{}]interface{}{}
5657
spaceliftWorkspaceEnabled := false
58+
5759
if i, ok2 := componentSettings["spacelift"]; ok2 {
58-
spaceliftSettings := i.(map[interface{}]interface{})
60+
spaceliftSettings = i.(map[interface{}]interface{})
5961

6062
if i3, ok3 := spaceliftSettings["workspace_enabled"]; ok3 {
6163
spaceliftWorkspaceEnabled = i3.(bool)
6264
}
6365
}
6466

65-
// If Spacelift workspace is disabled, don't include it
67+
// If Spacelift workspace is disabled, don't include it, continue to the next component
6668
if spaceliftWorkspaceEnabled == false {
6769
continue
6870
}
6971

72+
spaceliftExplicitLabels := []interface{}{}
73+
if i, ok2 := spaceliftSettings["labels"]; ok2 {
74+
spaceliftExplicitLabels = i.([]interface{})
75+
}
76+
7077
spaceliftConfig := map[string]interface{}{}
7178
spaceliftConfig["enabled"] = spaceliftWorkspaceEnabled
7279

@@ -138,6 +145,9 @@ func TransformStackConfigToSpaceliftStacks(
138145
for _, v := range componentDeps {
139146
labels = append(labels, fmt.Sprintf("deps:"+stackConfigPathTemplate, v))
140147
}
148+
for _, v := range spaceliftExplicitLabels {
149+
labels = append(labels, v.(string))
150+
}
141151
labels = append(labels, fmt.Sprintf("folder:component/%s", component))
142152
// Split on the first `-` and get the two parts: environment and stage
143153
stackNameParts := strings.SplitN(stackName, "-", 2)

internal/spacelift/spacelift_stack_processor_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ import (
99

1010
func TestSpaceliftStackProcessor(t *testing.T) {
1111
filePaths := []string{
12-
"../../examples/data-sources/utils_stack_config_yaml/stacks/uw2-dev.yaml",
13-
"../../examples/data-sources/utils_stack_config_yaml/stacks/uw2-prod.yaml",
14-
"../../examples/data-sources/utils_stack_config_yaml/stacks/uw2-staging.yaml",
15-
"../../examples/data-sources/utils_stack_config_yaml/stacks/uw2-uat.yaml",
12+
"../../examples/data-sources/utils_spacelift_stack_config/stacks/uw2-dev.yaml",
13+
"../../examples/data-sources/utils_spacelift_stack_config/stacks/uw2-prod.yaml",
14+
"../../examples/data-sources/utils_spacelift_stack_config/stacks/uw2-staging.yaml",
15+
"../../examples/data-sources/utils_spacelift_stack_config/stacks/uw2-uat.yaml",
1616
}
1717

1818
processStackDeps := true

0 commit comments

Comments
 (0)