Skip to content

Commit cbd391f

Browse files
authored
Refactor repeated default prefixes in variable resolution (#3365)
## Why Plan to update this with "resources", this reduces number of places to change. Also adds a central place to explain why this list has this contents. ## Tests Existing tests.
1 parent fe9d5d4 commit cbd391f

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

bundle/config/mutator/resolve_variable_references.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ rounds time
3333
*/
3434
const maxResolutionRounds = 11
3535

36+
// List of prefixes to be used by default in ResolveVariableReferencesOnlyResources/ResolveVariableReferencesWithoutResources
37+
// Prefixes specify which references are resolves, e.g. ${bundle...} and so on.
38+
// This list does not include "artifacts" because this section will be modified in build phase and variable resolution happens in initialize phase.
39+
// This list does not include "resources" because some of those references are known after resource is deployed.
40+
var defaultPrefixes = []string{
41+
"bundle",
42+
"workspace",
43+
"variables",
44+
}
45+
3646
type resolveVariableReferences struct {
3747
prefixes []string
3848
pattern dyn.Pattern
@@ -48,6 +58,9 @@ type resolveVariableReferences struct {
4858
}
4959

5060
func ResolveVariableReferencesOnlyResources(prefixes ...string) bundle.Mutator {
61+
if len(prefixes) == 0 {
62+
prefixes = defaultPrefixes
63+
}
5164
return &resolveVariableReferences{
5265
prefixes: prefixes,
5366
lookupFn: lookup,
@@ -58,6 +71,9 @@ func ResolveVariableReferencesOnlyResources(prefixes ...string) bundle.Mutator {
5871
}
5972

6073
func ResolveVariableReferencesWithoutResources(prefixes ...string) bundle.Mutator {
74+
if len(prefixes) == 0 {
75+
prefixes = defaultPrefixes
76+
}
6177
return &resolveVariableReferences{
6278
prefixes: prefixes,
6379
lookupFn: lookup,
@@ -67,11 +83,7 @@ func ResolveVariableReferencesWithoutResources(prefixes ...string) bundle.Mutato
6783

6884
func ResolveVariableReferencesInLookup() bundle.Mutator {
6985
return &resolveVariableReferences{
70-
prefixes: []string{
71-
"bundle",
72-
"workspace",
73-
"variables",
74-
},
86+
prefixes: defaultPrefixes,
7587
pattern: dyn.NewPattern(dyn.Key("variables"), dyn.AnyKey(), dyn.Key("lookup")),
7688
lookupFn: lookupForVariables,
7789
extraRounds: maxResolutionRounds - 1,

bundle/config/mutator/resourcemutator/process_static_resources.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,7 @@ func (p processStaticResources) Apply(ctx context.Context, b *bundle.Bundle) dia
4444
// Reads (dynamic): * (strings) (searches for variable references in string values)
4545
// Updates (dynamic): resources.* (strings) (resolves variable references to their actual values)
4646
// Resolves variable references in 'resources' using bundle, workspace, and variables prefixes
47-
mutator.ResolveVariableReferencesOnlyResources(
48-
"bundle",
49-
"workspace",
50-
"variables",
51-
),
47+
mutator.ResolveVariableReferencesOnlyResources(),
5248
mutator.NormalizePaths(),
5349

5450
// Translate dashboard paths into paths in the workspace file system

bundle/config/mutator/resourcemutator/resource_mutator.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,7 @@ func applyNormalizeMutators(ctx context.Context, b *bundle.Bundle) {
125125
// Reads (dynamic): * (strings) (searches for variable references in string values)
126126
// Updates (dynamic): resources.* (strings) (resolves variable references to their actual values)
127127
// Resolves variable references in 'resources' using bundle, workspace, and variables prefixes
128-
mutator.ResolveVariableReferencesOnlyResources(
129-
"bundle",
130-
"workspace",
131-
"variables",
132-
),
128+
mutator.ResolveVariableReferencesOnlyResources(),
133129

134130
// Reads (dynamic): resources.pipelines.*.libraries (checks for notebook.path and file.path fields)
135131
// Updates (dynamic): resources.pipelines.*.libraries (expands glob patterns in path fields to multiple library entries)

bundle/phases/initialize.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,7 @@ func Initialize(ctx context.Context, b *bundle.Bundle) {
119119
// Updates (dynamic): * (except 'resources') (strings) (resolves variable references to their actual values)
120120
// Resolves variable references in configuration (except resources) using bundle, workspace,
121121
// and variables prefixes
122-
mutator.ResolveVariableReferencesWithoutResources(
123-
"bundle",
124-
"workspace",
125-
"variables",
126-
),
122+
mutator.ResolveVariableReferencesWithoutResources(),
127123

128124
// Check for invalid use of /Volumes in workspace paths
129125
validate.ValidateVolumePath(),

0 commit comments

Comments
 (0)