当前位置: 首页>>代码示例>>Golang>>正文


Golang helmpath.Home函数代码示例

本文整理汇总了Golang中k8s/io/helm/cmd/helm/helmpath.Home函数的典型用法代码示例。如果您正苦于以下问题:Golang Home函数的具体用法?Golang Home怎么用?Golang Home使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Home函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestUpdateCharts

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")
	}
}
开发者ID:technosophos,项目名称:k8s-helm,代码行数:31,代码来源:repo_update_test.go

示例2: locateChartPath

// 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)
}
开发者ID:kubernetes,项目名称:helm,代码行数:63,代码来源:install.go

示例3: TestSetupEnv

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)
		}
	}
}
开发者ID:bacongobbler,项目名称:helm,代码行数:32,代码来源:plugins_test.go

示例4: newDependencyBuildCmd

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
}
开发者ID:technosophos,项目名称:k8s-helm,代码行数:26,代码来源:dependency_build.go

示例5: TestInitCmd_dryRun

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)
	}
}
开发者ID:technosophos,项目名称:k8s-helm,代码行数:34,代码来源:init_test.go

示例6: TestRepoAdd

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())
	}
}
开发者ID:slack,项目名称:helm,代码行数:31,代码来源:repo_add_test.go

示例7: TestInitCmd_clientOnly

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())
	}
}
开发者ID:kubernetes,项目名称:helm,代码行数:27,代码来源:init_test.go

示例8: TestInitCmd_exsits

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())
	}
}
开发者ID:kubernetes,项目名称:helm,代码行数:31,代码来源:init_test.go

示例9: TestInitCmd

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())
	}
}
开发者ID:kubernetes,项目名称:helm,代码行数:27,代码来源:init_test.go

示例10: TestEnsureHome

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)
	}
}
开发者ID:slack,项目名称:helm,代码行数:35,代码来源:init_test.go

示例11: newInitCmd

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
}
开发者ID:technosophos,项目名称:k8s-helm,代码行数:26,代码来源:init.go

示例12: TestUpdateCmd

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)
	}
}
开发者ID:technosophos,项目名称:k8s-helm,代码行数:33,代码来源:repo_update_test.go

示例13: TestResolveChartRef

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)
		}
	}
}
开发者ID:technosophos,项目名称:k8s-helm,代码行数:34,代码来源:chart_downloader_test.go

示例14: newDependencyUpdateCmd

// 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
}
开发者ID:runseb,项目名称:helm,代码行数:35,代码来源:dependency_update.go

示例15: TestRepoAddCmd

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)
		}
	}
}
开发者ID:slack,项目名称:helm,代码行数:33,代码来源:repo_add_test.go


注:本文中的k8s/io/helm/cmd/helm/helmpath.Home函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。