Skip to content

Commit 6a373d8

Browse files
committed
SKAFFOLD_UPDATE_CHECK should also be a global flag
Signed-off-by: David Gageot <[email protected]>
1 parent ac11549 commit 6a373d8

File tree

5 files changed

+29
-30
lines changed

5 files changed

+29
-30
lines changed

cmd/skaffold/app/cmd/cmd.go

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ var (
4545
forceColors bool
4646
overwrite bool
4747
interactive bool
48+
checkForUpdate bool
4849
shutdownAPIServer func() error
4950
)
5051

@@ -167,6 +168,7 @@ func NewSkaffoldCommand(out, err io.Writer) *cobra.Command {
167168
rootCmd.PersistentFlags().IntVar(&defaultColor, "color", int(color.DefaultColorCode), "Specify the default output color in ANSI escape codes")
168169
rootCmd.PersistentFlags().BoolVar(&forceColors, "force-colors", false, "Always print color codes (hidden)")
169170
rootCmd.PersistentFlags().BoolVar(&interactive, "interactive", true, "Allow user prompts for more information")
171+
rootCmd.PersistentFlags().BoolVar(&update.EnableCheck, "update-check", true, "Check for a more recent version of Skaffold")
170172
rootCmd.PersistentFlags().MarkHidden("force-colors")
171173

172174
setFlagsFromEnvVariables(rootCmd)

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

+2
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ Env vars:
9999

100100
* `SKAFFOLD_COLOR` (same as `--color`)
101101
* `SKAFFOLD_INTERACTIVE` (same as `--interactive`)
102+
* `SKAFFOLD_UPDATE_CHECK` (same as `--update-check`)
102103
* `SKAFFOLD_VERBOSITY` (same as `--verbosity`)
103104

104105
### skaffold build
@@ -697,6 +698,7 @@ The following options can be passed to any command:
697698
698699
--color=34: Specify the default output color in ANSI escape codes
699700
--interactive=true: Allow user prompts for more information
701+
--update-check=true: Check for a more recent version of Skaffold
700702
-v, --verbosity='warning': Log level (debug, info, warn, error, fatal, panic)
701703
702704

pkg/skaffold/constants/constants.go

-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ const (
5656
// DefaultDebugHelpersRegistry is the default location used for the helper images for `debug`.
5757
DefaultDebugHelpersRegistry = "gcr.io/gcp-dev-tools/duct-tape"
5858

59-
UpdateCheckEnvironmentVariable = "SKAFFOLD_UPDATE_CHECK"
60-
6159
DefaultSkaffoldDir = ".skaffold"
6260
DefaultCacheFile = "cache"
6361

pkg/skaffold/update/update.go

+4-11
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,22 @@ import (
2020
"fmt"
2121
"io/ioutil"
2222
"net/http"
23-
"os"
2423
"strings"
2524

2625
"github.com/blang/semver"
2726
"github.com/sirupsen/logrus"
2827

2928
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
30-
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
3129
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/version"
3230
)
3331

32+
// EnableCheck enabled the check for a more recent version of Skaffold.
33+
var EnableCheck bool
34+
3435
// For testing
3536
var (
3637
GetLatestAndCurrentVersion = getLatestAndCurrentVersion
3738
isConfigUpdateCheckEnabled = config.IsUpdateCheckEnabled
38-
getEnv = os.Getenv
3939
)
4040

4141
const LatestVersionURL = "https://storage.googleapis.com/skaffold/releases/latest/VERSION"
@@ -48,14 +48,7 @@ func IsUpdateCheckEnabled(configfile string) bool {
4848
return false
4949
}
5050

51-
return isUpdateCheckEnabledByEnvOrConfig(configfile)
52-
}
53-
54-
func isUpdateCheckEnabledByEnvOrConfig(configfile string) bool {
55-
if v := getEnv(constants.UpdateCheckEnvironmentVariable); v != "" {
56-
return strings.ToLower(v) == "true"
57-
}
58-
return isConfigUpdateCheckEnabled(configfile)
51+
return EnableCheck && isConfigUpdateCheckEnabled(configfile)
5952
}
6053

6154
// getLatestAndCurrentVersion uses a VERSION file stored on GCS to determine the latest released version

pkg/skaffold/update/update_test.go

+21-17
Original file line numberDiff line numberDiff line change
@@ -22,42 +22,46 @@ import (
2222
"github.com/GoogleContainerTools/skaffold/testutil"
2323
)
2424

25-
func TestIsUpdateCheckEnabledByEnvOrConfig(t *testing.T) {
25+
func TestIsUpdateCheckEnabled(t *testing.T) {
2626
tests := []struct {
2727
description string
28-
envVariable string
28+
enabled bool
2929
configCheck bool
3030
expected bool
3131
}{
3232
{
33-
description: "env variable is set to true",
34-
envVariable: "true",
35-
expected: true,
36-
},
37-
{
38-
description: "env variable is set to false",
39-
envVariable: "false",
33+
description: "globally disabled - disabled in config -> disabled",
34+
enabled: false,
35+
configCheck: false,
36+
expected: false,
4037
},
4138
{
42-
description: "env variable is set to random string",
43-
envVariable: "foo",
39+
description: "globally enabled - disabled in config -> disabled",
40+
enabled: true,
41+
configCheck: false,
42+
expected: false,
4443
},
4544
{
46-
description: "env variable is empty and config is enabled",
45+
description: "globally disabled - enabled in config -> disabled",
46+
enabled: false,
4747
configCheck: true,
48-
expected: true,
48+
expected: false,
4949
},
5050
{
51-
description: "env variable is false but Global update-check config is true",
52-
envVariable: "false",
51+
description: "globally enabled - enabled in config -> enabled",
52+
enabled: true,
5353
configCheck: true,
54+
expected: true,
5455
},
5556
}
5657
for _, test := range tests {
5758
testutil.Run(t, test.description, func(t *testutil.T) {
59+
t.Override(&EnableCheck, test.enabled)
5860
t.Override(&isConfigUpdateCheckEnabled, func(string) bool { return test.configCheck })
59-
t.Override(&getEnv, func(string) string { return test.envVariable })
60-
t.CheckDeepEqual(test.expected, isUpdateCheckEnabledByEnvOrConfig("dummyconfig"))
61+
62+
isEnabled := IsUpdateCheckEnabled("dummyconfig")
63+
64+
t.CheckDeepEqual(test.expected, isEnabled)
6165
})
6266
}
6367
}

0 commit comments

Comments
 (0)