Skip to content

Add CLI option --profile-auto-activation to allow disabling automatic profile activation. #4034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions cmd/skaffold/app/cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,14 @@ var FlagRegistry = []Flag{
FlagAddMethod: "StringVar",
DefinedOn: []string{"build", "debug", "dev", "run"},
},
{
Name: "profile-auto-activation",
Usage: "Set to false to disable profile auto activation",
Value: &opts.ProfileAutoActivation,
DefValue: true,
FlagAddMethod: "BoolVar",
DefinedOn: []string{"dev", "run", "debug", "deploy", "render", "build", "delete", "diagnose"},
},
}

var commandFlags []*pflag.Flag
Expand Down
16 changes: 16 additions & 0 deletions docs/content/en/docs/references/cli/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ Options:
-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
--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
--rpc-port=50051: tcp port to expose event API
Expand Down Expand Up @@ -167,6 +168,7 @@ Env vars:
* `SKAFFOLD_NAMESPACE` (same as `--namespace`)
* `SKAFFOLD_OUTPUT` (same as `--output`)
* `SKAFFOLD_PROFILE` (same as `--profile`)
* `SKAFFOLD_PROFILE_AUTO_ACTIVATION` (same as `--profile-auto-activation`)
* `SKAFFOLD_QUIET` (same as `--quiet`)
* `SKAFFOLD_RPC_HTTP_PORT` (same as `--rpc-http-port`)
* `SKAFFOLD_RPC_PORT` (same as `--rpc-port`)
Expand Down Expand Up @@ -341,6 +343,7 @@ Options:
--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
--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
--skip-tests=false: Whether to skip the tests after building
Expand Down Expand Up @@ -375,6 +378,7 @@ Env vars:
* `SKAFFOLD_NO_PRUNE_CHILDREN` (same as `--no-prune-children`)
* `SKAFFOLD_PORT_FORWARD` (same as `--port-forward`)
* `SKAFFOLD_PROFILE` (same as `--profile`)
* `SKAFFOLD_PROFILE_AUTO_ACTIVATION` (same as `--profile-auto-activation`)
* `SKAFFOLD_RPC_HTTP_PORT` (same as `--rpc-http-port`)
* `SKAFFOLD_RPC_PORT` (same as `--rpc-port`)
* `SKAFFOLD_SKIP_TESTS` (same as `--skip-tests`)
Expand All @@ -398,6 +402,7 @@ Options:
--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
--profile-auto-activation=true: Set to false to disable profile auto activation

Usage:
skaffold delete [options]
Expand All @@ -415,6 +420,7 @@ Env vars:
* `SKAFFOLD_KUBECONFIG` (same as `--kubeconfig`)
* `SKAFFOLD_NAMESPACE` (same as `--namespace`)
* `SKAFFOLD_PROFILE` (same as `--profile`)
* `SKAFFOLD_PROFILE_AUTO_ACTIVATION` (same as `--profile-auto-activation`)

### skaffold deploy

Expand Down Expand Up @@ -448,6 +454,7 @@ E.g. build.out created by running skaffold build --quiet -o "{{json .}}" > build
-n, --namespace='': Run deployments in the specified namespace
--port-forward=false: Port-forward exposed container ports within pods
-p, --profile=[]: Activate profiles by name
--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
--status-check=true: Wait for deployed resources to stabilize
Expand Down Expand Up @@ -476,6 +483,7 @@ Env vars:
* `SKAFFOLD_NAMESPACE` (same as `--namespace`)
* `SKAFFOLD_PORT_FORWARD` (same as `--port-forward`)
* `SKAFFOLD_PROFILE` (same as `--profile`)
* `SKAFFOLD_PROFILE_AUTO_ACTIVATION` (same as `--profile-auto-activation`)
* `SKAFFOLD_RPC_HTTP_PORT` (same as `--rpc-http-port`)
* `SKAFFOLD_RPC_PORT` (same as `--rpc-port`)
* `SKAFFOLD_STATUS_CHECK` (same as `--status-check`)
Expand Down Expand Up @@ -507,6 +515,7 @@ Options:
--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
--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
--rpc-port=50051: tcp port to expose event API
Expand Down Expand Up @@ -545,6 +554,7 @@ Env vars:
* `SKAFFOLD_NO_PRUNE_CHILDREN` (same as `--no-prune-children`)
* `SKAFFOLD_PORT_FORWARD` (same as `--port-forward`)
* `SKAFFOLD_PROFILE` (same as `--profile`)
* `SKAFFOLD_PROFILE_AUTO_ACTIVATION` (same as `--profile-auto-activation`)
* `SKAFFOLD_RENDER_ONLY` (same as `--render-only`)
* `SKAFFOLD_RPC_HTTP_PORT` (same as `--rpc-http-port`)
* `SKAFFOLD_RPC_PORT` (same as `--rpc-port`)
Expand All @@ -568,6 +578,7 @@ 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
--profile-auto-activation=true: Set to false to disable profile auto activation

