예제 #1
0
func TestUpdateCharts(t *testing.T) {
	srv, thome, err := repotest.NewTempServer("testdata/testserver/*.*")
	if err != nil {
		t.Fatal(err)
	}

	oldhome := homePath()
	helmHome = thome
	defer func() {
		srv.Stop()
		helmHome = oldhome
		os.Remove(thome)
	}()
	if err := ensureTestHome(helmpath.Home(thome), t); err != nil {
		t.Fatal(err)
	}

	buf := bytes.NewBuffer(nil)
	repos := []*repo.Entry{
		{Name: "charts", URL: srv.URL()},
	}
	updateCharts(repos, false, buf, helmpath.Home(thome))

	got := buf.String()
	if strings.Contains(got, "Unable to get an update") {
		t.Errorf("Failed to get a repo: %q", got)
	}
	if !strings.Contains(got, "Update Complete.") {
		t.Errorf("Update was not successful")
	}
}
예제 #2
0
파일: install.go 프로젝트: kubernetes/helm
// locateChartPath looks for a chart directory in known places, and returns either the full path or an error.
//
// This does not ensure that the chart is well-formed; only that the requested filename exists.
//
// Order of resolution:
// - current working directory
// - if path is absolute or begins with '.', error out here
// - chart repos in $HELM_HOME
// - URL
//
// If 'verify' is true, this will attempt to also verify the chart.
func locateChartPath(name, version string, verify bool, keyring string) (string, error) {
	name = strings.TrimSpace(name)
	version = strings.TrimSpace(version)
	if fi, err := os.Stat(name); err == nil {
		abs, err := filepath.Abs(name)
		if err != nil {
			return abs, err
		}
		if verify {
			if fi.IsDir() {
				return "", errors.New("cannot verify a directory")
			}
			if _, err := downloader.VerifyChart(abs, keyring); err != nil {
				return "", err
			}
		}
		return abs, nil
	}
	if filepath.IsAbs(name) || strings.HasPrefix(name, ".") {
		return name, fmt.Errorf("path %q not found", name)
	}

	crepo := filepath.Join(helmpath.Home(homePath()).Repository(), name)
	if _, err := os.Stat(crepo); err == nil {
		return filepath.Abs(crepo)
	}

	dl := downloader.ChartDownloader{
		HelmHome: helmpath.Home(homePath()),
		Out:      os.Stdout,
		Keyring:  keyring,
	}
	if verify {
		dl.Verify = downloader.VerifyAlways
	}

	filename, _, err := dl.DownloadTo(name, version, ".")
	if err == nil {
		lname, err := filepath.Abs(filename)
		if err != nil {
			return filename, err
		}
		if flagDebug {
			fmt.Printf("Fetched %s to %s\n", name, filename)
		}
		return lname, nil
	} else if flagDebug {
		return filename, err
	}

	return filename, fmt.Errorf("file %q not found", name)
}
예제 #3
0
func TestSetupEnv(t *testing.T) {
	name := "pequod"
	hh := helmpath.Home("testdata/helmhome")
	base := filepath.Join(hh.Plugins(), name)
	plugdirs := hh.Plugins()
	flagDebug = true
	defer func() {
		flagDebug = false
	}()

	setupEnv(name, base, plugdirs, hh)
	for _, tt := range []struct {
		name   string
		expect string
	}{
		{"HELM_PLUGIN_NAME", name},
		{"HELM_PLUGIN_DIR", base},
		{"HELM_PLUGIN", hh.Plugins()},
		{"HELM_DEBUG", "1"},
		{"HELM_HOME", hh.String()},
		{"HELM_PATH_REPOSITORY", hh.Repository()},
		{"HELM_PATH_REPOSITORY_FILE", hh.RepositoryFile()},
		{"HELM_PATH_CACHE", hh.Cache()},
		{"HELM_PATH_LOCAL_REPOSITORY", hh.LocalRepository()},
		{"HELM_PATH_STARTER", hh.Starters()},
		{"TILLER_HOST", tillerHost},
	} {
		if got := os.Getenv(tt.name); got != tt.expect {
			t.Errorf("Expected $%s=%q, got %q", tt.name, tt.expect, got)
		}
	}
}
예제 #4
0
func newDependencyBuildCmd(out io.Writer) *cobra.Command {
	dbc := &dependencyBuildCmd{
		out: out,
	}

	cmd := &cobra.Command{
		Use:   "build [flags] CHART",
		Short: "rebuild the charts/ directory based on the requirements.lock file",
		Long:  dependencyBuildDesc,
		RunE: func(cmd *cobra.Command, args []string) error {
			dbc.helmhome = helmpath.Home(homePath())
			dbc.chartpath = "."

			if len(args) > 0 {
				dbc.chartpath = args[0]
			}
			return dbc.run()
		},
	}

	f := cmd.Flags()
	f.BoolVar(&dbc.verify, "verify", false, "verify the packages against signatures")
	f.StringVar(&dbc.keyring, "keyring", defaultKeyring(), "keyring containing public keys")

	return cmd
}
예제 #5
0
func TestInitCmd_dryRun(t *testing.T) {
	// This is purely defensive in this case.
	home, err := ioutil.TempDir("", "helm_home")
	if err != nil {
		t.Fatal(err)
	}
	dbg := flagDebug
	flagDebug = true
	defer func() {
		os.Remove(home)
		flagDebug = dbg
	}()

	var buf bytes.Buffer
	fake := testclient.Fake{}
	cmd := &initCmd{
		out:        &buf,
		home:       helmpath.Home(home),
		kubeClient: fake.Extensions(),
		clientOnly: true,
		dryRun:     true,
	}
	if err := cmd.run(); err != nil {
		t.Fatal(err)
	}
	if len(fake.Actions()) != 0 {
		t.Error("expected no server calls")
	}

	var y map[string]interface{}
	if err := yaml.Unmarshal(buf.Bytes(), &y); err != nil {
		t.Errorf("Expected parseable YAML, got %q\n\t%s", buf.String(), err)
	}
}
예제 #6
0
파일: repo_add_test.go 프로젝트: slack/helm
func TestRepoAdd(t *testing.T) {
	ts, thome, err := repotest.NewTempServer("testdata/testserver/*.*")
	if err != nil {
		t.Fatal(err)
	}

	oldhome := homePath()
	helmHome = thome
	hh := helmpath.Home(thome)
	defer func() {
		ts.Stop()
		helmHome = oldhome
		os.Remove(thome)
	}()
	if err := ensureTestHome(hh, t); err != nil {
		t.Fatal(err)
	}

	if err := addRepository(testName, ts.URL(), hh); err != nil {
		t.Error(err)
	}

	f, err := repo.LoadRepositoriesFile(hh.RepositoryFile())
	if err != nil {
		t.Error(err)
	}

	if !f.Has(testName) {
		t.Errorf("%s was not successfully inserted into %s", testName, hh.RepositoryFile())
	}
}
예제 #7
0
func TestInitCmd_clientOnly(t *testing.T) {
	home, err := ioutil.TempDir("", "helm_home")
	if err != nil {
		t.Fatal(err)
	}
	defer os.Remove(home)

	var buf bytes.Buffer
	fc := fake.NewSimpleClientset()
	cmd := &initCmd{
		out:        &buf,
		home:       helmpath.Home(home),
		kubeClient: fc.Extensions(),
		clientOnly: true,
		namespace:  api.NamespaceDefault,
	}
	if err := cmd.run(); err != nil {
		t.Errorf("unexpected error: %v", err)
	}
	if len(fc.Actions()) != 0 {
		t.Error("expected client call")
	}
	expected := "Not installing tiller due to 'client-only' flag having been set"
	if !strings.Contains(buf.String(), expected) {
		t.Errorf("expected %q, got %q", expected, buf.String())
	}
}
예제 #8
0
func TestInitCmd_exsits(t *testing.T) {
	home, err := ioutil.TempDir("", "helm_home")
	if err != nil {
		t.Fatal(err)
	}
	defer os.Remove(home)

	var buf bytes.Buffer
	fc := fake.NewSimpleClientset(&extensions.Deployment{
		ObjectMeta: api.ObjectMeta{
			Namespace: api.NamespaceDefault,
			Name:      "tiller-deploy",
		},
	})
	fc.AddReactor("*", "*", func(action testcore.Action) (bool, runtime.Object, error) {
		return true, nil, errors.NewAlreadyExists(api.Resource("deployments"), "1")
	})
	cmd := &initCmd{
		out:        &buf,
		home:       helmpath.Home(home),
		kubeClient: fc.Extensions(),
		namespace:  api.NamespaceDefault,
	}
	if err := cmd.run(); err != nil {
		t.Errorf("expected error: %v", err)
	}
	expected := "Warning: Tiller is already installed in the cluster. (Use --client-only to suppress this message.)"
	if !strings.Contains(buf.String(), expected) {
		t.Errorf("expected %q, got %q", expected, buf.String())
	}
}
예제 #9
0
func TestInitCmd(t *testing.T) {
	home, err := ioutil.TempDir("", "helm_home")
	if err != nil {
		t.Fatal(err)
	}
	defer os.Remove(home)

	var buf bytes.Buffer
	fc := fake.NewSimpleClientset()
	cmd := &initCmd{
		out:        &buf,
		home:       helmpath.Home(home),
		kubeClient: fc.Extensions(),
		namespace:  api.NamespaceDefault,
	}
	if err := cmd.run(); err != nil {
		t.Errorf("expected error: %v", err)
	}
	action := fc.Actions()[0]
	if !action.Matches("create", "deployments") {
		t.Errorf("unexpected action: %v, expected create deployment", action)
	}
	expected := "Tiller (the helm server side component) has been installed into your Kubernetes Cluster."
	if !strings.Contains(buf.String(), expected) {
		t.Errorf("expected %q, got %q", expected, buf.String())
	}
}
예제 #10
0
파일: init_test.go 프로젝트: slack/helm
func TestEnsureHome(t *testing.T) {
	home, err := ioutil.TempDir("", "helm_home")
	if err != nil {
		t.Fatal(err)
	}
	defer os.Remove(home)

	b := bytes.NewBuffer(nil)
	hh := helmpath.Home(home)
	helmHome = home
	if err := ensureHome(hh, b); err != nil {
		t.Error(err)
	}

	expectedDirs := []string{hh.String(), hh.Repository(), hh.Cache(), hh.LocalRepository()}
	for _, dir := range expectedDirs {
		if fi, err := os.Stat(dir); err != nil {
			t.Errorf("%s", err)
		} else if !fi.IsDir() {
			t.Errorf("%s is not a directory", fi)
		}
	}

	if fi, err := os.Stat(hh.RepositoryFile()); err != nil {
		t.Error(err)
	} else if fi.IsDir() {
		t.Errorf("%s should not be a directory", fi)
	}

	if fi, err := os.Stat(hh.LocalRepository(localRepoIndexFilePath)); err != nil {
		t.Errorf("%s", err)
	} else if fi.IsDir() {
		t.Errorf("%s should not be a directory", fi)
	}
}
예제 #11
0
func newInitCmd(out io.Writer) *cobra.Command {
	i := &initCmd{
		out: out,
	}

	cmd := &cobra.Command{
		Use:   "init",
		Short: "initialize Helm on both client and server",
		Long:  initDesc,
		RunE: func(cmd *cobra.Command, args []string) error {
			if len(args) != 0 {
				return errors.New("This command does not accept arguments")
			}
			i.home = helmpath.Home(homePath())
			return i.run()
		},
	}

	f := cmd.Flags()
	f.StringVarP(&i.image, "tiller-image", "i", "", "override tiller image")
	f.BoolVar(&i.canary, "canary-image", false, "use the canary tiller image")
	f.BoolVarP(&i.clientOnly, "client-only", "c", false, "if set does not install tiller")
	f.BoolVar(&i.dryRun, "dry-run", false, "do not install local or remote")

	return cmd
}
예제 #12
0
func TestUpdateCmd(t *testing.T) {
	thome, err := tempHelmHome(t)
	if err != nil {
		t.Fatal(err)
	}
	oldhome := homePath()
	helmHome = thome
	defer func() {
		helmHome = oldhome
		os.Remove(thome)
	}()

	out := bytes.NewBuffer(nil)
	// Instead of using the HTTP updater, we provide our own for this test.
	// The TestUpdateCharts test verifies the HTTP behavior independently.
	updater := func(repos []*repo.Entry, verbose bool, out io.Writer, home helmpath.Home) {
		for _, re := range repos {
			fmt.Fprintln(out, re.Name)
		}
	}
	uc := &repoUpdateCmd{
		out:    out,
		update: updater,
		home:   helmpath.Home(thome),
	}
	if err := uc.run(); err != nil {
		t.Fatal(err)
	}

	if got := out.String(); !strings.Contains(got, "charts") || !strings.Contains(got, "local") {
		t.Errorf("Expected 'charts' and 'local' (in any order) got %q", got)
	}
}
예제 #13
0
func TestResolveChartRef(t *testing.T) {
	tests := []struct {
		name, ref, expect, version string
		fail                       bool
	}{
		{name: "full URL", ref: "http://example.com/foo-1.2.3.tgz", expect: "http://example.com/foo-1.2.3.tgz"},
		{name: "full URL, HTTPS", ref: "https://example.com/foo-1.2.3.tgz", expect: "https://example.com/foo-1.2.3.tgz"},
		{name: "full URL, HTTPS, irrelevant version", ref: "https://example.com/foo-1.2.3.tgz", version: "0.1.0", expect: "https://example.com/foo-1.2.3.tgz"},
		{name: "reference, testing repo", ref: "testing/alpine", expect: "http://example.com/alpine-1.2.3.tgz"},
		{name: "reference, version, testing repo", ref: "testing/alpine", version: "0.2.0", expect: "http://example.com/alpine-0.2.0.tgz"},
		{name: "full URL, file", ref: "file:///foo-1.2.3.tgz", fail: true},
		{name: "invalid", ref: "invalid-1.2.3", fail: true},
		{name: "not found", ref: "nosuchthing/invalid-1.2.3", fail: true},
	}

	c := ChartDownloader{
		HelmHome: helmpath.Home("testdata/helmhome"),
		Out:      os.Stderr,
	}

	for _, tt := range tests {
		u, err := c.ResolveChartVersion(tt.ref, tt.version)
		if err != nil {
			if tt.fail {
				continue
			}
			t.Errorf("%s: failed with error %s", tt.name, err)
			continue
		}
		if got := u.String(); got != tt.expect {
			t.Errorf("%s: expected %s, got %s", tt.name, tt.expect, got)
		}
	}
}
예제 #14
0
// newDependencyUpdateCmd creates a new dependency update command.
func newDependencyUpdateCmd(out io.Writer) *cobra.Command {
	duc := &dependencyUpdateCmd{
		out: out,
	}

	cmd := &cobra.Command{
		Use:     "update [flags] CHART",
		Aliases: []string{"up"},
		Short:   "update charts/ based on the contents of requirements.yaml",
		Long:    dependencyUpDesc,
		RunE: func(cmd *cobra.Command, args []string) error {
			cp := "."
			if len(args) > 0 {
				cp = args[0]
			}

			var err error
			duc.chartpath, err = filepath.Abs(cp)
			if err != nil {
				return err
			}

			duc.helmhome = helmpath.Home(homePath())

			return duc.run()
		},
	}

	f := cmd.Flags()
	f.BoolVar(&duc.verify, "verify", false, "Verify the packages against signatures.")
	f.StringVar(&duc.keyring, "keyring", defaultKeyring(), "The keyring containing public keys.")

	return cmd
}
예제 #15
0
파일: repo_add_test.go 프로젝트: slack/helm
func TestRepoAddCmd(t *testing.T) {
	srv, thome, err := repotest.NewTempServer("testdata/testserver/*.*")
	if err != nil {
		t.Fatal(err)
	}

	oldhome := homePath()
	helmHome = thome
	defer func() {
		srv.Stop()
		helmHome = oldhome
		os.Remove(thome)
	}()
	if err := ensureTestHome(helmpath.Home(thome), t); err != nil {
		t.Fatal(err)
	}

	tests := []releaseCase{
		{
			name:     "add a repository",
			args:     []string{testName, srv.URL()},
			expected: testName + " has been added to your repositories",
		},
	}

	for _, tt := range tests {
		buf := bytes.NewBuffer(nil)
		c := newRepoAddCmd(buf)
		if err := c.RunE(c, tt.args); err != nil {
			t.Errorf("%q: expected %q, got %q", tt.name, tt.expected, err)
		}
	}
}
예제 #16
0
파일: helm.go 프로젝트: bacongobbler/helm
func newRootCmd(out io.Writer) *cobra.Command {
	cmd := &cobra.Command{
		Use:          "helm",
		Short:        "The Helm package manager for Kubernetes.",
		Long:         globalUsage,
		SilenceUsage: true,
		PersistentPostRun: func(cmd *cobra.Command, args []string) {
			teardown()
		},
	}
	p := cmd.PersistentFlags()
	p.StringVar(&helmHome, "home", defaultHelmHome(), "location of your Helm config. Overrides $HELM_HOME")
	p.StringVar(&tillerHost, "host", defaultHelmHost(), "address of tiller. Overrides $HELM_HOST")
	p.StringVar(&kubeContext, "kube-context", "", "name of the kubeconfig context to use")
	p.BoolVar(&flagDebug, "debug", false, "enable verbose output")
	p.StringVar(&tillerNamespace, "tiller-namespace", defaultTillerNamespace(), "namespace of tiller")

	// Tell gRPC not to log to console.
	grpclog.SetLogger(log.New(ioutil.Discard, "", log.LstdFlags))

	rup := newRepoUpdateCmd(out)
	rup.Deprecated = "use 'helm repo update'\n"

	cmd.AddCommand(
		newCreateCmd(out),
		newDeleteCmd(nil, out),
		newDependencyCmd(out),
		newFetchCmd(out),
		newGetCmd(nil, out),
		newHomeCmd(out),
		newHistoryCmd(nil, out),
		newInitCmd(out),
		newInspectCmd(nil, out),
		newInstallCmd(nil, out),
		newLintCmd(out),
		newListCmd(nil, out),
		newPackageCmd(nil, out),
		newRepoCmd(out),
		newRollbackCmd(nil, out),
		newSearchCmd(out),
		newServeCmd(out),
		newStatusCmd(nil, out),
		newUpgradeCmd(nil, out),
		newVerifyCmd(out),
		newVersionCmd(nil, out),
		newCompletionCmd(out, cmd),

		// Hidden documentation generator command: 'helm docs'
		newDocsCmd(out, cmd),

		// Deprecated
		rup,
	)

	// Find and add plugins
	loadPlugins(cmd, helmpath.Home(homePath()), out)

	return cmd
}
예제 #17
0
파일: serve.go 프로젝트: slack/helm
func newServeCmd(out io.Writer) *cobra.Command {
	srv := &serveCmd{out: out}
	cmd := &cobra.Command{
		Use:   "serve",
		Short: "start a local http web server",
		Long:  serveDesc,
		RunE: func(cmd *cobra.Command, args []string) error {
			srv.home = helmpath.Home(homePath())
			return srv.run()
		},
	}

	f := cmd.Flags()
	f.StringVar(&srv.repoPath, "repo-path", helmpath.Home(homePath()).LocalRepository(), "local directory path from which to serve charts")
	f.StringVar(&srv.address, "address", "localhost:8879", "address to listen on")

	return cmd
}
예제 #18
0
파일: fetch.go 프로젝트: kubernetes/helm
func (f *fetchCmd) run() error {
	pname := f.chartRef
	c := downloader.ChartDownloader{
		HelmHome: helmpath.Home(homePath()),
		Out:      f.out,
		Keyring:  f.keyring,
		Verify:   downloader.VerifyNever,
	}

	if f.verify {
		c.Verify = downloader.VerifyAlways
	} else if f.verifyLater {
		c.Verify = downloader.VerifyLater
	}

	// If untar is set, we fetch to a tempdir, then untar and copy after
	// verification.
	dest := f.destdir
	if f.untar {
		var err error
		dest, err = ioutil.TempDir("", "helm-")
		if err != nil {
			return fmt.Errorf("Failed to untar: %s", err)
		}
		defer os.RemoveAll(dest)
	}

	saved, v, err := c.DownloadTo(pname, f.version, dest)
	if err != nil {
		return err
	}

	if f.verify {
		fmt.Fprintf(f.out, "Verification: %v\n", v)
	}

	// After verification, untar the chart into the requested directory.
	if f.untar {
		ud := f.untardir
		if !filepath.IsAbs(ud) {
			ud = filepath.Join(f.destdir, ud)
		}
		if fi, err := os.Stat(ud); err != nil {
			if err := os.MkdirAll(ud, 0755); err != nil {
				return fmt.Errorf("Failed to untar (mkdir): %s", err)
			}

		} else if !fi.IsDir() {
			return fmt.Errorf("Failed to untar: %s is not a directory", ud)
		}

		return chartutil.ExpandFile(ud, saved)
	}
	return nil
}
예제 #19
0
파일: install.go 프로젝트: runseb/helm
// locateChartPath looks for a chart directory in known places, and returns either the full path or an error.
//
// This does not ensure that the chart is well-formed; only that the requested filename exists.
//
// Order of resolution:
// - current working directory
// - if path is absolute or begins with '.', error out here
// - chart repos in $HELM_HOME
//
// If 'verify' is true, this will attempt to also verify the chart.
func locateChartPath(name string, verify bool, keyring string) (string, error) {
	if fi, err := os.Stat(name); err == nil {
		abs, err := filepath.Abs(name)
		if err != nil {
			return abs, err
		}
		if verify {
			if fi.IsDir() {
				return "", errors.New("cannot verify a directory")
			}
			if _, err := downloader.VerifyChart(abs, keyring); err != nil {
				return "", err
			}
		}
		return abs, nil
	}
	if filepath.IsAbs(name) || strings.HasPrefix(name, ".") {
		return name, fmt.Errorf("path %q not found", name)
	}

	crepo := filepath.Join(repositoryDirectory(), name)
	if _, err := os.Stat(crepo); err == nil {
		return filepath.Abs(crepo)
	}

	// Try fetching the chart from a remote repo into a tmpdir
	origname := name
	if filepath.Ext(name) != ".tgz" {
		name += ".tgz"
	}

	dl := downloader.ChartDownloader{
		HelmHome: helmpath.Home(homePath()),
		Out:      os.Stdout,
		Keyring:  keyring,
	}
	if verify {
		dl.Verify = downloader.VerifyAlways
	}

	if _, err := dl.DownloadTo(name, "."); err == nil {
		lname, err := filepath.Abs(filepath.Base(name))
		if err != nil {
			return lname, err
		}
		fmt.Printf("Fetched %s to %s\n", origname, lname)
		return lname, nil
	}

	return name, fmt.Errorf("file %q not found", origname)
}
예제 #20
0
// tempHelmHome sets up a Helm Home in a temp dir.
//
// This does not clean up the directory. You must do that yourself.
// You  must also set helmHome yourself.
func tempHelmHome(t *testing.T) (string, error) {
	oldhome := helmHome
	dir, err := ioutil.TempDir("", "helm_home-")
	if err != nil {
		return "n/", err
	}

	helmHome = dir
	if err := ensureTestHome(helmpath.Home(helmHome), t); err != nil {
		return "n/", err
	}
	helmHome = oldhome
	return dir, nil
}
예제 #21
0
func newRepoListCmd(out io.Writer) *cobra.Command {
	list := &repoListCmd{
		out: out,
	}

	cmd := &cobra.Command{
		Use:   "list [flags]",
		Short: "list chart repositories",
		RunE: func(cmd *cobra.Command, args []string) error {
			list.home = helmpath.Home(homePath())
			return list.run()
		},
	}

	return cmd
}
예제 #22
0
파일: search.go 프로젝트: runseb/helm
func newSearchCmd(out io.Writer) *cobra.Command {
	sc := &searchCmd{out: out, helmhome: helmpath.Home(homePath())}

	cmd := &cobra.Command{
		Use:   "search [keyword]",
		Short: "search for a keyword in charts",
		Long:  searchDesc,
		RunE: func(cmd *cobra.Command, args []string) error {
			return sc.run(args)
		},
		PreRunE: requireInit,
	}

	cmd.Flags().BoolVarP(&sc.regexp, "regexp", "r", false, "use regular expressions for searching")

	return cmd
}
예제 #23
0
func newRepoUpdateCmd(out io.Writer) *cobra.Command {
	u := &repoUpdateCmd{
		out:    out,
		update: updateCharts,
	}
	cmd := &cobra.Command{
		Use:     "update",
		Aliases: []string{"up"},
		Short:   "update information on available charts in the chart repositories",
		Long:    updateDesc,
		RunE: func(cmd *cobra.Command, args []string) error {
			u.home = helmpath.Home(homePath())
			return u.run()
		},
	}
	return cmd
}
예제 #24
0
func newSearchCmd(out io.Writer) *cobra.Command {
	sc := &searchCmd{out: out, helmhome: helmpath.Home(homePath())}

	cmd := &cobra.Command{
		Use:   "search [keyword]",
		Short: "search for a keyword in charts",
		Long:  searchDesc,
		RunE: func(cmd *cobra.Command, args []string) error {
			return sc.run(args)
		},
	}

	f := cmd.Flags()
	f.BoolVarP(&sc.regexp, "regexp", "r", false, "use regular expressions for searching")
	f.BoolVarP(&sc.versions, "versions", "l", false, "show the long listing, with each version of each chart on its own line")

	return cmd
}
예제 #25
0
func TestDownloadTo(t *testing.T) {
	hh, err := ioutil.TempDir("", "helm-downloadto-")
	if err != nil {
		t.Fatal(err)
	}
	defer os.RemoveAll(hh)

	dest := filepath.Join(hh, "dest")
	os.MkdirAll(dest, 0755)

	// Set up a fake repo
	srv := repotest.NewServer(hh)
	defer srv.Stop()
	if _, err := srv.CopyCharts("testdata/*.tgz*"); err != nil {
		t.Error(err)
		return
	}

	c := ChartDownloader{
		HelmHome: helmpath.Home("testdata/helmhome"),
		Out:      os.Stderr,
		Verify:   VerifyAlways,
		Keyring:  "testdata/helm-test-key.pub",
	}
	cname := "/signtest-0.1.0.tgz"
	where, v, err := c.DownloadTo(srv.URL()+cname, "", dest)
	if err != nil {
		t.Error(err)
		return
	}

	if expect := filepath.Join(dest, cname); where != expect {
		t.Errorf("Expected download to %s, got %s", expect, where)
	}

	if v.FileHash == "" {
		t.Error("File hash was empty, but verification is required.")
	}

	if _, err := os.Stat(filepath.Join(dest, cname)); err != nil {
		t.Error(err)
		return
	}
}
예제 #26
0
func TestDownloadTo_VerifyLater(t *testing.T) {
	hh, err := ioutil.TempDir("", "helm-downloadto-")
	if err != nil {
		t.Fatal(err)
	}
	defer os.RemoveAll(hh)

	dest := filepath.Join(hh, "dest")
	os.MkdirAll(dest, 0755)

	// Set up a fake repo
	srv := repotest.NewServer(hh)
	defer srv.Stop()
	if _, err := srv.CopyCharts("testdata/*.tgz*"); err != nil {
		t.Error(err)
		return
	}

	c := ChartDownloader{
		HelmHome: helmpath.Home("testdata/helmhome"),
		Out:      os.Stderr,
		Verify:   VerifyLater,
	}
	cname := "/signtest-0.1.0.tgz"
	where, _, err := c.DownloadTo(srv.URL()+cname, "", dest)
	if err != nil {
		t.Error(err)
		return
	}

	if expect := filepath.Join(dest, cname); where != expect {
		t.Errorf("Expected download to %s, got %s", expect, where)
	}

	if _, err := os.Stat(filepath.Join(dest, cname)); err != nil {
		t.Error(err)
		return
	}
	if _, err := os.Stat(filepath.Join(dest, cname+".prov")); err != nil {
		t.Error(err)
		return
	}
}
예제 #27
0
func TestRepoRemove(t *testing.T) {
	testURL := "https://test-url.com"

	b := bytes.NewBuffer(nil)

	home, err := tempHelmHome(t)
	if err != nil {
		t.Fatal(err)
	}
	defer os.Remove(home)
	hh := helmpath.Home(home)

	if err := removeRepoLine(b, testName, hh); err == nil {
		t.Errorf("Expected error removing %s, but did not get one.", testName)
	}
	if err := insertRepoLine(testName, testURL, hh); err != nil {
		t.Error(err)
	}

	mf, _ := os.Create(hh.CacheIndex(testName))
	mf.Close()

	b.Reset()
	if err := removeRepoLine(b, testName, hh); err != nil {
		t.Errorf("Error removing %s from repositories", testName)
	}
	if !strings.Contains(b.String(), "has been removed") {
		t.Errorf("Unexpected output: %s", b.String())
	}

	if _, err := os.Stat(hh.CacheIndex(testName)); err == nil {
		t.Errorf("Error cache file was not removed for repository %s", testName)
	}

	f, err := repo.LoadRepositoriesFile(hh.RepositoryFile())
	if err != nil {
		t.Error(err)
	}

	if f.Has(testName) {
		t.Errorf("%s was not successfully removed from repositories list", testName)
	}
}
예제 #28
0
파일: package.go 프로젝트: kubernetes/helm
func newPackageCmd(out io.Writer) *cobra.Command {
	pkg := &packageCmd{
		out: out,
	}

	cmd := &cobra.Command{
		Use:   "package [flags] [CHART_PATH] [...]",
		Short: "package a chart directory into a chart archive",
		Long:  packageDesc,
		RunE: func(cmd *cobra.Command, args []string) error {
			pkg.home = helmpath.Home(homePath())
			if len(args) == 0 {
				return fmt.Errorf("This command needs at least one argument, the path to the chart.")
			}
			if pkg.sign {
				if pkg.key == "" {
					return errors.New("--key is required for signing a package")
				}
				if pkg.keyring == "" {
					return errors.New("--keyring is required for signing a package")
				}
			}
			for i := 0; i < len(args); i++ {
				pkg.path = args[i]
				if err := pkg.run(cmd, args); err != nil {
					return err
				}
			}
			return nil
		},
	}

	f := cmd.Flags()
	f.BoolVar(&pkg.save, "save", true, "save packaged chart to local chart repository")
	f.BoolVar(&pkg.sign, "sign", false, "use a PGP private key to sign this package")
	f.StringVar(&pkg.key, "key", "", "name of the key to use when signing. Used if --sign is true")
	f.StringVar(&pkg.keyring, "keyring", defaultKeyring(), "location of a public keyring")

	return cmd
}
예제 #29
0
func newRepoRemoveCmd(out io.Writer) *cobra.Command {
	remove := &repoRemoveCmd{
		out: out,
	}

	cmd := &cobra.Command{
		Use:     "remove [flags] [NAME]",
		Aliases: []string{"rm"},
		Short:   "remove a chart repository",
		RunE: func(cmd *cobra.Command, args []string) error {
			if err := checkArgsLength(len(args), "name of chart repository"); err != nil {
				return err
			}
			remove.name = args[0]
			remove.home = helmpath.Home(homePath())

			return remove.run()
		},
	}

	return cmd
}
예제 #30
0
파일: init_test.go 프로젝트: slack/helm
func TestInitCmd(t *testing.T) {
	home, err := ioutil.TempDir("", "helm_home")
	if err != nil {
		t.Fatal(err)
	}
	defer os.Remove(home)

	var buf bytes.Buffer
	fake := testclient.Fake{}
	cmd := &initCmd{out: &buf, home: helmpath.Home(home), kubeClient: fake.Extensions()}
	if err := cmd.run(); err != nil {
		t.Errorf("expected error: %v", err)
	}
	actions := fake.Actions()
	if action, ok := actions[0].(testclient.CreateAction); !ok || action.GetResource() != "deployments" {
		t.Errorf("unexpected action: %v, expected create deployment", actions[0])
	}
	expected := "Tiller (the helm server side component) has been installed into your Kubernetes Cluster."
	if !strings.Contains(buf.String(), expected) {
		t.Errorf("expected %q, got %q", expected, buf.String())
	}
}