From ad9c68dc19e381127f9340d331f5c35a356bca50 Mon Sep 17 00:00:00 2001 From: Mihael Rodek Date: Wed, 18 May 2022 13:34:28 +0200 Subject: [PATCH] Updated tests and add new functions for versioning Signed-off-by: Mihael Rodek --- cmd/helm/plugin_update.go | 14 +++++++++----- pkg/plugin/installer/installer.go | 13 +++++++++++-- pkg/plugin/installer/vcs_installer.go | 16 ++++++++++++++-- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/cmd/helm/plugin_update.go b/cmd/helm/plugin_update.go index 6a0998b20..36ac77fc7 100644 --- a/cmd/helm/plugin_update.go +++ b/cmd/helm/plugin_update.go @@ -29,8 +29,7 @@ import ( ) type pluginUpdateOptions struct { - names map[string]string - version string + names map[string]string } const pluginUpdateDesc = ` @@ -41,7 +40,7 @@ func newPluginUpdateCmd(out io.Writer) *cobra.Command { o := &pluginUpdateOptions{} cmd := &cobra.Command{ - Use: "update ...", + Use: "update ...", Aliases: []string{"up"}, Short: "update one or more Helm plugins", Long: pluginUpdateDesc, @@ -55,7 +54,6 @@ func newPluginUpdateCmd(out io.Writer) *cobra.Command { 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 } @@ -109,7 +107,13 @@ func updatePlugin(p *plugin.Plugin, version string) error { 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 { return err } diff --git a/pkg/plugin/installer/installer.go b/pkg/plugin/installer/installer.go index 05deb87b5..867aeea43 100644 --- a/pkg/plugin/installer/installer.go +++ b/pkg/plugin/installer/installer.go @@ -75,8 +75,17 @@ func NewForSource(source, version string) (Installer, error) { } // FindSource determines the correct Installer for the given source. -func FindSource(location, version string) (Installer, error) { - installer, err := existingVCSRepo(location, version) +func FindSource(location string) (Installer, error) { + 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" { return installer, errors.New("cannot get information about plugin source") } diff --git a/pkg/plugin/installer/vcs_installer.go b/pkg/plugin/installer/vcs_installer.go index 49c93c21b..796f84d81 100644 --- a/pkg/plugin/installer/vcs_installer.go +++ b/pkg/plugin/installer/vcs_installer.go @@ -16,11 +16,11 @@ limitations under the License. package installer // import "helm.sh/helm/v3/pkg/plugin/installer" import ( - "github.com/Masterminds/vcs" "os" "sort" "github.com/Masterminds/semver/v3" + "github.com/Masterminds/vcs" "github.com/pkg/errors" "helm.sh/helm/v3/internal/third_party/dep/fs" @@ -35,7 +35,19 @@ type VCSInstaller struct { 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) if err != nil { return nil, err