From 78bc86ee1752d74610ebc90015d57b1a99cfe07c Mon Sep 17 00:00:00 2001 From: Cornelius Weig <22861411+corneliusweig@users.noreply.github.com> Date: Wed, 30 Jan 2019 23:19:56 +0100 Subject: [PATCH] Add new flag '--force' to run/deploy commands This flag controls, if resources may be re-created, if patching is not possible. Signed-off-by: Cornelius Weig <22861411+corneliusweig@users.noreply.github.com> --- cmd/skaffold/app/cmd/cmd.go | 1 + docs/content/en/docs/references/cli/_index.md | 4 ++++ pkg/skaffold/config/options.go | 1 + pkg/skaffold/runner/runner.go | 3 ++- 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd/skaffold/app/cmd/cmd.go b/cmd/skaffold/app/cmd/cmd.go index eeef1ed51de..c91b3c8d34e 100644 --- a/cmd/skaffold/app/cmd/cmd.go +++ b/cmd/skaffold/app/cmd/cmd.go @@ -142,6 +142,7 @@ func FlagToEnvVarName(f *pflag.Flag) string { func AddRunDeployFlags(cmd *cobra.Command) { cmd.Flags().BoolVar(&opts.Tail, "tail", false, "Stream logs from deployed objects") + cmd.Flags().BoolVar(&opts.ForceDeploy, "force", false, "Recreate kubernetes resources if necessary during deployment (warning: might cause downtime!)") cmd.Flags().StringArrayVarP(&opts.CustomLabels, "label", "l", nil, "Add custom labels to deployed objects. Set multiple times for multiple labels.") } diff --git a/docs/content/en/docs/references/cli/_index.md b/docs/content/en/docs/references/cli/_index.md index 77ddc788713..af17878e303 100644 --- a/docs/content/en/docs/references/cli/_index.md +++ b/docs/content/en/docs/references/cli/_index.md @@ -319,6 +319,7 @@ Flags: -d, --default-repo string Default repository value (overrides global config) --enable-rpc skaffold dev Enable gRPC for exposing Skaffold events (true by default for skaffold dev) -f, --filename string Filename or URL to the pipeline file (default "skaffold.yaml") + --force Recreate kubernetes resources if necessary during deployment (warning: might cause downtime!) --images strings A list of pre-built images to deploy -l, --label stringArray Add custom labels to deployed objects. Set multiple times for multiple labels. -n, --namespace string Run deployments in the specified namespace @@ -342,6 +343,7 @@ Env vars: * `SKAFFOLD_DEFAULT_REPO` (same as `--default-repo`) * `SKAFFOLD_ENABLE_RPC` (same as `--enable-rpc`) * `SKAFFOLD_FILENAME` (same as `--filename`) +* `SKAFFOLD_FORCE` (same as `--force`) * `SKAFFOLD_IMAGES` (same as `--images`) * `SKAFFOLD_LABEL` (same as `--label`) * `SKAFFOLD_NAMESPACE` (same as `--namespace`) @@ -501,6 +503,7 @@ Flags: -d, --default-repo string Default repository value (overrides global config) --enable-rpc skaffold dev Enable gRPC for exposing Skaffold events (true by default for skaffold dev) -f, --filename string Filename or URL to the pipeline file (default "skaffold.yaml") + --force Recreate kubernetes resources if necessary during deployment (warning: might cause downtime!) -l, --label stringArray Add custom labels to deployed objects. Set multiple times for multiple labels. -n, --namespace string Run deployments in the specified namespace -p, --profile stringArray Activate profiles by name @@ -524,6 +527,7 @@ Env vars: * `SKAFFOLD_DEFAULT_REPO` (same as `--default-repo`) * `SKAFFOLD_ENABLE_RPC` (same as `--enable-rpc`) * `SKAFFOLD_FILENAME` (same as `--filename`) +* `SKAFFOLD_FORCE` (same as `--force`) * `SKAFFOLD_LABEL` (same as `--label`) * `SKAFFOLD_NAMESPACE` (same as `--namespace`) * `SKAFFOLD_PROFILE` (same as `--profile`) diff --git a/pkg/skaffold/config/options.go b/pkg/skaffold/config/options.go index c665a54d6d0..12c76a98f64 100644 --- a/pkg/skaffold/config/options.go +++ b/pkg/skaffold/config/options.go @@ -40,6 +40,7 @@ type SkaffoldOptions struct { CacheArtifacts bool ExperimentalGUI bool EnableRPC bool + ForceDeploy bool Profiles []string CustomTag string Namespace string diff --git a/pkg/skaffold/runner/runner.go b/pkg/skaffold/runner/runner.go index e9b5783c40c..70687be8330 100644 --- a/pkg/skaffold/runner/runner.go +++ b/pkg/skaffold/runner/runner.go @@ -102,7 +102,8 @@ func NewForConfig(opts *config.SkaffoldOptions, cfg *latest.SkaffoldPipeline) (* return nil, errors.Wrap(err, "parsing test config") } - deployer, err := getDeployer(&cfg.Deploy, kubeContext, opts.Namespace, true, defaultRepo) + forceDeploy := opts.Command == "dev" || opts.ForceDeploy + deployer, err := getDeployer(&cfg.Deploy, kubeContext, opts.Namespace, forceDeploy, defaultRepo) if err != nil { return nil, errors.Wrap(err, "parsing deploy config") }