From 9c6fb45551ccfd5d99b23e8534a0810914e7b9b7 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Wed, 29 Apr 2020 18:33:38 +0200 Subject: [PATCH] Disable profiles with the command line Fixes #3988 Signed-off-by: David Gageot --- cmd/skaffold/app/cmd/flags.go | 2 +- docs/content/en/docs/references/cli/_index.md | 16 +++++++-------- pkg/skaffold/schema/profiles.go | 20 ++++++++++++++++++- pkg/skaffold/schema/profiles_test.go | 13 ++++++++++++ 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/cmd/skaffold/app/cmd/flags.go b/cmd/skaffold/app/cmd/flags.go index d197dc6be1f..1ce7f9116a2 100644 --- a/cmd/skaffold/app/cmd/flags.go +++ b/cmd/skaffold/app/cmd/flags.go @@ -56,7 +56,7 @@ var FlagRegistry = []Flag{ { Name: "profile", Shorthand: "p", - Usage: "Activate profiles by name", + Usage: "Activate profiles by name (prefixed with `-` to disable a profile)", Value: &opts.Profiles, DefValue: []string{}, FlagAddMethod: "StringSliceVar", diff --git a/docs/content/en/docs/references/cli/_index.md b/docs/content/en/docs/references/cli/_index.md index 0ee40e83fda..8e77f6ae02c 100644 --- a/docs/content/en/docs/references/cli/_index.md +++ b/docs/content/en/docs/references/cli/_index.md @@ -141,7 +141,7 @@ Options: --kubeconfig='': Path to the kubeconfig file to use for CLI requests. -n, --namespace='': Run deployments in the specified namespace -o, --output={{json .}}: Used in conjunction with --quiet flag. Format output with go-template. For full struct documentation, see https://godoc.org/github.com/GoogleContainerTools/skaffold/cmd/skaffold/app/flags#BuildOutput - -p, --profile=[]: Activate profiles by name + -p, --profile=[]: Activate profiles by name (prefixed with `-` to disable a profile) --profile-auto-activation=true: Set to false to disable profile auto activation -q, --quiet=false: Suppress the build output and print image built on success. See --output to format output. --rpc-http-port=50052: tcp port to expose event REST API over HTTP @@ -348,7 +348,7 @@ Options: --no-prune=false: Skip removing images and containers built by Skaffold --no-prune-children=false: Skip removing layers reused by Skaffold --port-forward=false: Port-forward exposed container ports within pods - -p, --profile=[]: Activate profiles by name + -p, --profile=[]: Activate profiles by name (prefixed with `-` to disable a profile) --profile-auto-activation=true: Set to false to disable profile auto activation --rpc-http-port=50052: tcp port to expose event REST API over HTTP --rpc-port=50051: tcp port to expose event API @@ -407,7 +407,7 @@ Options: --kube-context='': Deploy to this Kubernetes context --kubeconfig='': Path to the kubeconfig file to use for CLI requests. -n, --namespace='': Run deployments in the specified namespace - -p, --profile=[]: Activate profiles by name + -p, --profile=[]: Activate profiles by name (prefixed with `-` to disable a profile) --profile-auto-activation=true: Set to false to disable profile auto activation Usage: @@ -459,7 +459,7 @@ E.g. build.out created by running skaffold build --quiet -o "{{json .}}" > build -l, --label=[]: Add custom labels to deployed objects. Set multiple times for multiple labels -n, --namespace='': Run deployments in the specified namespace --port-forward=false: Port-forward exposed container ports within pods - -p, --profile=[]: Activate profiles by name + -p, --profile=[]: Activate profiles by name (prefixed with `-` to disable a profile) --profile-auto-activation=true: Set to false to disable profile auto activation --rpc-http-port=50052: tcp port to expose event REST API over HTTP --rpc-port=50051: tcp port to expose event API @@ -520,7 +520,7 @@ Options: --no-prune=false: Skip removing images and containers built by Skaffold --no-prune-children=false: Skip removing layers reused by Skaffold --port-forward=false: Port-forward exposed container ports within pods - -p, --profile=[]: Activate profiles by name + -p, --profile=[]: Activate profiles by name (prefixed with `-` to disable a profile) --profile-auto-activation=true: Set to false to disable profile auto activation --render-only=false: Print rendered Kubernetes manifests instead of deploying them --rpc-http-port=50052: tcp port to expose event REST API over HTTP @@ -583,7 +583,7 @@ Run a diagnostic on Skaffold Options: -c, --config='': File for global configurations (defaults to $HOME/.skaffold/config) -f, --filename='skaffold.yaml': Path or URL to the Skaffold config file - -p, --profile=[]: Activate profiles by name + -p, --profile=[]: Activate profiles by name (prefixed with `-` to disable a profile) --profile-auto-activation=true: Set to false to disable profile auto activation Usage: @@ -693,7 +693,7 @@ Options: --loud=false: Show the build logs and output -n, --namespace='': Run deployments in the specified namespace --output='': file to write rendered manifests to - -p, --profile=[]: Activate profiles by name + -p, --profile=[]: Activate profiles by name (prefixed with `-` to disable a profile) --profile-auto-activation=true: Set to false to disable profile auto activation Usage: @@ -745,7 +745,7 @@ Options: --no-prune=false: Skip removing images and containers built by Skaffold --no-prune-children=false: Skip removing layers reused by Skaffold --port-forward=false: Port-forward exposed container ports within pods - -p, --profile=[]: Activate profiles by name + -p, --profile=[]: Activate profiles by name (prefixed with `-` to disable a profile) --profile-auto-activation=true: Set to false to disable profile auto activation --render-only=false: Print rendered Kubernetes manifests instead of deploying them --rpc-http-port=50052: tcp port to expose event REST API over HTTP diff --git a/pkg/skaffold/schema/profiles.go b/pkg/skaffold/schema/profiles.go index 77150768033..7ab821a3c5d 100644 --- a/pkg/skaffold/schema/profiles.go +++ b/pkg/skaffold/schema/profiles.go @@ -110,11 +110,29 @@ func activatedProfiles(profiles []latest.Profile, opts cfg.SkaffoldOptions) ([]s } } - activated = append(activated, opts.Profiles...) + for _, profile := range opts.Profiles { + if strings.HasPrefix(profile, "-") { + activated = removeValue(activated, strings.TrimPrefix(profile, "-")) + } else { + activated = append(activated, profile) + } + } return activated, contextSpecificProfiles, nil } +func removeValue(values []string, value string) []string { + var updated []string + + for _, v := range values { + if v != value { + updated = append(updated, v) + } + } + + return updated +} + func isEnv(env string) (bool, error) { if env == "" { return true, nil diff --git a/pkg/skaffold/schema/profiles_test.go b/pkg/skaffold/schema/profiles_test.go index 16f30b35506..26391560465 100644 --- a/pkg/skaffold/schema/profiles_test.go +++ b/pkg/skaffold/schema/profiles_test.go @@ -730,6 +730,19 @@ func TestActivatedProfiles(t *testing.T) { }, expected: []string{"activated", "also-activated"}, }, + { + description: "Disabled on the command line", + opts: cfg.SkaffoldOptions{ + ProfileAutoActivation: true, + Command: "dev", + Profiles: []string{"-dev-profile"}, + }, + profiles: []latest.Profile{ + {Name: "dev-profile", Activation: []latest.Activation{{Command: "dev"}}}, + {Name: "run-or-dev-profile", Activation: []latest.Activation{{Command: "(run)|(dev)"}}}, + }, + expected: []string{"run-or-dev-profile"}, + }, } for _, test := range tests {