Usage:
skaffold diagnose [options]
Expand All @@ -581,6 +592,7 @@ Env vars:
* `SKAFFOLD_CONFIG` (same as `--config`)
* `SKAFFOLD_FILENAME` (same as `--filename`)
* `SKAFFOLD_PROFILE` (same as `--profile`)
* `SKAFFOLD_PROFILE_AUTO_ACTIVATION` (same as `--profile-auto-activation`)

### skaffold fix

Expand Down Expand Up @@ -676,6 +688,7 @@ Options:
-n, --namespace='': Run deployments in the specified namespace
--output='': file to write rendered manifests to
-p, --profile=[]: Activate profiles by name
--profile-auto-activation=true: Set to false to disable profile auto activation

Usage:
skaffold render [options]
Expand All @@ -693,6 +706,7 @@ Env vars:
* `SKAFFOLD_NAMESPACE` (same as `--namespace`)
* `SKAFFOLD_OUTPUT` (same as `--output`)
* `SKAFFOLD_PROFILE` (same as `--profile`)
* `SKAFFOLD_PROFILE_AUTO_ACTIVATION` (same as `--profile-auto-activation`)

### skaffold run

Expand Down Expand Up @@ -726,6 +740,7 @@ Options:
--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
--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
--rpc-port=50051: tcp port to expose event API
Expand Down Expand Up @@ -761,6 +776,7 @@ Env vars:
* `SKAFFOLD_NO_PRUNE_CHILDREN` (same as `--no-prune-children`)
* `SKAFFOLD_PORT_FORWARD` (same as `--port-forward`)
* `SKAFFOLD_PROFILE` (same as `--profile`)
* `SKAFFOLD_PROFILE_AUTO_ACTIVATION` (same as `--profile-auto-activation`)
* `SKAFFOLD_RENDER_ONLY` (same as `--render-only`)
* `SKAFFOLD_RPC_HTTP_PORT` (same as `--rpc-http-port`)
* `SKAFFOLD_RPC_PORT` (same as `--rpc-port`)
Expand Down
68 changes: 34 additions & 34 deletions pkg/skaffold/config/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,40 +32,40 @@ type PortForwardOptions struct {
// SkaffoldOptions are options that are set by command line arguments not included
// in the config file itself
type SkaffoldOptions struct {
ConfigurationFile string
GlobalConfig string
Cleanup bool
Notification bool
Tail bool
TailDev bool
SkipTests bool
CacheArtifacts bool
EnableRPC bool
Force bool
NoPrune bool
NoPruneChildren bool
StatusCheck bool
AutoBuild bool
AutoSync bool
AutoDeploy bool
RenderOnly bool
PortForward PortForwardOptions
CustomTag string
Namespace string
CacheFile string
Trigger string
KubeContext string
KubeConfig string
WatchPollInterval int
DefaultRepo StringOrUndefined
CustomLabels []string
TargetImages []string
Profiles []string
InsecureRegistries []string
Command string
RPCPort int
RPCHTTPPort int

ConfigurationFile string
GlobalConfig string
Cleanup bool
Notification bool
Tail bool
TailDev bool
SkipTests bool
CacheArtifacts bool
EnableRPC bool
Force bool
NoPrune bool
NoPruneChildren bool
StatusCheck bool
AutoBuild bool
AutoSync bool
AutoDeploy bool
RenderOnly bool
ProfileAutoActivation bool
PortForward PortForwardOptions
CustomTag string
Namespace string
CacheFile string
Trigger string
KubeContext string
KubeConfig string
WatchPollInterval int
DefaultRepo StringOrUndefined
CustomLabels []string
TargetImages []string
Profiles []string
InsecureRegistries []string
Command string
RPCPort int
RPCHTTPPort int
// TODO(https://github.com/GoogleContainerTools/skaffold/issues/3668):
// remove minikubeProfile from here and instead detect it by matching the
// kubecontext API Server to minikube profiles
Expand Down
36 changes: 19 additions & 17 deletions pkg/skaffold/schema/profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,28 @@ func activatedProfiles(profiles []latest.Profile, opts cfg.SkaffoldOptions) ([]s
var activated []string
var contextSpecificProfiles []string

// Auto-activated profiles
for _, profile := range profiles {
for _, cond := range profile.Activation {
command := isCommand(cond.Command, opts)

env, err := isEnv(cond.Env)
if err != nil {
return nil, nil, err
}
if opts.ProfileAutoActivation {
// Auto-activated profiles
for _, profile := range profiles {
for _, cond := range profile.Activation {
command := isCommand(cond.Command, opts)

env, err := isEnv(cond.Env)
if err != nil {
return nil, nil, err
}

kubeContext, err := isKubeContext(cond.KubeContext, opts)
if err != nil {
return nil, nil, err
}
kubeContext, err := isKubeContext(cond.KubeContext, opts)
if err != nil {
return nil, nil, err
}

if command && env && kubeContext {
if cond.KubeContext != "" {
contextSpecificProfiles = append(contextSpecificProfiles, profile.Name)
if command && env && kubeContext {
if cond.KubeContext != "" {
contextSpecificProfiles = append(contextSpecificProfiles, profile.Name)
}
activated = append(activated, profile.Name)
}
activated = append(activated, profile.Name)
}
}
}
Expand Down
Loading