Skip to content

Commit

Permalink
Apply feedback
Browse files Browse the repository at this point in the history
Signed-off-by: David Gageot <[email protected]>
  • Loading branch information
dgageot committed Jan 31, 2019
1 parent 8844ca2 commit 2522d70
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
11 changes: 5 additions & 6 deletions integration/examples/annotated-skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -225,16 +225,15 @@ profiles:
- name: other
# profiles can also patch some values using standard JSON patch notation
patches:
# This profile will replace the `dockerfile` value of the first artifact by `Dockerfile.DEV`
- path: /build/artifacts/0/docker/dockerfile
value: Dockerfile.DEV
# profiles can be auto-activated by external factors, like environment variables
# kubeContext value or depending on which skaffold command is run.
activation:
# Auto-activate this profile if the DEBUG env variable is set to `true` and the
# kubeContect is `ctx1`
#- env: DEBUG=true
# kubeContext: ctx1
# Also auto-activate `skaffold dev` is run
# Auto-activate this profile if the DEBUG env variable is set to `true` AND the kubeContext is `ctx1`
# - env: DEBUG=true
# kubeContext: ctx1
# Auto-activate if the skaffold command is `skaffold run` OR if the kubeContext is NOT `ctx2`
# - command: run
# Also auto-activate is the kubeContext is NOT `ctx2`
# - kubeContext: "!ctx2"
8 changes: 4 additions & 4 deletions pkg/skaffold/schema/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ func isEnv(env string) (bool, error) {
key := keyValue[0]
value := keyValue[1]

return equalValue(value, os.Getenv(key)), nil
return satisfies(value, os.Getenv(key)), nil
}

func isCommand(command string, opts *cfg.SkaffoldOptions) bool {
if command == "" {
return true
}

return equalValue(command, opts.Command)
return satisfies(command, opts.Command)
}

func isKubeContext(kubeContext string) (bool, error) {
Expand All @@ -115,10 +115,10 @@ func isKubeContext(kubeContext string) (bool, error) {
return false, errors.Wrap(err, "getting current cluster context")
}

return equalValue(kubeContext, currentKubeContext), nil
return satisfies(kubeContext, currentKubeContext), nil
}

func equalValue(expected, actual string) bool {
func satisfies(expected, actual string) bool {
if strings.HasPrefix(expected, "!") {
return actual != expected[1:]
}
Expand Down
17 changes: 16 additions & 1 deletion pkg/skaffold/schema/profiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func TestActivatedProfiles(t *testing.T) {
},
expected: []string{"activated", "also-activated"},
}, {
description: "Auto-activated by combination",
description: "AND between activation criteria",
opts: &cfg.SkaffoldOptions{
Command: "dev",
},
Expand All @@ -295,6 +295,21 @@ func TestActivatedProfiles(t *testing.T) {
},
},
expected: []string{"activated"},
}, {
description: "OR between activations",
opts: &cfg.SkaffoldOptions{
Command: "dev",
},
profiles: []latest.Profile{
{
Name: "activated", Activation: []latest.Activation{{
Command: "run",
}, {
Command: "dev",
}},
},
},
expected: []string{"activated"},
},
}

Expand Down

0 comments on commit 2522d70

Please sign in to comment.