mirror of https://github.com/helm/helm
Adds update option to plugin command (#2410)
* Adds update option to plugin command Fixes issues/2385 - helm install silently updates the plugin, if it pre-existed * Added tests for new methods for plugin update * Updated docs * Updated review comments :) * Return error exit code when there is errorpull/2448/merge
parent
8b6fff4474
commit
ff42dadde4
@ -0,0 +1,114 @@
|
||||
/*
|
||||
Copyright 2017 The Kubernetes Authors All rights reserved.
|
||||
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 main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"k8s.io/helm/pkg/helm/helmpath"
|
||||
"k8s.io/helm/pkg/plugin"
|
||||
"k8s.io/helm/pkg/plugin/installer"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
type pluginUpdateCmd struct {
|
||||
names []string
|
||||
home helmpath.Home
|
||||
out io.Writer
|
||||
}
|
||||
|
||||
func newPluginUpdateCmd(out io.Writer) *cobra.Command {
|
||||
pcmd := &pluginUpdateCmd{out: out}
|
||||
cmd := &cobra.Command{
|
||||
Use: "update <plugin>...",
|
||||
Short: "update one or more Helm plugins",
|
||||
PreRunE: func(cmd *cobra.Command, args []string) error {
|
||||
return pcmd.complete(args)
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
return pcmd.run()
|
||||
},
|
||||
}
|
||||
return cmd
|
||||
}
|
||||
|
||||
func (pcmd *pluginUpdateCmd) complete(args []string) error {
|
||||
if len(args) == 0 {
|
||||
return errors.New("please provide plugin name to update")
|
||||
}
|
||||
pcmd.names = args
|
||||
pcmd.home = settings.Home
|
||||
return nil
|
||||
}
|
||||
|
||||
func (pcmd *pluginUpdateCmd) run() error {
|
||||
installer.Debug = settings.Debug
|
||||
plugdirs := pluginDirs(pcmd.home)
|
||||
debug("loading installed plugins from %s", plugdirs)
|
||||
plugins, err := findPlugins(plugdirs)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var errorPlugins []string
|
||||
|
||||
for _, name := range pcmd.names {
|
||||
if found := findPlugin(plugins, name); found != nil {
|
||||
if err := updatePlugin(found, pcmd.home); err != nil {
|
||||
errorPlugins = append(errorPlugins, fmt.Sprintf("Failed to update plugin %s, got error (%v)", name, err))
|
||||
} else {
|
||||
fmt.Fprintf(pcmd.out, "Updated plugin: %s\n", name)
|
||||
}
|
||||
} else {
|
||||
errorPlugins = append(errorPlugins, fmt.Sprintf("Plugin: %s not found", name))
|
||||
}
|
||||
}
|
||||
if len(errorPlugins) > 0 {
|
||||
return fmt.Errorf(strings.Join(errorPlugins, "\n"))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func updatePlugin(p *plugin.Plugin, home helmpath.Home) error {
|
||||
exactLocation, err := filepath.EvalSymlinks(p.Dir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
absExactLocation, err := filepath.Abs(exactLocation)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
i, err := installer.FindSource(absExactLocation, home)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := installer.Update(i); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
debug("loading plugin from %s", i.Path())
|
||||
updatedPlugin, err := plugin.LoadDir(i.Path())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return runHook(updatedPlugin, plugin.Update, home)
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
## helm plugin update
|
||||
|
||||
update one or more Helm plugins
|
||||
|
||||
### Synopsis
|
||||
|
||||
|
||||
update one or more Helm plugins
|
||||
|
||||
```
|
||||
helm plugin update <plugin>...
|
||||
```
|
||||
|
||||
### Options inherited from parent commands
|
||||
|
||||
```
|
||||
--debug enable verbose output
|
||||
--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
|
||||
--tiller-namespace string namespace of tiller (default "kube-system")
|
||||
```
|
||||
|
||||
### SEE ALSO
|
||||
* [helm plugin](helm_plugin.md) - add, list, or remove Helm plugins
|
||||
|
||||
###### Auto generated by spf13/cobra on 6-May-2017
|
@ -0,0 +1,50 @@
|
||||
.TH "HELM" "1" "May 2017" "Auto generated by spf13/cobra" ""
|
||||
.nh
|
||||
.ad l
|
||||
|
||||
|
||||
.SH NAME
|
||||
.PP
|
||||
helm\-plugin\-update \- update one or more Helm plugins
|
||||
|
||||
|
||||
.SH SYNOPSIS
|
||||
.PP
|
||||
\fBhelm plugin update <plugin>\&...\fP
|
||||
|
||||
|
||||
.SH DESCRIPTION
|
||||
.PP
|
||||
update one or more Helm plugins
|
||||
|
||||
|
||||
.SH OPTIONS INHERITED FROM PARENT COMMANDS
|
||||
.PP
|
||||
\fB\-\-debug\fP[=false]
|
||||
enable verbose output
|
||||
|
||||
.PP
|
||||
\fB\-\-home\fP="~/.helm"
|
||||
location of your Helm config. Overrides $HELM\_HOME
|
||||
|
||||
.PP
|
||||
\fB\-\-host\fP=""
|
||||
address of tiller. Overrides $HELM\_HOST
|
||||
|
||||
.PP
|
||||
\fB\-\-kube\-context\fP=""
|
||||
name of the kubeconfig context to use
|
||||
|
||||
.PP
|
||||
\fB\-\-tiller\-namespace\fP="kube\-system"
|
||||
namespace of tiller
|
||||
|
||||
|
||||
.SH SEE ALSO
|
||||
.PP
|
||||
\fBhelm\-plugin(1)\fP
|
||||
|
||||
|
||||
.SH HISTORY
|
||||
.PP
|
||||
6\-May\-2017 Auto generated by spf13/cobra
|
Loading…
Reference in new issue