Skip to content

Commit 6dde63b

Browse files
authored
Merge pull request #2068 from FabianKramm/master
refactor: disable probes if image or command is replaced
2 parents 19bb13a + 16ddfdf commit 6dde63b

15 files changed

Lines changed: 226 additions & 75 deletions

File tree

e2e/framework/helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func ExpectRemoteContainerFileContents(labelSelector, container string, namespac
157157
func ExpectLocalFileContentsImmediately(filePath string, contents string) {
158158
out, err := ioutil.ReadFile(filePath)
159159
ExpectNoError(err)
160-
gomega.ExpectWithOffset(2, string(out)).To(gomega.Equal(contents))
160+
gomega.ExpectWithOffset(1, string(out)).To(gomega.Equal(contents))
161161
}
162162

163163
func ExpectLocalFileContents(filePath string, contents string) {

e2e/tests/dependencies/dependencies.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ var _ = DevSpaceDescribe("dependencies", func() {
6666
err = devCmd.RunDefault(f)
6767
framework.ExpectNoError(err)
6868
framework.ExpectLocalFileContentsImmediately(filepath.Join(tempDir, "out.txt"), `dep3
69-
dep2
70-
dep2
71-
wait
69+
dep2dep2wait
7270
`)
7371
})
7472

e2e/tests/dependencies/testdata/wait/dep1.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ pipelines:
99
deploy: |-
1010
run_dependencies --all
1111
# We use dep2 here because we don't know if dep1 or dep2 finishs first
12-
echo "dep2" >> out.txt
12+
echo -n "dep2" >> out.txt
1313

e2e/tests/dependencies/testdata/wait/dep2.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ dependencies:
88
pipelines:
99
deploy: |-
1010
run_dependencies --all
11-
echo "dep2" >> out.txt
11+
echo -n "dep2" >> out.txt
1212

e2e/tests/pipelines/pipelines.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package pipelines
22

33
import (
44
"context"
5+
"github.com/loft-sh/devspace/pkg/devspace/context/values"
56
"io/ioutil"
67
"os"
78
"time"
@@ -33,6 +34,41 @@ var _ = DevSpaceDescribe("pipelines", func() {
3334
framework.ExpectNoError(err)
3435
})
3536

37+
ginkgo.It("should resolve pipeline flags", func() {
38+
tempDir, err := framework.CopyToTempDir("tests/pipelines/testdata/flags")
39+
framework.ExpectNoError(err)
40+
defer framework.CleanupTempDir(initialDir, tempDir)
41+
42+
ns, err := kubeClient.CreateNamespace("pipelines")
43+
framework.ExpectNoError(err)
44+
defer framework.ExpectDeleteNamespace(kubeClient, ns)
45+
46+
devCmd := &cmd.RunPipelineCmd{
47+
GlobalFlags: &flags.GlobalFlags{
48+
NoWarn: true,
49+
Namespace: ns,
50+
},
51+
Pipeline: "dev",
52+
Ctx: values.WithFlagsMap(context.Background(), map[string]string{
53+
"test": "test",
54+
"test2": "",
55+
}),
56+
}
57+
err = devCmd.RunDefault(f)
58+
framework.ExpectNoError(err)
59+
60+
framework.ExpectLocalFileContentsImmediately("test.txt", "test\n")
61+
framework.ExpectLocalFileContentsImmediately("test2.txt", "\n")
62+
framework.ExpectLocalFileContentsImmediately("other.txt", "test\n")
63+
framework.ExpectLocalFileContentsImmediately("other2.txt", "false\n")
64+
framework.ExpectLocalFileContentsImmediately("other3.txt", "true\n")
65+
framework.ExpectLocalFileContentsImmediately("dep1-test.txt", "test\n")
66+
framework.ExpectLocalFileContentsImmediately("dep1-test2.txt", "true\n")
67+
framework.ExpectLocalFileContentsImmediately("dep1-other.txt", "test\n")
68+
framework.ExpectLocalFileContentsImmediately("dep1-other2.txt", "false\n")
69+
framework.ExpectLocalFileContentsImmediately("dep1-other3.txt", "false\n")
70+
})
71+
3672
ginkgo.It("should exec container", func() {
3773
tempDir, err := framework.CopyToTempDir("tests/pipelines/testdata/exec_container")
3874
framework.ExpectNoError(err)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
version: v2beta1
2+
name: dep1
3+
4+
pipelines:
5+
other:
6+
flags:
7+
- name: other
8+
default: test
9+
type: string
10+
- name: other2
11+
default: true
12+
- name: other3
13+
default: false
14+
run: |-
15+
if get_flag test; then
16+
exit 1
17+
fi
18+
19+
echo $(get_flag other) > dep1-other.txt
20+
echo $(get_flag other2) > dep1-other2.txt
21+
echo $(get_flag other3) > dep1-other3.txt
22+
23+
dev:
24+
flags:
25+
- name: test
26+
default: test
27+
type: string
28+
- name: test3
29+
run: |-
30+
echo $(get_flag test) > dep1-test.txt
31+
if get_flag test2; then
32+
exit 1
33+
fi
34+
echo $(get_flag test3) > dep1-test2.txt
35+
run_pipelines other --set-flag other2=false
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
version: v2beta1
2+
name: test
3+
4+
dependencies:
5+
dep1:
6+
path: dep1.yaml
7+
8+
pipelines:
9+
other:
10+
flags:
11+
- name: other
12+
default: test
13+
type: string
14+
- name: other2
15+
default: true
16+
- name: other3
17+
default: true
18+
run: |-
19+
if get_flag test; then
20+
exit 1
21+
fi
22+
23+
echo $(get_flag other) > other.txt
24+
echo $(get_flag other2) > other2.txt
25+
echo $(get_flag other3) > other3.txt
26+
27+
dev:
28+
flags:
29+
- name: test
30+
default: test
31+
type: string
32+
- name: test2
33+
run: |-
34+
echo "$(get_flag test)" > test.txt
35+
echo "$(get_flag test2)" > test2.txt
36+
37+
run_pipelines other --set-flag other2=false
38+
run_dependencies dep1 --set-flag test3=true --pipeline dev
39+
40+
41+
42+
43+

pkg/devspace/context/values/values.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package values
33
import (
44
"context"
55
flag "github.com/spf13/pflag"
6+
"strings"
67
)
78

89
// The key type is unexported to prevent collisions
@@ -18,14 +19,29 @@ const (
1819
flagsKey
1920
)
2021

21-
// WithFlags creates a new context with the dev context
22+
// WithFlagsMap creates a new context with the given flags
23+
func WithFlagsMap(parent context.Context, flagsMap map[string]string) context.Context {
24+
return WithValue(parent, flagsKey, flagsMap)
25+
}
26+
27+
// WithFlags creates a new context with the given flags
2228
func WithFlags(parent context.Context, flagSet *flag.FlagSet) context.Context {
23-
return WithValue(parent, flagsKey, flagSet)
29+
flagsMap := map[string]string{}
30+
flagSet.VisitAll(func(f *flag.Flag) {
31+
sliceType, ok := f.Value.(flag.SliceValue)
32+
if ok {
33+
flagsMap[f.Name] = strings.Join(sliceType.GetSlice(), " ")
34+
} else {
35+
flagsMap[f.Name] = f.Value.String()
36+
}
37+
})
38+
39+
return WithFlagsMap(parent, flagsMap)
2440
}
2541

2642
// FlagsFrom returns a context used to start and stop dev configurations
27-
func FlagsFrom(ctx context.Context) (*flag.FlagSet, bool) {
28-
flags, ok := ctx.Value(flagsKey).(*flag.FlagSet)
43+
func FlagsFrom(ctx context.Context) (map[string]string, bool) {
44+
flags, ok := ctx.Value(flagsKey).(map[string]string)
2945
return flags, ok
3046
}
3147

pkg/devspace/deploy/deployer/kubectl/builder.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ var useOldDryRun = func(ctx context.Context, dir, path string) (bool, error) {
8585

8686
v1, err := constraint.NewVersion(strings.TrimPrefix(strings.TrimSpace(string(out)), "Client Version: v"))
8787
if err != nil {
88-
89-
return false, err
88+
return false, nil
9089
}
9190

9291
v2, err := constraint.NewVersion("1.18.0")

pkg/devspace/pipeline/engine/basichandler/commands/get_flag.go

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import (
44
"context"
55
"fmt"
66
"github.com/loft-sh/devspace/pkg/devspace/context/values"
7-
flag "github.com/spf13/pflag"
87
"mvdan.cc/sh/v3/interp"
9-
"strings"
108
)
119

1210
func GetFlag(ctx context.Context, args []string) error {
@@ -22,19 +20,7 @@ func GetFlag(ctx context.Context, args []string) error {
2220
return interp.NewExitStatus(1)
2321
}
2422

25-
value := ""
26-
found := false
27-
flags.VisitAll(func(f *flag.Flag) {
28-
if !found && f.Name == args[0] {
29-
sliceType, ok := f.Value.(flag.SliceValue)
30-
if ok {
31-
value = strings.Join(sliceType.GetSlice(), " ")
32-
} else {
33-
value = f.Value.String()
34-
}
35-
found = true
36-
}
37-
})
23+
value, found := flags[args[0]]
3824
if !found {
3925
_, _ = hc.Stderr.Write([]byte(fmt.Sprintf("couldn't find flag %s", args[0])))
4026
return interp.NewExitStatus(1)

0 commit comments

Comments
 (0)