Skip to content
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

Merge back release/v0.37.1 #2800

Merged
merged 2 commits into from Sep 4, 2019
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,9 @@
# v0.37.1 Release - 09/04/2019

This is a minor release for a privacy policy update:

* add privacy notice and command to set update check false [#2774](https://github.com/GoogleContainerTools/skaffold/pull/2774)

# v0.37.0 Release - 08/29/2019

No new features in this release!
Expand Down
8 changes: 3 additions & 5 deletions cmd/skaffold/app/cmd/cmd.go
Expand Up @@ -100,7 +100,7 @@ func NewSkaffoldCommand(out, err io.Writer) *cobra.Command {
logrus.Debugf("Update check is disabled because of quiet mode")
} else {
go func() {
if err := updateCheck(updateMsg); err != nil {
if err := updateCheck(updateMsg, opts.GlobalConfig); err != nil {
logrus.Infof("update check failed: %s", err)
}
}()
Expand All @@ -121,8 +121,6 @@ func NewSkaffoldCommand(out, err io.Writer) *cobra.Command {
},
}

SetUpFlags()

groups := templates.CommandGroups{
{
Message: "End-to-end pipelines:",
Expand Down Expand Up @@ -183,8 +181,8 @@ func NewCmdOptions() *cobra.Command {
return cmd
}

func updateCheck(ch chan string) error {
if !update.IsUpdateCheckEnabled() {
func updateCheck(ch chan string, configfile string) error {
if !update.IsUpdateCheckEnabled(configfile) {
logrus.Debugf("Update check not enabled, skipping.")
return nil
}
Expand Down
14 changes: 14 additions & 0 deletions cmd/skaffold/app/cmd/config/set_test.go
Expand Up @@ -146,6 +146,20 @@ func TestSetAndUnsetConfig(t *testing.T) {
},
},
},
{
description: "set global update-check",
key: "update-check",
value: "true",
global: true,
expectedSetCfg: &config.GlobalConfig{
Global: &config.ContextConfig{UpdateCheck: util.BoolPtr(true)},
ContextConfigs: []*config.ContextConfig{},
},
expectedUnsetCfg: &config.GlobalConfig{
Global: &config.ContextConfig{},
ContextConfigs: []*config.ContextConfig{},
},
},
}
for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
Expand Down
11 changes: 6 additions & 5 deletions cmd/skaffold/app/cmd/flags.go
Expand Up @@ -250,8 +250,8 @@ var FlagRegistry = []Flag{

var commandFlags []*pflag.Flag

// SetUpFlags creates pflag.Flag for all registered flags
func SetUpFlags() {
// SetupFlags creates pflag.Flag for all registered flags
func SetupFlags() {
commandFlags = make([]*pflag.Flag, len(FlagRegistry))
for i, fl := range FlagRegistry {
fs := pflag.NewFlagSet(fl.Name, pflag.ContinueOnError)
Expand All @@ -274,9 +274,6 @@ func SetUpFlags() {
}

func AddFlags(fs *pflag.FlagSet, cmdName string) {
if len(commandFlags) == 0 {
SetUpFlags()
}
for _, f := range commandFlags {
if hasCmdAnnotation(cmdName, f.Annotations["cmds"]) {
fs.AddFlag(f)
Expand All @@ -293,3 +290,7 @@ func hasCmdAnnotation(cmdName string, annotations []string) bool {
}
return false
}

func init() {
SetupFlags()
}
2 changes: 1 addition & 1 deletion cmd/skaffold/app/cmd/flags_test.go
Expand Up @@ -62,6 +62,6 @@ func TestAddFlagsSmoke(t *testing.T) {
Use: "test",
Short: "Test commanf for smoke testing",
}
SetUpFlags()
SetupFlags()
AddFlags(testCmd.Flags(), "test")
}
4 changes: 2 additions & 2 deletions docs/config.toml
Expand Up @@ -67,8 +67,8 @@ weight = 1
# Everything below this are Site Params

[params]
#copyright = "Skaffold"
#privacy_policy = "https://policies.google.com/privacy"
copyright = "Skaffold Authors"
privacy_policy = "https://policies.google.com/privacy"
github_repo = "https://github.com/GoogleContainerTools/skaffold"
skaffold_version = "skaffold/v1beta13"

Expand Down
10 changes: 10 additions & 0 deletions docs/content/en/docs/getting-started/_index.md
Expand Up @@ -145,6 +145,16 @@ For the latest **bleeding edge** build:

{{% /tabs %}}

{{< alert title="Note" >}}
To keep Skaffold up to date, update checks are made to Google servers to see if a new version of
Skaffold is available.

You can turn this update check off by following <a href=/docs/references/privacy/#update-check>these instructions</a>.


Your use of this software is subject to the <a href=https://policies.google.com/privacy>Google Privacy Policy</a>
{{< /alert >}}

## Downloading the sample app

1. Clone the Skaffold repository:
Expand Down
1 change: 1 addition & 0 deletions docs/content/en/docs/references/_index.md
Expand Up @@ -8,4 +8,5 @@ weight: 100
|----------|
| [CLI](/docs/references/cli) |
| [skaffold.yaml](/docs/references/yaml) |
| [Privacy Settings] (/docs/references/privacy) |

21 changes: 21 additions & 0 deletions docs/content/en/docs/references/privacy/_index.md
@@ -0,0 +1,21 @@
---
title: "Privacy Settings"
linkTitle: "Privacy Settings"
weight: 300
---

The privacy of our users is very important to us.
Your use of this software is subject to the <a href=https://policies.google.com/privacy>Google Privacy Policy</a>.

## Update check

To keep Skaffold up to date, update checks are made to Google servers to see if a new version of
Skaffold is available. By default, this behavior is enabled. As a side effect this request is logged.

To disable the update check you have two options:

1. set the `SKAFFOLD_UPDATE_CHECK` environment variable to `false`
2. turn it off in skaffold's global config with:
```bash
skaffold config set -g update-check false
```
1 change: 1 addition & 0 deletions pkg/skaffold/config/global_config.go
Expand Up @@ -30,4 +30,5 @@ type ContextConfig struct {
DefaultRepo string `yaml:"default-repo,omitempty"`
LocalCluster *bool `yaml:"local-cluster,omitempty"`
InsecureRegistries []string `yaml:"insecure-registries,omitempty"`
UpdateCheck *bool `yaml:"update-check,omitempty"`
}
4 changes: 2 additions & 2 deletions pkg/skaffold/config/options_test.go
Expand Up @@ -130,12 +130,12 @@ func TestIsTargetImage(t *testing.T) {
expectedMatch: true,
},
{
description: "match full name",
description: "match full description",
targetImages: []string{"domain/image"},
expectedMatch: true,
},
{
description: "match partial name",
description: "match partial description",
targetImages: []string{"image"},
expectedMatch: true,
},
Expand Down
13 changes: 11 additions & 2 deletions pkg/skaffold/config/util.go
Expand Up @@ -49,7 +49,8 @@ var (
configErr error
configOnce sync.Once

ReadConfigFile = readConfigFileCached
ReadConfigFile = readConfigFileCached
GetConfigForCurrentKubectx = getConfigForCurrentKubectx
)

// readConfigFileCached reads the specified file and returns the contents
Expand Down Expand Up @@ -96,7 +97,7 @@ func ReadConfigFileNoCache(configFile string) (*GlobalConfig, error) {
// GetConfigForCurrentKubectx returns the specific config to be modified based on the kubeContext.
// Either returns the config corresponding to the provided or current context,
// or the global config.
func GetConfigForCurrentKubectx(configFile string) (*ContextConfig, error) {
func getConfigForCurrentKubectx(configFile string) (*ContextConfig, error) {
configOnce.Do(func() {
cfg, err := ReadConfigFile(configFile)
if err != nil {
Expand Down Expand Up @@ -191,3 +192,11 @@ func isDefaultLocal(kubeContext string) bool {
func IsKindCluster(kubeContext string) bool {
return strings.HasSuffix(kubeContext, "@kind")
}

func IsUpdateCheckEnabled(configfile string) bool {
cfg, err := GetConfigForCurrentKubectx(configfile)
if err != nil {
return true
}
return cfg == nil || cfg.UpdateCheck == nil || *cfg.UpdateCheck
}
63 changes: 53 additions & 10 deletions pkg/skaffold/config/util_test.go
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package config

import (
"fmt"
"path/filepath"
"strings"
"testing"
Expand Down Expand Up @@ -108,13 +109,13 @@ func Test_getConfigForKubeContextWithGlobalDefaults(t *testing.T) {
}

tests := []struct {
name string
description string
kubecontext string
cfg *GlobalConfig
expectedConfig *ContextConfig
}{
{
name: "global config when kubecontext is empty",
description: "global config when kubecontext is empty",
cfg: &GlobalConfig{
Global: &ContextConfig{
InsecureRegistries: []string{"mediocre.io"},
Expand All @@ -135,28 +136,28 @@ func Test_getConfigForKubeContextWithGlobalDefaults(t *testing.T) {
},
},
{
name: "no global config and no kubecontext",
description: "no global config and no kubecontext",
cfg: &GlobalConfig{},
expectedConfig: &ContextConfig{},
},
{
name: "config for unknown kubecontext",
description: "config for unknown kubecontext",
kubecontext: someKubeContext,
cfg: &GlobalConfig{},
expectedConfig: &ContextConfig{
Kubecontext: someKubeContext,
},
},
{
name: "config for kubecontext when globals are empty",
description: "config for kubecontext when globals are empty",
kubecontext: someKubeContext,
cfg: &GlobalConfig{
ContextConfigs: []*ContextConfig{sampleConfig2, sampleConfig1},
},
expectedConfig: sampleConfig1,
},
{
name: "config for kubecontext without merged values",
description: "config for kubecontext without merged values",
kubecontext: someKubeContext,
cfg: &GlobalConfig{
Global: sampleConfig2,
Expand All @@ -165,7 +166,7 @@ func Test_getConfigForKubeContextWithGlobalDefaults(t *testing.T) {
expectedConfig: sampleConfig1,
},
{
name: "config for kubecontext with merged values",
description: "config for kubecontext with merged values",
kubecontext: someKubeContext,
cfg: &GlobalConfig{
Global: sampleConfig2,
Expand All @@ -182,7 +183,7 @@ func Test_getConfigForKubeContextWithGlobalDefaults(t *testing.T) {
},
},
{
name: "config for unknown kubecontext with merged values",
description: "config for unknown kubecontext with merged values",
kubecontext: someKubeContext,
cfg: &GlobalConfig{Global: sampleConfig2},
expectedConfig: &ContextConfig{
Expand All @@ -192,7 +193,7 @@ func Test_getConfigForKubeContextWithGlobalDefaults(t *testing.T) {
},
},
{
name: "merge global and context-specific insecure-registries",
description: "merge global and context-specific insecure-registries",
kubecontext: someKubeContext,
cfg: &GlobalConfig{
Global: &ContextConfig{
Expand All @@ -210,9 +211,51 @@ func Test_getConfigForKubeContextWithGlobalDefaults(t *testing.T) {
},
}
for _, test := range tests {
testutil.Run(t, test.name, func(t *testutil.T) {
testutil.Run(t, test.description, func(t *testutil.T) {
actual, err := getConfigForKubeContextWithGlobalDefaults(test.cfg, test.kubecontext)
t.CheckErrorAndDeepEqual(false, err, test.expectedConfig, actual)
})
}
}

func TestIsUpdateCheckEnabled(t *testing.T) {
tests := []struct {
description string
cfg *ContextConfig
readErr error
expected bool
}{
{
description: "config update-check is nil returns true",
cfg: &ContextConfig{},
expected: true,
},
{
description: "config update-check is true",
cfg: &ContextConfig{UpdateCheck: util.BoolPtr(true)},
expected: true,
},
{
description: "config update-check is false",
cfg: &ContextConfig{UpdateCheck: util.BoolPtr(false)},
},
{
description: "config is nil",
cfg: nil,
expected: true,
},
{
description: "config has err",
cfg: nil,
readErr: fmt.Errorf("error while reading"),
expected: true,
},
}
for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
t.Override(&GetConfigForCurrentKubectx, func(string) (*ContextConfig, error) { return test.cfg, test.readErr })
actual := IsUpdateCheckEnabled("dummyconfig")
t.CheckDeepEqual(test.expected, actual)
})
}
}
Empty file added pkg/skaffold/update/dummyconfig
Empty file.
15 changes: 12 additions & 3 deletions pkg/skaffold/update/update.go
Expand Up @@ -22,6 +22,7 @@ import (
"os"
"strings"

"github.com/GoogleContainerTools/skaffold/pkg/skaffold/config"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/constants"
"github.com/GoogleContainerTools/skaffold/pkg/skaffold/version"
"github.com/blang/semver"
Expand All @@ -31,20 +32,28 @@ import (
// Fot testing
var (
GetLatestAndCurrentVersion = getLatestAndCurrentVersion
isConfigUpdateCheckEnabled = config.IsUpdateCheckEnabled
getEnv = os.Getenv
)

const latestVersionURL = "https://storage.googleapis.com/skaffold/releases/latest/VERSION"

// IsUpdateCheckEnabled returns whether or not the update check is enabled
// It is true by default, but setting it to any other value than true will disable the check
func IsUpdateCheckEnabled() bool {
func IsUpdateCheckEnabled(configfile string) bool {
// Don't perform a version check on dirty trees
if version.Get().GitTreeState == "dirty" {
return false
}

v := os.Getenv(constants.UpdateCheckEnvironmentVariable)
return v == "" || strings.ToLower(v) == "true"
return isUpdateCheckEnabledByEnvOrConfig(configfile)
}

func isUpdateCheckEnabledByEnvOrConfig(configfile string) bool {
if v := getEnv(constants.UpdateCheckEnvironmentVariable); v != "" {
return strings.ToLower(v) == "true"
}
return isConfigUpdateCheckEnabled(configfile)
}

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