diff --git a/internal/plugin/installer/base.go b/internal/plugin/installer/base.go index 54d25287a..5f8e745cc 100644 --- a/internal/plugin/installer/base.go +++ b/internal/plugin/installer/base.go @@ -36,10 +36,22 @@ func newBase(source string) base { } } +// pluginsDir returns the directory where plugins should be installed. When +// HELM_PLUGINS contains a list of directories (separated by the OS path list +// separator), the first non-empty directory is the default install target. +func (b *base) pluginsDir() string { + for _, dir := range filepath.SplitList(b.PluginsDirectory) { + if dir != "" { + return dir + } + } + return b.PluginsDirectory +} + // Path is where the plugin will be installed. func (b *base) Path() string { if b.Source == "" { return "" } - return filepath.Join(b.PluginsDirectory, filepath.Base(b.Source)) + return filepath.Join(b.pluginsDir(), filepath.Base(b.Source)) } diff --git a/internal/plugin/installer/base_test.go b/internal/plugin/installer/base_test.go index 8ef7ff588..0f1b74160 100644 --- a/internal/plugin/installer/base_test.go +++ b/internal/plugin/installer/base_test.go @@ -14,6 +14,8 @@ limitations under the License. package installer import ( + "path/filepath" + "strings" "testing" "github.com/stretchr/testify/assert" @@ -32,7 +34,15 @@ func TestPath(t *testing.T) { }, { source: "https://github.com/jkroepke/helm-secrets", helmPluginsDir: "/helm/data/plugins", - expectPath: "/helm/data/plugins/helm-secrets", + expectPath: filepath.Join("/helm/data/plugins", "helm-secrets"), + }, { + source: "https://github.com/jkroepke/helm-secrets", + helmPluginsDir: strings.Join([]string{"/helm/data/plugins", "/helm/data/extra"}, string(filepath.ListSeparator)), + expectPath: filepath.Join("/helm/data/plugins", "helm-secrets"), + }, { + source: "https://github.com/jkroepke/helm-secrets", + helmPluginsDir: string(filepath.ListSeparator) + "/helm/data/plugins", + expectPath: filepath.Join("/helm/data/plugins", "helm-secrets"), }, } diff --git a/internal/plugin/installer/http_installer.go b/internal/plugin/installer/http_installer.go index 7be326de2..3fbe6a3e1 100644 --- a/internal/plugin/installer/http_installer.go +++ b/internal/plugin/installer/http_installer.go @@ -152,7 +152,7 @@ func (i HTTPInstaller) Path() string { if i.Source == "" { return "" } - return helmpath.DataPath("plugins", i.PluginName) + return filepath.Join(i.pluginsDir(), i.PluginName) } // SupportsVerification returns true if the HTTP installer can verify plugins diff --git a/internal/plugin/installer/local_installer.go b/internal/plugin/installer/local_installer.go index 59918401b..1505d0f57 100644 --- a/internal/plugin/installer/local_installer.go +++ b/internal/plugin/installer/local_installer.go @@ -176,7 +176,7 @@ func (i *LocalInstaller) Path() string { pluginName = stripPluginName(pluginName) } - return helmpath.DataPath("plugins", pluginName) + return filepath.Join(i.pluginsDir(), pluginName) } // SupportsVerification returns true if the local installer can verify plugins diff --git a/internal/plugin/installer/oci_installer.go b/internal/plugin/installer/oci_installer.go index 383ddb914..9b62dc980 100644 --- a/internal/plugin/installer/oci_installer.go +++ b/internal/plugin/installer/oci_installer.go @@ -195,7 +195,7 @@ func (i OCIInstaller) Path() string { if i.Source == "" { return "" } - return filepath.Join(i.settings.PluginsDirectory, i.PluginName) + return filepath.Join(i.pluginsDir(), i.PluginName) } // extractTarGz extracts a gzipped tar archive to a directory