Skip to content

Commit efee084

Browse files
authored
Merge pull request #4054 from dgageot/fix-3988
Disable profiles with the command line
2 parents ecf7c71 + 9c6fb45 commit efee084

File tree

4 files changed

+41
-10
lines changed

4 files changed

+41
-10
lines changed

cmd/skaffold/app/cmd/flags.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ var FlagRegistry = []Flag{
5656
{
5757
Name: "profile",
5858
Shorthand: "p",
59-
Usage: "Activate profiles by name",
59+
Usage: "Activate profiles by name (prefixed with `-` to disable a profile)",
6060
Value: &opts.Profiles,
6161
DefValue: []string{},
6262
FlagAddMethod: "StringSliceVar",

docs/content/en/docs/references/cli/_index.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ Options:
141141
--kubeconfig='': Path to the kubeconfig file to use for CLI requests.
142142
-n, --namespace='': Run deployments in the specified namespace
143143
-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
144-
-p, --profile=[]: Activate profiles by name
144+
-p, --profile=[]: Activate profiles by name (prefixed with `-` to disable a profile)
145145
--profile-auto-activation=true: Set to false to disable profile auto activation
146146
-q, --quiet=false: Suppress the build output and print image built on success. See --output to format output.
147147
--rpc-http-port=50052: tcp port to expose event REST API over HTTP
@@ -348,7 +348,7 @@ Options:
348348
--no-prune=false: Skip removing images and containers built by Skaffold
349349
--no-prune-children=false: Skip removing layers reused by Skaffold
350350
--port-forward=false: Port-forward exposed container ports within pods
351-
-p, --profile=[]: Activate profiles by name
351+
-p, --profile=[]: Activate profiles by name (prefixed with `-` to disable a profile)
352352
--profile-auto-activation=true: Set to false to disable profile auto activation
353353
--rpc-http-port=50052: tcp port to expose event REST API over HTTP
354354
--rpc-port=50051: tcp port to expose event API
@@ -407,7 +407,7 @@ Options:
407407
--kube-context='': Deploy to this Kubernetes context
408408
--kubeconfig='': Path to the kubeconfig file to use for CLI requests.
409409
-n, --namespace='': Run deployments in the specified namespace
410-
-p, --profile=[]: Activate profiles by name
410+
-p, --profile=[]: Activate profiles by name (prefixed with `-` to disable a profile)
411411
--profile-auto-activation=true: Set to false to disable profile auto activation
412412
413413
Usage:
@@ -459,7 +459,7 @@ E.g. build.out created by running skaffold build --quiet -o "{{json .}}" > build
459459
-l, --label=[]: Add custom labels to deployed objects. Set multiple times for multiple labels
460460
-n, --namespace='': Run deployments in the specified namespace
461461
--port-forward=false: Port-forward exposed container ports within pods
462-
-p, --profile=[]: Activate profiles by name
462+
-p, --profile=[]: Activate profiles by name (prefixed with `-` to disable a profile)
463463
--profile-auto-activation=true: Set to false to disable profile auto activation
464464
--rpc-http-port=50052: tcp port to expose event REST API over HTTP
465465
--rpc-port=50051: tcp port to expose event API
@@ -520,7 +520,7 @@ Options:
520520
--no-prune=false: Skip removing images and containers built by Skaffold
521521
--no-prune-children=false: Skip removing layers reused by Skaffold
522522
--port-forward=false: Port-forward exposed container ports within pods
523-
-p, --profile=[]: Activate profiles by name
523+
-p, --profile=[]: Activate profiles by name (prefixed with `-` to disable a profile)
524524
--profile-auto-activation=true: Set to false to disable profile auto activation
525525
--render-only=false: Print rendered Kubernetes manifests instead of deploying them
526526
--rpc-http-port=50052: tcp port to expose event REST API over HTTP
@@ -583,7 +583,7 @@ Run a diagnostic on Skaffold
583583
Options:
584584
-c, --config='': File for global configurations (defaults to $HOME/.skaffold/config)
585585
-f, --filename='skaffold.yaml': Path or URL to the Skaffold config file
586-
-p, --profile=[]: Activate profiles by name
586+
-p, --profile=[]: Activate profiles by name (prefixed with `-` to disable a profile)
587587
--profile-auto-activation=true: Set to false to disable profile auto activation
588588
589589
Usage:
@@ -693,7 +693,7 @@ Options:
693693
--loud=false: Show the build logs and output
694694
-n, --namespace='': Run deployments in the specified namespace
695695
--output='': file to write rendered manifests to
696-
-p, --profile=[]: Activate profiles by name
696+
-p, --profile=[]: Activate profiles by name (prefixed with `-` to disable a profile)
697697
--profile-auto-activation=true: Set to false to disable profile auto activation
698698
699699
Usage:
@@ -745,7 +745,7 @@ Options:
745745
--no-prune=false: Skip removing images and containers built by Skaffold
746746
--no-prune-children=false: Skip removing layers reused by Skaffold
747747
--port-forward=false: Port-forward exposed container ports within pods
748-
-p, --profile=[]: Activate profiles by name
748+
-p, --profile=[]: Activate profiles by name (prefixed with `-` to disable a profile)
749749
--profile-auto-activation=true: Set to false to disable profile auto activation
750750
--render-only=false: Print rendered Kubernetes manifests instead of deploying them
751751
--rpc-http-port=50052: tcp port to expose event REST API over HTTP

pkg/skaffold/schema/profiles.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,29 @@ func activatedProfiles(profiles []latest.Profile, opts cfg.SkaffoldOptions) ([]s
110110
}
111111
}
112112

113-
activated = append(activated, opts.Profiles...)
113+
for _, profile := range opts.Profiles {
114+
if strings.HasPrefix(profile, "-") {
115+
activated = removeValue(activated, strings.TrimPrefix(profile, "-"))
116+
} else {
117+
activated = append(activated, profile)
118+
}
119+
}
114120

115121
return activated, contextSpecificProfiles, nil
116122
}
117123

124+
func removeValue(values []string, value string) []string {
125+
var updated []string
126+
127+
for _, v := range values {
128+
if v != value {
129+
updated = append(updated, v)
130+
}
131+
}
132+
133+
return updated
134+
}
135+
118136
func isEnv(env string) (bool, error) {
119137
if env == "" {
120138
return true, nil

pkg/skaffold/schema/profiles_test.go

+13
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,19 @@ func TestActivatedProfiles(t *testing.T) {
730730
},
731731
expected: []string{"activated", "also-activated"},
732732
},
733+
{
734+
description: "Disabled on the command line",
735+
opts: cfg.SkaffoldOptions{
736+
ProfileAutoActivation: true,
737+
Command: "dev",
738+
Profiles: []string{"-dev-profile"},
739+
},
740+
profiles: []latest.Profile{
741+
{Name: "dev-profile", Activation: []latest.Activation{{Command: "dev"}}},
742+
{Name: "run-or-dev-profile", Activation: []latest.Activation{{Command: "(run)|(dev)"}}},
743+
},
744+
expected: []string{"run-or-dev-profile"},
745+
},
733746
}
734747

735748
for _, test := range tests {

0 commit comments

Comments
 (0)