Skip to content

Commit f45b0c9

Browse files
committed
feat: allow variables in complete imports section
1 parent 0e1efa8 commit f45b0c9

6 files changed

Lines changed: 82 additions & 3 deletions

File tree

e2e/tests/imports/imports.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,60 @@ var _ = DevSpaceDescribe("imports", func() {
3131
framework.ExpectNoError(err)
3232
})
3333

34+
ginkgo.It("should import correctly with variables", func() {
35+
tempDir, err := framework.CopyToTempDir("tests/imports/testdata/conditional")
36+
framework.ExpectNoError(err)
37+
defer framework.CleanupTempDir(initialDir, tempDir)
38+
39+
ns, err := kubeClient.CreateNamespace("imports")
40+
framework.ExpectNoError(err)
41+
defer func() {
42+
err := kubeClient.DeleteNamespace(ns)
43+
framework.ExpectNoError(err)
44+
}()
45+
46+
// create a new dev command
47+
deployCmd := &cmd.RunPipelineCmd{
48+
GlobalFlags: &flags.GlobalFlags{
49+
NoWarn: true,
50+
Namespace: ns,
51+
Profiles: []string{},
52+
},
53+
Pipeline: "deploy",
54+
}
55+
56+
// run the command
57+
err = deployCmd.RunDefault(f)
58+
framework.ExpectNoError(err)
59+
60+
// read temp folder
61+
framework.ExpectLocalFileContentsWithoutSpaces("import1.txt", "import1")
62+
63+
// change path
64+
err = os.Setenv("IMPORT1_PATH", "import2.yaml")
65+
framework.ExpectNoError(err)
66+
defer func() {
67+
_ = os.Unsetenv("IMPORT1_PATH")
68+
}()
69+
70+
// create a new dev command
71+
deployCmd = &cmd.RunPipelineCmd{
72+
GlobalFlags: &flags.GlobalFlags{
73+
NoWarn: true,
74+
Namespace: ns,
75+
Profiles: []string{},
76+
},
77+
Pipeline: "deploy",
78+
}
79+
80+
// run the command
81+
err = deployCmd.RunDefault(f)
82+
framework.ExpectNoError(err)
83+
84+
// read temp folder
85+
framework.ExpectLocalFileContentsWithoutSpaces("import1.txt", "import2")
86+
})
87+
3488
ginkgo.It("should import correctly", func() {
3589
tempDir, err := framework.CopyToTempDir("tests/imports/testdata/local")
3690
framework.ExpectNoError(err)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: v2beta1
2+
name: base
3+
4+
imports:
5+
- path: ./${IMPORT1_PATH}
6+
7+
vars:
8+
IMPORT1_PATH:
9+
source: env
10+
default: import1.yaml
11+
12+
pipelines:
13+
deploy:
14+
run: |-
15+
echo ${IMPORT1} > import1.txt
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
version: v2beta1
2+
name: import1
3+
4+
vars:
5+
IMPORT1: import1
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
version: v2beta1
2+
name: import1
3+
4+
vars:
5+
IMPORT1: import2

pkg/devspace/config/loader/imports.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func ResolveImports(ctx context.Context, resolver variable.Resolver, basePath st
4646
return nil, errors.Errorf("Version is missing in devspace.yaml")
4747
}
4848

49-
rawImportsInterface, err := resolver.FillVariablesInclude(ctx, rawImports, []string{"/imports/*/enabled"})
49+
rawImportsInterface, err := resolver.FillVariablesInclude(ctx, rawImports, []string{"/imports/**"})
5050
if err != nil {
5151
return nil, err
5252
}

pkg/devspace/config/loader/variable/resolver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ func (r *resolver) insertVariableGraph(g *graph.Graph, node *latest.Variable) er
260260
func (r *resolver) FillVariablesInclude(ctx context.Context, haystack interface{}, includedPaths []string) (interface{}, error) {
261261
paths := []*regexp.Regexp{}
262262
for _, path := range includedPaths {
263-
path = strings.ReplaceAll(path, "*", "[^/]+")
264263
path = strings.ReplaceAll(path, "**", ".+")
264+
path = strings.ReplaceAll(path, "*", "[^/]+")
265265
path = "^" + path + "$"
266266
expr, err := regexp.Compile(path)
267267
if err != nil {
@@ -290,8 +290,8 @@ func (r *resolver) FillVariablesInclude(ctx context.Context, haystack interface{
290290
func (r *resolver) FillVariablesExclude(ctx context.Context, haystack interface{}, excludedPaths []string) (interface{}, error) {
291291
paths := []*regexp.Regexp{}
292292
for _, path := range excludedPaths {
293-
path = strings.ReplaceAll(path, "*", "[^/]+")
294293
path = strings.ReplaceAll(path, "**", ".+")
294+
path = strings.ReplaceAll(path, "*", "[^/]+")
295295
path = "^" + path + "$"
296296
expr, err := regexp.Compile(path)
297297
if err != nil {

0 commit comments

Comments
 (0)