Updated tests and add new functions for versioning

Signed-off-by: Mihael Rodek <mihael.rodek1@gmail.com>
pull/10971/head
Mihael Rodek 3 years ago
parent 7a9d79f99b
commit ad9c68dc19

@ -29,8 +29,7 @@ import (
) )
type pluginUpdateOptions struct { type pluginUpdateOptions struct {
names map[string]string names map[string]string
version string
} }
const pluginUpdateDesc = ` const pluginUpdateDesc = `
@ -41,7 +40,7 @@ func newPluginUpdateCmd(out io.Writer) *cobra.Command {
o := &pluginUpdateOptions{} o := &pluginUpdateOptions{}
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "update <plugin:[version]>...", Use: "update <plugin[:version]>...",
Aliases: []string{"up"}, Aliases: []string{"up"},
Short: "update one or more Helm plugins", Short: "update one or more Helm plugins",
Long: pluginUpdateDesc, Long: pluginUpdateDesc,
@ -55,7 +54,6 @@ func newPluginUpdateCmd(out io.Writer) *cobra.Command {
return o.run(out) return o.run(out)
}, },
} }
cmd.Flags().StringVar(&o.version, "version", "", "specify a version constraint. If this is not specified, the latest version is installed")
return cmd return cmd
} }
@ -109,7 +107,13 @@ func updatePlugin(p *plugin.Plugin, version string) error {
return err return err
} }
i, err := installer.FindSource(absExactLocation, version) var i installer.Installer
if version != "" {
i, err = installer.FindSourceWithVersion(absExactLocation, version)
} else {
i, err = installer.FindSource(absExactLocation)
}
if err != nil { if err != nil {
return err return err
} }

@ -75,8 +75,17 @@ func NewForSource(source, version string) (Installer, error) {
} }
// FindSource determines the correct Installer for the given source. // FindSource determines the correct Installer for the given source.
func FindSource(location, version string) (Installer, error) { func FindSource(location string) (Installer, error) {
installer, err := existingVCSRepo(location, version) installer, err := existingVCSRepo(location)
if err != nil && err.Error() == "Cannot detect VCS" {
return installer, errors.New("cannot get information about plugin source")
}
return installer, err
}
// FindSourceWithVersion determines the correct Installer for the given source with provided version.
func FindSourceWithVersion(location, version string) (Installer, error) {
installer, err := existingVCSRepoWithVersion(location, version)
if err != nil && err.Error() == "Cannot detect VCS" { if err != nil && err.Error() == "Cannot detect VCS" {
return installer, errors.New("cannot get information about plugin source") return installer, errors.New("cannot get information about plugin source")
} }

@ -16,11 +16,11 @@ limitations under the License.
package installer // import "helm.sh/helm/v3/pkg/plugin/installer" package installer // import "helm.sh/helm/v3/pkg/plugin/installer"
import ( import (
"github.com/Masterminds/vcs"
"os" "os"
"sort" "sort"
"github.com/Masterminds/semver/v3" "github.com/Masterminds/semver/v3"
"github.com/Masterminds/vcs"
"github.com/pkg/errors" "github.com/pkg/errors"
"helm.sh/helm/v3/internal/third_party/dep/fs" "helm.sh/helm/v3/internal/third_party/dep/fs"
@ -35,7 +35,19 @@ type VCSInstaller struct {
base base
} }
func existingVCSRepo(location, version string) (Installer, error) { func existingVCSRepo(location string) (Installer, error) {
repo, err := vcs.NewRepo("", location)
if err != nil {
return nil, err
}
i := &VCSInstaller{
Repo: repo,
base: newBase(repo.Remote()),
}
return i, nil
}
func existingVCSRepoWithVersion(location, version string) (Installer, error) {
repo, err := vcs.NewRepo("", location) repo, err := vcs.NewRepo("", location)
if err != nil { if err != nil {
return nil, err return nil, err

Loading…
Cancel
Save