diff --git a/cmd/helm/helm.go b/cmd/helm/helm.go index 4c7ca9290..12a8701bf 100644 --- a/cmd/helm/helm.go +++ b/cmd/helm/helm.go @@ -21,6 +21,7 @@ import ( "io/ioutil" "log" "os" + "path/filepath" "strings" "github.com/spf13/cobra" @@ -34,6 +35,7 @@ import ( _ "k8s.io/client-go/plugin/pkg/client/auth" "k8s.io/helm/pkg/helm" helm_env "k8s.io/helm/pkg/helm/environment" + "k8s.io/helm/pkg/helm/notify" "k8s.io/helm/pkg/helm/portforwarder" "k8s.io/helm/pkg/kube" "k8s.io/helm/pkg/tlsutil" @@ -79,6 +81,8 @@ Environment: ` func newRootCmd(args []string) *cobra.Command { + updateMessages := make(chan string) + cmd := &cobra.Command{ Use: "helm", Short: "The Helm package manager for Kubernetes.", @@ -88,9 +92,29 @@ func newRootCmd(args []string) *cobra.Command { tlsCaCertFile = os.ExpandEnv(tlsCaCertFile) tlsCertFile = os.ExpandEnv(tlsCertFile) tlsKeyFile = os.ExpandEnv(tlsKeyFile) + + // Check for update in pre-run via goroutine and print update in post-run + // This allows the update check to happen concurrently from the command + if !settings.SkipSelfUpdateCheck { + lastUpdatePath := filepath.Join(settings.Home.String(), "last_update_check") + go func() { + // 604800 = 60 seconds * 60 minutes * 24 hours * 7 days + newVer, err := notify.IfTimeFromFile(lastUpdatePath, 604800, "https://mattfarina.github.io/test_helm_releases_url/releases.json") + if err != nil { + debug("Error checking for newer version of Helm: %q", err) + } + updateMessages <- newVer + }() + } + }, - PersistentPostRun: func(*cobra.Command, []string) { + PersistentPostRun: func(cmd *cobra.Command, args []string) { teardown() + msg := <-updateMessages + if msg != "" { + out := cmd.OutOrStdout() + fmt.Fprintf(out, "A new release of Helm is available at the version %s\n", msg) + } }, } flags := cmd.PersistentFlags() diff --git a/docs/helm/helm.md b/docs/helm/helm.md index 8592cad7c..8faf69d15 100644 --- a/docs/helm/helm.md +++ b/docs/helm/helm.md @@ -36,6 +36,7 @@ Environment: --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -68,4 +69,4 @@ Environment: * [helm verify](helm_verify.md) - verify that a chart at the given path has been signed and is valid * [helm version](helm_version.md) - print the client/server version information -###### Auto generated by spf13/cobra on 14-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_completion.md b/docs/helm/helm_completion.md index 994205d88..aa6569b91 100644 --- a/docs/helm/helm_completion.md +++ b/docs/helm/helm_completion.md @@ -28,6 +28,7 @@ helm completion SHELL --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -35,4 +36,4 @@ helm completion SHELL ### SEE ALSO * [helm](helm.md) - The Helm package manager for Kubernetes. -###### Auto generated by spf13/cobra on 8-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_create.md b/docs/helm/helm_create.md index 6e0f3de78..c4ef2988f 100644 --- a/docs/helm/helm_create.md +++ b/docs/helm/helm_create.md @@ -47,6 +47,7 @@ helm create NAME --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -54,4 +55,4 @@ helm create NAME ### SEE ALSO * [helm](helm.md) - The Helm package manager for Kubernetes. -###### Auto generated by spf13/cobra on 8-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_delete.md b/docs/helm/helm_delete.md index 9eee6e8ec..a4605f3bb 100644 --- a/docs/helm/helm_delete.md +++ b/docs/helm/helm_delete.md @@ -39,6 +39,7 @@ helm delete [flags] RELEASE_NAME [...] --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -46,4 +47,4 @@ helm delete [flags] RELEASE_NAME [...] ### SEE ALSO * [helm](helm.md) - The Helm package manager for Kubernetes. -###### Auto generated by spf13/cobra on 13-Apr-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_dependency.md b/docs/helm/helm_dependency.md index 34d49e20a..6697f9d44 100644 --- a/docs/helm/helm_dependency.md +++ b/docs/helm/helm_dependency.md @@ -61,6 +61,7 @@ for this case. --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -71,4 +72,4 @@ for this case. * [helm dependency list](helm_dependency_list.md) - list the dependencies for the given chart * [helm dependency update](helm_dependency_update.md) - update charts/ based on the contents of requirements.yaml -###### Auto generated by spf13/cobra on 8-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_dependency_build.md b/docs/helm/helm_dependency_build.md index 0413a9a85..acccf432b 100644 --- a/docs/helm/helm_dependency_build.md +++ b/docs/helm/helm_dependency_build.md @@ -34,6 +34,7 @@ helm dependency build [flags] CHART --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -41,4 +42,4 @@ helm dependency build [flags] CHART ### SEE ALSO * [helm dependency](helm_dependency.md) - manage a chart's dependencies -###### Auto generated by spf13/cobra on 8-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_dependency_list.md b/docs/helm/helm_dependency_list.md index b4343081c..d92c8bb64 100644 --- a/docs/helm/helm_dependency_list.md +++ b/docs/helm/helm_dependency_list.md @@ -26,6 +26,7 @@ helm dependency list [flags] CHART --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -33,4 +34,4 @@ helm dependency list [flags] CHART ### SEE ALSO * [helm dependency](helm_dependency.md) - manage a chart's dependencies -###### Auto generated by spf13/cobra on 8-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_dependency_update.md b/docs/helm/helm_dependency_update.md index 3c90ff779..90555df90 100644 --- a/docs/helm/helm_dependency_update.md +++ b/docs/helm/helm_dependency_update.md @@ -39,6 +39,7 @@ helm dependency update [flags] CHART --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -46,4 +47,4 @@ helm dependency update [flags] CHART ### SEE ALSO * [helm dependency](helm_dependency.md) - manage a chart's dependencies -###### Auto generated by spf13/cobra on 8-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_fetch.md b/docs/helm/helm_fetch.md index 1ddef65fa..b01df66ba 100644 --- a/docs/helm/helm_fetch.md +++ b/docs/helm/helm_fetch.md @@ -50,9 +50,12 @@ helm fetch [flags] [chart URL | repo/chartname] [...] --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` ### SEE ALSO * [helm](helm.md) - The Helm package manager for Kubernetes. + +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_get.md b/docs/helm/helm_get.md index 9cd70e520..a526018b3 100644 --- a/docs/helm/helm_get.md +++ b/docs/helm/helm_get.md @@ -40,6 +40,7 @@ helm get [flags] RELEASE_NAME --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -50,4 +51,4 @@ helm get [flags] RELEASE_NAME * [helm get manifest](helm_get_manifest.md) - download the manifest for a named release * [helm get values](helm_get_values.md) - download the values file for a named release -###### Auto generated by spf13/cobra on 8-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_get_hooks.md b/docs/helm/helm_get_hooks.md index 85fa5d04b..0bf472e6b 100644 --- a/docs/helm/helm_get_hooks.md +++ b/docs/helm/helm_get_hooks.md @@ -33,6 +33,7 @@ helm get hooks [flags] RELEASE_NAME --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -40,4 +41,4 @@ helm get hooks [flags] RELEASE_NAME ### SEE ALSO * [helm get](helm_get.md) - download a named release -###### Auto generated by spf13/cobra on 8-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_get_manifest.md b/docs/helm/helm_get_manifest.md index a00c1be56..b03cef8c7 100644 --- a/docs/helm/helm_get_manifest.md +++ b/docs/helm/helm_get_manifest.md @@ -35,6 +35,7 @@ helm get manifest [flags] RELEASE_NAME --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -42,4 +43,4 @@ helm get manifest [flags] RELEASE_NAME ### SEE ALSO * [helm get](helm_get.md) - download a named release -###### Auto generated by spf13/cobra on 8-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_get_values.md b/docs/helm/helm_get_values.md index d8944b475..b3604c5d3 100644 --- a/docs/helm/helm_get_values.md +++ b/docs/helm/helm_get_values.md @@ -32,6 +32,7 @@ helm get values [flags] RELEASE_NAME --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -39,4 +40,4 @@ helm get values [flags] RELEASE_NAME ### SEE ALSO * [helm get](helm_get.md) - download a named release -###### Auto generated by spf13/cobra on 8-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_history.md b/docs/helm/helm_history.md index ac51a8994..96452ee1c 100755 --- a/docs/helm/helm_history.md +++ b/docs/helm/helm_history.md @@ -45,6 +45,7 @@ helm history [flags] RELEASE_NAME --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -52,4 +53,4 @@ helm history [flags] RELEASE_NAME ### SEE ALSO * [helm](helm.md) - The Helm package manager for Kubernetes. -###### Auto generated by spf13/cobra on 14-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_home.md b/docs/helm/helm_home.md index bdccd756f..d72365185 100644 --- a/docs/helm/helm_home.md +++ b/docs/helm/helm_home.md @@ -21,6 +21,7 @@ helm home --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -28,4 +29,4 @@ helm home ### SEE ALSO * [helm](helm.md) - The Helm package manager for Kubernetes. -###### Auto generated by spf13/cobra on 8-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_init.md b/docs/helm/helm_init.md index 5374488af..ef8ddd388 100644 --- a/docs/helm/helm_init.md +++ b/docs/helm/helm_init.md @@ -64,6 +64,7 @@ helm init --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -71,4 +72,4 @@ helm init ### SEE ALSO * [helm](helm.md) - The Helm package manager for Kubernetes. -###### Auto generated by spf13/cobra on 8-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_inspect.md b/docs/helm/helm_inspect.md index e46b3dbf4..569493f44 100644 --- a/docs/helm/helm_inspect.md +++ b/docs/helm/helm_inspect.md @@ -37,6 +37,7 @@ helm inspect [CHART] --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -47,4 +48,4 @@ helm inspect [CHART] * [helm inspect readme](helm_inspect_readme.md) - shows inspect readme * [helm inspect values](helm_inspect_values.md) - shows inspect values -###### Auto generated by spf13/cobra on 14-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_inspect_chart.md b/docs/helm/helm_inspect_chart.md index cd1328b59..f8a000139 100644 --- a/docs/helm/helm_inspect_chart.md +++ b/docs/helm/helm_inspect_chart.md @@ -35,6 +35,7 @@ helm inspect chart [CHART] --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -42,4 +43,4 @@ helm inspect chart [CHART] ### SEE ALSO * [helm inspect](helm_inspect.md) - inspect a chart -###### Auto generated by spf13/cobra on 8-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_inspect_readme.md b/docs/helm/helm_inspect_readme.md index 9dd9ebd43..ac509f8e7 100644 --- a/docs/helm/helm_inspect_readme.md +++ b/docs/helm/helm_inspect_readme.md @@ -33,6 +33,7 @@ helm inspect readme [CHART] --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -40,4 +41,4 @@ helm inspect readme [CHART] ### SEE ALSO * [helm inspect](helm_inspect.md) - inspect a chart -###### Auto generated by spf13/cobra on 14-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_inspect_values.md b/docs/helm/helm_inspect_values.md index 6a907cc7d..53c90e959 100644 --- a/docs/helm/helm_inspect_values.md +++ b/docs/helm/helm_inspect_values.md @@ -35,6 +35,7 @@ helm inspect values [CHART] --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -42,4 +43,4 @@ helm inspect values [CHART] ### SEE ALSO * [helm inspect](helm_inspect.md) - inspect a chart -###### Auto generated by spf13/cobra on 8-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_install.md b/docs/helm/helm_install.md index 62d02cc38..225865768 100644 --- a/docs/helm/helm_install.md +++ b/docs/helm/helm_install.md @@ -112,6 +112,7 @@ helm install [CHART] --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -119,4 +120,4 @@ helm install [CHART] ### SEE ALSO * [helm](helm.md) - The Helm package manager for Kubernetes. -###### Auto generated by spf13/cobra on 5-Jun-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_lint.md b/docs/helm/helm_lint.md index c10322efd..5330b0bc2 100644 --- a/docs/helm/helm_lint.md +++ b/docs/helm/helm_lint.md @@ -35,6 +35,7 @@ helm lint [flags] PATH --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -42,4 +43,4 @@ helm lint [flags] PATH ### SEE ALSO * [helm](helm.md) - The Helm package manager for Kubernetes. -###### Auto generated by spf13/cobra on 20-May-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_list.md b/docs/helm/helm_list.md index 99872a413..d169abd24 100755 --- a/docs/helm/helm_list.md +++ b/docs/helm/helm_list.md @@ -67,6 +67,7 @@ helm list [flags] [FILTER] --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -74,4 +75,4 @@ helm list [flags] [FILTER] ### SEE ALSO * [helm](helm.md) - The Helm package manager for Kubernetes. -###### Auto generated by spf13/cobra on 17-Apr-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_package.md b/docs/helm/helm_package.md index 21090fa45..754fa6130 100644 --- a/docs/helm/helm_package.md +++ b/docs/helm/helm_package.md @@ -40,6 +40,7 @@ helm package [flags] [CHART_PATH] [...] --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -47,4 +48,4 @@ helm package [flags] [CHART_PATH] [...] ### SEE ALSO * [helm](helm.md) - The Helm package manager for Kubernetes. -###### Auto generated by spf13/cobra on 16-Apr-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_plugin.md b/docs/helm/helm_plugin.md index cc42aa4dc..3a36eb3ac 100644 --- a/docs/helm/helm_plugin.md +++ b/docs/helm/helm_plugin.md @@ -16,6 +16,7 @@ Manage client-side Helm plugins. --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -27,4 +28,4 @@ Manage client-side Helm plugins. * [helm plugin remove](helm_plugin_remove.md) - remove one or more Helm plugins * [helm plugin update](helm_plugin_update.md) - update one or more Helm plugins -###### Auto generated by spf13/cobra on 8-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_plugin_install.md b/docs/helm/helm_plugin_install.md index 196ca97dd..303c04d1d 100644 --- a/docs/helm/helm_plugin_install.md +++ b/docs/helm/helm_plugin_install.md @@ -29,6 +29,7 @@ helm plugin install [options] ... --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -36,4 +37,4 @@ helm plugin install [options] ... ### SEE ALSO * [helm plugin](helm_plugin.md) - add, list, or remove Helm plugins -###### Auto generated by spf13/cobra on 8-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_plugin_list.md b/docs/helm/helm_plugin_list.md index ddfd04ee6..acd23750e 100644 --- a/docs/helm/helm_plugin_list.md +++ b/docs/helm/helm_plugin_list.md @@ -18,6 +18,7 @@ helm plugin list --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -25,4 +26,4 @@ helm plugin list ### SEE ALSO * [helm plugin](helm_plugin.md) - add, list, or remove Helm plugins -###### Auto generated by spf13/cobra on 8-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_plugin_remove.md b/docs/helm/helm_plugin_remove.md index 8543a367a..06126f4a4 100644 --- a/docs/helm/helm_plugin_remove.md +++ b/docs/helm/helm_plugin_remove.md @@ -18,6 +18,7 @@ helm plugin remove ... --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -25,4 +26,4 @@ helm plugin remove ... ### SEE ALSO * [helm plugin](helm_plugin.md) - add, list, or remove Helm plugins -###### Auto generated by spf13/cobra on 8-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_plugin_update.md b/docs/helm/helm_plugin_update.md index 9e5e205f0..2efa6889b 100644 --- a/docs/helm/helm_plugin_update.md +++ b/docs/helm/helm_plugin_update.md @@ -18,6 +18,7 @@ helm plugin update ... --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -25,4 +26,4 @@ helm plugin update ... ### SEE ALSO * [helm plugin](helm_plugin.md) - add, list, or remove Helm plugins -###### Auto generated by spf13/cobra on 8-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_repo.md b/docs/helm/helm_repo.md index 4109ceca4..6f06989eb 100644 --- a/docs/helm/helm_repo.md +++ b/docs/helm/helm_repo.md @@ -20,6 +20,7 @@ Example usage: --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -32,4 +33,4 @@ Example usage: * [helm repo remove](helm_repo_remove.md) - remove a chart repository * [helm repo update](helm_repo_update.md) - update information of available charts locally from chart repositories -###### Auto generated by spf13/cobra on 8-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_repo_add.md b/docs/helm/helm_repo_add.md index 456ffa27e..03fdc0552 100644 --- a/docs/helm/helm_repo_add.md +++ b/docs/helm/helm_repo_add.md @@ -29,6 +29,7 @@ helm repo add [flags] [NAME] [URL] --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -36,4 +37,4 @@ helm repo add [flags] [NAME] [URL] ### SEE ALSO * [helm repo](helm_repo.md) - add, list, remove, update, and index chart repositories -###### Auto generated by spf13/cobra on 8-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_repo_index.md b/docs/helm/helm_repo_index.md index 14b412b29..a95b5e31f 100644 --- a/docs/helm/helm_repo_index.md +++ b/docs/helm/helm_repo_index.md @@ -34,6 +34,7 @@ helm repo index [flags] [DIR] --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -41,4 +42,4 @@ helm repo index [flags] [DIR] ### SEE ALSO * [helm repo](helm_repo.md) - add, list, remove, update, and index chart repositories -###### Auto generated by spf13/cobra on 8-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_repo_list.md b/docs/helm/helm_repo_list.md index 858ef957f..299ef09ab 100644 --- a/docs/helm/helm_repo_list.md +++ b/docs/helm/helm_repo_list.md @@ -18,6 +18,7 @@ helm repo list [flags] --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -25,4 +26,4 @@ helm repo list [flags] ### SEE ALSO * [helm repo](helm_repo.md) - add, list, remove, update, and index chart repositories -###### Auto generated by spf13/cobra on 8-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_repo_remove.md b/docs/helm/helm_repo_remove.md index 801bc3c3f..04b4de647 100644 --- a/docs/helm/helm_repo_remove.md +++ b/docs/helm/helm_repo_remove.md @@ -18,6 +18,7 @@ helm repo remove [flags] [NAME] --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -25,4 +26,4 @@ helm repo remove [flags] [NAME] ### SEE ALSO * [helm repo](helm_repo.md) - add, list, remove, update, and index chart repositories -###### Auto generated by spf13/cobra on 8-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_repo_update.md b/docs/helm/helm_repo_update.md index 897ed24b7..4a7b5bdda 100644 --- a/docs/helm/helm_repo_update.md +++ b/docs/helm/helm_repo_update.md @@ -24,6 +24,7 @@ helm repo update --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -31,4 +32,4 @@ helm repo update ### SEE ALSO * [helm repo](helm_repo.md) - add, list, remove, update, and index chart repositories -###### Auto generated by spf13/cobra on 8-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_reset.md b/docs/helm/helm_reset.md index ed68b1b84..672941a4b 100644 --- a/docs/helm/helm_reset.md +++ b/docs/helm/helm_reset.md @@ -34,6 +34,7 @@ helm reset --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -41,4 +42,4 @@ helm reset ### SEE ALSO * [helm](helm.md) - The Helm package manager for Kubernetes. -###### Auto generated by spf13/cobra on 8-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_rollback.md b/docs/helm/helm_rollback.md index ae64a0a26..1ce02224f 100644 --- a/docs/helm/helm_rollback.md +++ b/docs/helm/helm_rollback.md @@ -41,6 +41,7 @@ helm rollback [flags] [RELEASE] [REVISION] --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -48,4 +49,4 @@ helm rollback [flags] [RELEASE] [REVISION] ### SEE ALSO * [helm](helm.md) - The Helm package manager for Kubernetes. -###### Auto generated by spf13/cobra on 13-Apr-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_search.md b/docs/helm/helm_search.md index 1ed04e880..bed829339 100644 --- a/docs/helm/helm_search.md +++ b/docs/helm/helm_search.md @@ -32,6 +32,7 @@ helm search [keyword] --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -39,4 +40,4 @@ helm search [keyword] ### SEE ALSO * [helm](helm.md) - The Helm package manager for Kubernetes. -###### Auto generated by spf13/cobra on 23-Apr-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_serve.md b/docs/helm/helm_serve.md index 90ebb6da9..b1ebe6220 100644 --- a/docs/helm/helm_serve.md +++ b/docs/helm/helm_serve.md @@ -39,6 +39,7 @@ helm serve --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -46,4 +47,4 @@ helm serve ### SEE ALSO * [helm](helm.md) - The Helm package manager for Kubernetes. -###### Auto generated by spf13/cobra on 8-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_status.md b/docs/helm/helm_status.md index 02ec0ad66..025a3ba96 100644 --- a/docs/helm/helm_status.md +++ b/docs/helm/helm_status.md @@ -39,6 +39,7 @@ helm status [flags] RELEASE_NAME --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -46,4 +47,4 @@ helm status [flags] RELEASE_NAME ### SEE ALSO * [helm](helm.md) - The Helm package manager for Kubernetes. -###### Auto generated by spf13/cobra on 8-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_template.md b/docs/helm/helm_template.md index cdc8a84a6..5f5e2edad 100644 --- a/docs/helm/helm_template.md +++ b/docs/helm/helm_template.md @@ -45,6 +45,7 @@ helm template [flags] CHART --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -52,4 +53,4 @@ helm template [flags] CHART ### SEE ALSO * [helm](helm.md) - The Helm package manager for Kubernetes. -###### Auto generated by spf13/cobra on 22-May-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_test.md b/docs/helm/helm_test.md index 062244e73..7096e99a4 100644 --- a/docs/helm/helm_test.md +++ b/docs/helm/helm_test.md @@ -35,6 +35,7 @@ helm test [RELEASE] --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -42,4 +43,4 @@ helm test [RELEASE] ### SEE ALSO * [helm](helm.md) - The Helm package manager for Kubernetes. -###### Auto generated by spf13/cobra on 8-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_upgrade.md b/docs/helm/helm_upgrade.md index b952624a5..ea42563d9 100644 --- a/docs/helm/helm_upgrade.md +++ b/docs/helm/helm_upgrade.md @@ -75,6 +75,7 @@ helm upgrade [RELEASE] [CHART] --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -82,4 +83,4 @@ helm upgrade [RELEASE] [CHART] ### SEE ALSO * [helm](helm.md) - The Helm package manager for Kubernetes. -###### Auto generated by spf13/cobra on 4-Apr-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_verify.md b/docs/helm/helm_verify.md index bc5343937..ac9372592 100644 --- a/docs/helm/helm_verify.md +++ b/docs/helm/helm_verify.md @@ -33,6 +33,7 @@ helm verify [flags] PATH --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -40,4 +41,4 @@ helm verify [flags] PATH ### SEE ALSO * [helm](helm.md) - The Helm package manager for Kubernetes. -###### Auto generated by spf13/cobra on 8-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/docs/helm/helm_version.md b/docs/helm/helm_version.md index 1f48cceba..b4e745e2a 100644 --- a/docs/helm/helm_version.md +++ b/docs/helm/helm_version.md @@ -48,6 +48,7 @@ helm version --home string location of your Helm config. Overrides $HELM_HOME (default "~/.helm") --host string address of Tiller. Overrides $HELM_HOST --kube-context string name of the kubeconfig context to use + --skip-self-update-check disable checking for updates to Helm --tiller-connection-timeout int the duration (in seconds) Helm will wait to establish a connection to tiller (default 300) --tiller-namespace string namespace of Tiller (default "kube-system") ``` @@ -55,4 +56,4 @@ helm version ### SEE ALSO * [helm](helm.md) - The Helm package manager for Kubernetes. -###### Auto generated by spf13/cobra on 8-Mar-2018 +###### Auto generated by spf13/cobra on 18-Jul-2018 diff --git a/pkg/helm/environment/environment.go b/pkg/helm/environment/environment.go index 2980e6dc9..501dac212 100644 --- a/pkg/helm/environment/environment.go +++ b/pkg/helm/environment/environment.go @@ -49,6 +49,8 @@ type EnvSettings struct { Debug bool // KubeContext is the name of the kubeconfig context. KubeContext string + // SkipSelfUpdateCheck tells helm to skip checking if there is an update to itself. + SkipSelfUpdateCheck bool } // AddFlags binds flags to the given flagset. @@ -59,6 +61,7 @@ func (s *EnvSettings) AddFlags(fs *pflag.FlagSet) { fs.BoolVar(&s.Debug, "debug", false, "enable verbose output") fs.StringVar(&s.TillerNamespace, "tiller-namespace", "kube-system", "namespace of Tiller") fs.Int64Var(&s.TillerConnectionTimeout, "tiller-connection-timeout", int64(300), "the duration (in seconds) Helm will wait to establish a connection to tiller") + fs.BoolVar(&s.SkipSelfUpdateCheck, "skip-self-update-check", false, "disable checking for updates to Helm") } // Init sets values from the environment. diff --git a/pkg/helm/notify/notify.go b/pkg/helm/notify/notify.go new file mode 100644 index 000000000..c89da4121 --- /dev/null +++ b/pkg/helm/notify/notify.go @@ -0,0 +1,183 @@ +/* +Copyright The Helm maintainers + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package notify // import "k8s.io/helm/pkg/helm/notify" + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "net/http" + "sort" + "strings" + "time" + + "github.com/Masterminds/semver" + "k8s.io/helm/pkg/version" +) + +var ( + // The time format used in the file recording the last check + timeLayout = time.RFC1123Z +) + +// Release contains information for a release +type Release struct { + + // Version is the version for the release (e.g., `v2.11.0`) + Version string `json:"version"` + + // Checksums is a map of the file checksums for a release. For example, + // a key might be "darwin-amd64" and the value is the checksum for the release + // in that environment + Checksums map[string]string `json:"checksums,omitempty"` +} + +// Releases is an array of Release +type Releases []Release + +// IfTime checks if there is a newer version of Helm if the wait period is over +// Arguments are: +// - lastUpdateTime: The last time an update was checked +// - waitTime: The period to wait before checking again +// - checkURL: A URL with a JSON file containing the updates +// TODO: Change checkURL to the internal object +// The return data includes: +// - bool: true if an was checked for and false otherwise +// - string: the latest version if there is a newer version and an empty string otherwise +func IfTime(lastUpdateTime time.Time, waitTime time.Duration, checkURL string) (bool, string, error) { + // Check if current time has waited long enough + curr := time.Since(lastUpdateTime) + if curr <= waitTime { + return false, "", nil + } + + // Check for an update + releases, err := getJSON(checkURL) + if err != nil { + return true, "", err + } + + // Check if there is a new release + curSemVer, err := semver.NewVersion(version.GetVersion()) + if err != nil { + return true, "", err + } + + var vs []*semver.Version + + for _, release := range releases { + tmpVer, err := semver.NewVersion(release.Version) + if err == nil { + vs = append(vs, tmpVer) + } + } + sort.Sort(semver.Collection(vs)) + + if len(vs) > 0 && vs[len(vs)-1].GreaterThan(curSemVer) { + return true, vs[len(vs)-1].String(), nil + } + + // Return new release if one found + return true, "", nil +} + +// IfTimeFromFile will notify of a new version available if: +// - The current time is greater than waitTime + the last time it was updated +// - There is a newer version available +// This is a helper function wrapping IfTime, reading from the filesystem, +// and pretty printing if there is a new version. +// The arguments are: +// - lastUpdatePath: The path to the local filesystem location containing the +// last time an update was checked for +// - waitTime: The time in seconds to wait from the last check before checking +// again. +// - checkURL: A URL to a JSON file with version information to check for updates +func IfTimeFromFile(lastUpdatePath string, waitTime int64, checkURL string) (string, error) { + // Read contents of the time file + content, err := ioutil.ReadFile(lastUpdatePath) + + if err != nil { + // The file does not exist so we will assume this is a first run and create + // the file with a time of now so it will tell about an update in the future + errStr := err.Error() + if strings.Contains(errStr, "no such file or directory") { + curTime := time.Now().Format(timeLayout) + ioutil.WriteFile(lastUpdatePath, []byte(curTime), 0644) + content = []byte(curTime) + } else { + return "", err + } + } + + // Convert the string time to a usable Time instance + lastChecked, err := time.Parse(timeLayout, strings.TrimSpace(string(content))) + if err != nil { + return "", err + } + + // Convert the wait period to a Duration instance + waitPeriod := time.Duration(waitTime) * time.Second + + // Call NotifyIfTime + checked, newVersion, err := IfTime(lastChecked, waitPeriod, checkURL) + + if err != nil { + return "", err + } + + // Update the check time if a check happened + if checked { + curTime := time.Now().Format(timeLayout) + ioutil.WriteFile(lastUpdatePath, []byte(curTime), 0644) + + // If there is a new version and a check happened print the message + return newVersion, nil + } + + return "", nil + +} + +func getJSON(href string) (Releases, error) { + client := &http.Client{} + + // Construct the request + req, err := http.NewRequest("GET", href, nil) + if err != nil { + return nil, err + } + req.Header.Set("User-Agent", "Helm/"+strings.TrimPrefix(version.GetVersion(), "v")) + + // Perform the request and handle errors + resp, err := client.Do(req) + if err != nil { + return nil, err + } + defer resp.Body.Close() + if resp.StatusCode != 200 { + return nil, fmt.Errorf("Failed to fetch update information at %s : %s", href, resp.Status) + } + + // Get the contents of the JSON file + target := Releases{} + err = json.NewDecoder(resp.Body).Decode(&target) + if err != nil { + return nil, err + } + + return target, nil +} diff --git a/pkg/helm/notify/notify_test.go b/pkg/helm/notify/notify_test.go new file mode 100644 index 000000000..f46bff9e6 --- /dev/null +++ b/pkg/helm/notify/notify_test.go @@ -0,0 +1,209 @@ +/* +Copyright The Helm maintainers + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +package notify + +import ( + "encoding/json" + "fmt" + "io/ioutil" + "net/http" + "net/http/httptest" + "os" + "path/filepath" + "testing" + "time" + + "github.com/Masterminds/semver" + "k8s.io/helm/pkg/version" +) + +type URLHandler struct { + releases Releases +} + +func (h *URLHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { + b, err := json.Marshal(h.releases) + if err != nil { + fmt.Println(err) + return + } + w.Header().Set("Content-Type", "application/javascript") + fmt.Fprintf(w, string(b)) +} + +func TestWorkingIfTime(t *testing.T) { + + curSemVer, err := semver.NewVersion(version.GetVersion()) + if err != nil { + t.Errorf("internal version (%s) could not be parsed: %s", version.GetVersion(), err) + } + + nextVer := curSemVer.IncMinor() + nextVerString := "v" + nextVer.String() + + tests := []struct { + checked bool + version string + newVersion string + duration int64 + }{ + {true, nextVerString, nextVer.String(), 10}, + {true, "v" + curSemVer.String(), "", 10}, + {false, nextVerString, "", 10000}, + } + + tmpTime := time.Now() + tmpTime = tmpTime.Add(-100 * time.Second) + + for i, tc := range tests { + handler := &URLHandler{ + releases: []Release{{Version: tc.version}}, + } + server := httptest.NewServer(handler) + + checked, newVer, err := IfTime(tmpTime, time.Duration(tc.duration)*time.Second, server.URL) + if err != nil { + t.Errorf("unexpected error checking IfTime: %s", err) + } + if checked != tc.checked { + t.Errorf("new version check of %t but got %t for test case %d", tc.checked, checked, i) + } + + if tc.newVersion != newVer { + t.Errorf("expected a new version of %qbut got %q for test case %d", tc.newVersion, newVer, i) + } + } +} + +func TestWorkingIfTimeFromFile(t *testing.T) { + + curSemVer, err := semver.NewVersion(version.GetVersion()) + if err != nil { + t.Errorf("internal version (%s) could not be parsed: %s", version.GetVersion(), err) + } + + nextVer := curSemVer.IncMinor() + + tests := []struct { + version *semver.Version + newVersion string + duration int64 + }{ + {&nextVer, nextVer.String(), 10}, + {curSemVer, "", 10}, + {&nextVer, "", 10000}, + } + + tempDir, err := ioutil.TempDir("", "helm-update_check-") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(tempDir) + lastUpdatePath := filepath.Join(tempDir, "last_update_check") + + for i, tc := range tests { + + tmpTime := time.Now() + tmpTime = tmpTime.Add(-100 * time.Second) + ioutil.WriteFile(lastUpdatePath, []byte(tmpTime.Format(timeLayout)), 0644) + + handler := &URLHandler{ + releases: []Release{{Version: "v" + tc.version.String()}}, + } + server := httptest.NewServer(handler) + + newVer, err := IfTimeFromFile(lastUpdatePath, tc.duration, server.URL) + if err != nil { + t.Errorf("unexpected error checking IfTime: %s", err) + } + + if tc.newVersion != newVer { + t.Errorf("expected a new version of %qbut got %q for test case %d", tc.newVersion, newVer, i) + } + } +} + +type URLHandlerNone struct{} + +func (h *URLHandlerNone) ServeHTTP(w http.ResponseWriter, r *http.Request) { +} + +func TestBadURLIfTime(t *testing.T) { + handler := &URLHandlerNone{} + server := httptest.NewServer(handler) + + tmpTime := time.Now() + tmpTime = tmpTime.Add(-100 * time.Second) + _, _, err := IfTime(tmpTime, time.Duration(10)*time.Second, server.URL) + + if err == nil { + t.Error("expected error with handler but did not get one") + } +} + +func TestBadURLIfTimeFromFile(t *testing.T) { + handler := &URLHandlerNone{} + server := httptest.NewServer(handler) + + tmpTime := time.Now() + tmpTime = tmpTime.Add(-100 * time.Second) + tempDir, err := ioutil.TempDir("", "helm-update_check-") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(tempDir) + lastUpdatePath := filepath.Join(tempDir, "last_update_check") + ioutil.WriteFile(lastUpdatePath, []byte(tmpTime.Format(timeLayout)), 0644) + + _, err = IfTimeFromFile(lastUpdatePath, 10, server.URL) + + if err == nil { + t.Error("expected error with handler but did not get one") + } +} + +func TestNoFileIfTimeFromFile(t *testing.T) { + handler := &URLHandler{ + releases: []Release{{Version: "v1.2.3"}}, + } + server := httptest.NewServer(handler) + + tempDir, err := ioutil.TempDir("", "helm-update_check-") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(tempDir) + lastUpdatePath := filepath.Join(tempDir, "last_update_check") + + newVer, err := IfTimeFromFile(lastUpdatePath, 10, server.URL) + + if err != nil { + t.Errorf("unexpected error: %s", err) + } + + if newVer != "" { + t.Errorf("expected an empty string version but got %s", newVer) + } + + content, err := ioutil.ReadFile(lastUpdatePath) + if err != nil { + t.Errorf("unexpected error: %s", err) + } + _, err = time.Parse(timeLayout, string(content)) + if err != nil { + t.Errorf("unexpected error: %s", err) + } +}