Skip to content

Commit

Permalink
Disable profiles with the command line
Browse files Browse the repository at this point in the history
Fixes GoogleContainerTools#3988

Signed-off-by: David Gageot <[email protected]>
  • Loading branch information
dgageot committed Apr 29, 2020
1 parent e4640d5 commit 9c6fb45
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
2 changes: 1 addition & 1 deletion cmd/skaffold/app/cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 8 additions & 8 deletions docs/content/en/docs/references/cli/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
20 changes: 19 additions & 1 deletion pkg/skaffold/schema/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions pkg/skaffold/schema/profiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 9c6fb45

Please sign in to comment.