|
|
@ -16,22 +16,23 @@ limitations under the License.
|
|
|
|
package installer // import "k8s.io/helm/pkg/plugin/installer"
|
|
|
|
package installer // import "k8s.io/helm/pkg/plugin/installer"
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
|
"k8s.io/helm/pkg/helm/helmpath"
|
|
|
|
"archive/tar"
|
|
|
|
"path/filepath"
|
|
|
|
"bytes"
|
|
|
|
|
|
|
|
"compress/gzip"
|
|
|
|
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"io"
|
|
|
|
"k8s.io/helm/pkg/getter"
|
|
|
|
"k8s.io/helm/pkg/getter"
|
|
|
|
"k8s.io/helm/pkg/helm/environment"
|
|
|
|
"k8s.io/helm/pkg/helm/environment"
|
|
|
|
|
|
|
|
"k8s.io/helm/pkg/helm/helmpath"
|
|
|
|
"k8s.io/helm/pkg/plugin/cache"
|
|
|
|
"k8s.io/helm/pkg/plugin/cache"
|
|
|
|
"compress/gzip"
|
|
|
|
|
|
|
|
"archive/tar"
|
|
|
|
|
|
|
|
"io"
|
|
|
|
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"bytes"
|
|
|
|
|
|
|
|
"regexp"
|
|
|
|
"regexp"
|
|
|
|
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type HttpInstaller struct {
|
|
|
|
// HTTPInstaller installs plugins from an archive served by a web server.
|
|
|
|
|
|
|
|
type HTTPInstaller struct {
|
|
|
|
CacheDir string
|
|
|
|
CacheDir string
|
|
|
|
PluginName string
|
|
|
|
PluginName string
|
|
|
|
base
|
|
|
|
base
|
|
|
@ -39,13 +40,16 @@ type HttpInstaller struct {
|
|
|
|
getter getter.Getter
|
|
|
|
getter getter.Getter
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type TarGzExtractor struct {}
|
|
|
|
// TarGzExtractor extracts gzip compressed tar archives
|
|
|
|
|
|
|
|
type TarGzExtractor struct{}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Extractor provides an interface for extracting archives
|
|
|
|
type Extractor interface {
|
|
|
|
type Extractor interface {
|
|
|
|
Extract(buffer *bytes.Buffer, targetDir string) error
|
|
|
|
Extract(buffer *bytes.Buffer, targetDir string) error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var Extractors = map[string]Extractor {
|
|
|
|
// Extractors contains a map of suffixes and matching implementations of extractor to return
|
|
|
|
|
|
|
|
var Extractors = map[string]Extractor{
|
|
|
|
".tar.gz": &TarGzExtractor{},
|
|
|
|
".tar.gz": &TarGzExtractor{},
|
|
|
|
".tgz": &TarGzExtractor{},
|
|
|
|
".tgz": &TarGzExtractor{},
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -60,8 +64,8 @@ func NewExtractor(source string) (Extractor, error) {
|
|
|
|
return nil, fmt.Errorf("no extractor implemented yet for %s", source)
|
|
|
|
return nil, fmt.Errorf("no extractor implemented yet for %s", source)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// NewHttpInstaller creates a new HttpInstaller.
|
|
|
|
// NewHTTPInstaller creates a new HttpInstaller.
|
|
|
|
func NewHttpInstaller(source string, home helmpath.Home) (*HttpInstaller, error) {
|
|
|
|
func NewHTTPInstaller(source string, home helmpath.Home) (*HTTPInstaller, error) {
|
|
|
|
|
|
|
|
|
|
|
|
key, err := cache.Key(source)
|
|
|
|
key, err := cache.Key(source)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
@ -78,12 +82,12 @@ func NewHttpInstaller(source string, home helmpath.Home) (*HttpInstaller, error)
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
get, err := getConstructor.New(source,"", "", "")
|
|
|
|
get, err := getConstructor.New(source, "", "", "")
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
i := &HttpInstaller{
|
|
|
|
i := &HTTPInstaller{
|
|
|
|
CacheDir: home.Path("cache", "plugins", key),
|
|
|
|
CacheDir: home.Path("cache", "plugins", key),
|
|
|
|
PluginName: stripPluginName(filepath.Base(source)),
|
|
|
|
PluginName: stripPluginName(filepath.Base(source)),
|
|
|
|
base: newBase(source, home),
|
|
|
|
base: newBase(source, home),
|
|
|
@ -106,10 +110,10 @@ func stripPluginName(name string) string {
|
|
|
|
return re.ReplaceAllString(strippedName, `$1`)
|
|
|
|
return re.ReplaceAllString(strippedName, `$1`)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Install() downloads and extracts the tarball into the cache directory and creates a symlink to the plugin directory in $HELM_HOME.
|
|
|
|
// Install downloads and extracts the tarball into the cache directory and creates a symlink to the plugin directory in $HELM_HOME.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Implements Installer.
|
|
|
|
// Implements Installer.
|
|
|
|
func (i *HttpInstaller) Install() error {
|
|
|
|
func (i *HTTPInstaller) Install() error {
|
|
|
|
|
|
|
|
|
|
|
|
pluginData, err := i.getter.Get(i.Source)
|
|
|
|
pluginData, err := i.getter.Get(i.Source)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
@ -135,25 +139,25 @@ func (i *HttpInstaller) Install() error {
|
|
|
|
|
|
|
|
|
|
|
|
// Update updates a local repository
|
|
|
|
// Update updates a local repository
|
|
|
|
// Not implemented for now since tarball most likely will be packaged by version
|
|
|
|
// Not implemented for now since tarball most likely will be packaged by version
|
|
|
|
func (i *HttpInstaller) Update() error {
|
|
|
|
func (i *HTTPInstaller) Update() error {
|
|
|
|
return fmt.Errorf("method Update() not implemented for HttpInstaller")
|
|
|
|
return fmt.Errorf("method Update() not implemented for HttpInstaller")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Override link because we want to use HttpInstaller.Path() not base.Path()
|
|
|
|
// Override link because we want to use HttpInstaller.Path() not base.Path()
|
|
|
|
func (i *HttpInstaller) link(from string) error {
|
|
|
|
func (i *HTTPInstaller) link(from string) error {
|
|
|
|
debug("symlinking %s to %s", from, i.Path())
|
|
|
|
debug("symlinking %s to %s", from, i.Path())
|
|
|
|
return os.Symlink(from, i.Path())
|
|
|
|
return os.Symlink(from, i.Path())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Override Path() because we want to join on the plugin name not the file name
|
|
|
|
// Path is overridden because we want to join on the plugin name not the file name
|
|
|
|
func (i HttpInstaller) Path() string {
|
|
|
|
func (i HTTPInstaller) Path() string {
|
|
|
|
if i.base.Source == "" {
|
|
|
|
if i.base.Source == "" {
|
|
|
|
return ""
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return filepath.Join(i.base.HelmHome.Plugins(), i.PluginName)
|
|
|
|
return filepath.Join(i.base.HelmHome.Plugins(), i.PluginName)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Extracts tar.gz archive
|
|
|
|
// Extract extracts compressed archives
|
|
|
|
//
|
|
|
|
//
|
|
|
|
// Implements Extractor.
|
|
|
|
// Implements Extractor.
|
|
|
|
func (g *TarGzExtractor) Extract(buffer *bytes.Buffer, targetDir string) error {
|
|
|
|
func (g *TarGzExtractor) Extract(buffer *bytes.Buffer, targetDir string) error {
|
|
|
@ -194,7 +198,7 @@ func (g *TarGzExtractor) Extract(buffer *bytes.Buffer, targetDir string) error {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
return fmt.Errorf("unknown type: %s in %s", header.Typeflag, header.Name)
|
|
|
|
return fmt.Errorf("unknown type: %b in %s", header.Typeflag, header.Name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|