Skip to content

Commit 17c8852

Browse files
authored
Merge pull request #1839 from pratikjagrut/patches.path.check
fix: remove path variable check
2 parents e8c4c4d + dee12ad commit 17c8852

File tree

4 files changed

+61
-37
lines changed

4 files changed

+61
-37
lines changed

e2e/tests/config/config.go

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package config
33
import (
44
"bytes"
55
"fmt"
6-
"github.com/loft-sh/devspace/pkg/devspace/config/loader/variable"
76
"os"
87
"path/filepath"
98

9+
"github.com/loft-sh/devspace/pkg/devspace/config/loader/variable"
10+
1011
"github.com/loft-sh/devspace/cmd"
1112
"github.com/loft-sh/devspace/cmd/flags"
1213
"github.com/loft-sh/devspace/pkg/devspace/config/versions/latest"
@@ -1907,4 +1908,33 @@ var _ = DevSpaceDescribe("config", func() {
19071908
gomega.Expect(deployment1.Kubectl).To(gomega.BeNil())
19081909
gomega.Expect(*deployment1.Helm.ComponentChart).To(gomega.BeTrue())
19091910
})
1911+
1912+
// regression test for issue: https://github.com/loft-sh/devspace/issues/1835
1913+
ginkgo.It("should load config with var in patch", func() {
1914+
tempDir, err := framework.CopyToTempDir("tests/config/testdata/profile-patches")
1915+
framework.ExpectNoError(err)
1916+
defer framework.CleanupTempDir(initialDir, tempDir)
1917+
1918+
config, _, err := framework.LoadConfigWithOptions(f, filepath.Join(tempDir, "path-variable.yaml"),
1919+
&loader.ConfigOptions{Profiles: []string{"demo"}})
1920+
framework.ExpectNoError(err)
1921+
1922+
framework.ExpectEqual(len(config.Config().Deployments), 1)
1923+
1924+
deployment := config.Config().Deployments[0]
1925+
framework.ExpectEqual(deployment.Name, "test-me-server")
1926+
1927+
values, ok := deployment.Helm.Values["containers"].([]interface{})
1928+
gomega.Expect(ok).To(gomega.BeTrue())
1929+
gomega.Expect(values).NotTo(gomega.BeEmpty())
1930+
1931+
v, ok := values[0].(map[interface{}]interface{})
1932+
gomega.Expect(ok).To(gomega.BeTrue())
1933+
gomega.Expect(v).NotTo(gomega.BeNil())
1934+
1935+
framework.ExpectEqual(v["name"], "replace-0")
1936+
1937+
gomega.Expect(deployment.Kubectl).To(gomega.BeNil())
1938+
gomega.Expect(*deployment.Helm.ComponentChart).To(gomega.BeTrue())
1939+
})
19101940
})
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
version: v1beta11
2+
vars:
3+
- name: IMAGE
4+
value: john/devbackend
5+
- name: PREFIX
6+
value: test-me
7+
deployments:
8+
- name: ${PREFIX}-server
9+
helm:
10+
componentChart: true
11+
values:
12+
containers:
13+
- name: container-0
14+
image: ${IMAGE}
15+
dev:
16+
replacePods:
17+
- imageSelector: ${IMAGE}
18+
replaceImage: ubuntu:18.04
19+
patches:
20+
- op: add
21+
path: spec.containers[0].command
22+
value: ["sleep"]
23+
profiles:
24+
- name: demo
25+
patches:
26+
- op: replace
27+
path: deployments.name=${PREFIX}-server.helm.values.containers[0].name
28+
value: replace-0

pkg/devspace/config/loader/loader.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,15 @@ package loader
22

33
import (
44
"fmt"
5-
"github.com/loft-sh/devspace/pkg/util/constraint"
65
"io/ioutil"
76
"os"
87
"os/exec"
98
"path/filepath"
109
"regexp"
1110
"strings"
1211

12+
"github.com/loft-sh/devspace/pkg/util/constraint"
13+
1314
"github.com/loft-sh/devspace/pkg/devspace/plugin"
1415
"github.com/loft-sh/devspace/pkg/devspace/upgrade"
1516

@@ -422,10 +423,6 @@ func validateProfile(profile interface{}) error {
422423
}
423424

424425
for idx, patch := range profileConfig.Patches {
425-
if vars.VarMatchRegex.MatchString(patch.Path) {
426-
return fmt.Errorf("patches[%d] path cannot be a variable", idx)
427-
}
428-
429426
if expression.ExpressionMatchRegex.MatchString(patch.Path) {
430427
return fmt.Errorf("patches[%d] path cannot be an expression", idx)
431428
}

pkg/devspace/config/loader/loader_test.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,37 +1127,6 @@ profiles:
11271127
},
11281128
},
11291129
},
1130-
"Profile with patch path variable": {
1131-
in: &parseTestCaseInput{
1132-
config: `
1133-
version: v1beta11
1134-
deployments:
1135-
- name: deployment
1136-
helm:
1137-
componentChart: true
1138-
values:
1139-
containers:
1140-
- image: nginx
1141-
profiles:
1142-
- name: testprofile
1143-
patches:
1144-
- path: ${path}
1145-
op: replace
1146-
value:
1147-
- name: deployment
1148-
helm:
1149-
componentChart: true
1150-
values:
1151-
containers:
1152-
- image: ubuntu
1153-
`,
1154-
options: &ConfigOptions{Profiles: []string{"testprofile"}},
1155-
generatedConfig: &generated.Config{Vars: map[string]string{
1156-
"path": "deployments",
1157-
}},
1158-
},
1159-
expectedErr: "error validating profiles[0]: patches[0] path cannot be a variable",
1160-
},
11611130
"Profile with patch path expression": {
11621131
in: &parseTestCaseInput{
11631132
config: `

0 commit comments

Comments
 (0)