Esempio n. 1
0
func TestUpgradeCmd(t *testing.T) {
	tmpChart, _ := ioutil.TempDir("testdata", "tmp")
	defer os.RemoveAll(tmpChart)
	cfile := &chart.Metadata{
		Name:        "testUpgradeChart",
		Description: "A Helm chart for Kubernetes",
		Version:     "0.1.0",
	}
	chartPath, err := chartutil.Create(cfile, tmpChart)
	if err != nil {
		t.Errorf("Error creating chart for upgrade: %v", err)
	}
	ch, _ := chartutil.Load(chartPath)
	_ = releaseMock(&releaseOptions{
		name:  "funny-bunny",
		chart: ch,
	})

	// update chart version
	cfile = &chart.Metadata{
		Name:        "testUpgradeChart",
		Description: "A Helm chart for Kubernetes",
		Version:     "0.1.2",
	}

	chartPath, err = chartutil.Create(cfile, tmpChart)
	if err != nil {
		t.Errorf("Error creating chart: %v", err)
	}
	ch, err = chartutil.Load(chartPath)
	if err != nil {
		t.Errorf("Error loading updated chart: %v", err)
	}

	tests := []releaseCase{
		{
			name:     "upgrade a release",
			args:     []string{"funny-bunny", chartPath},
			resp:     releaseMock(&releaseOptions{name: "funny-bunny", version: 2, chart: ch}),
			expected: "funny-bunny has been upgraded. Happy Helming!\n",
		},
		{
			name:     "install a release with 'upgrade --install'",
			args:     []string{"zany-bunny", chartPath},
			flags:    []string{"-i"},
			resp:     releaseMock(&releaseOptions{name: "zany-bunny", version: 1, chart: ch}),
			expected: "zany-bunny has been upgraded. Happy Helming!\n",
		},
	}

	cmd := func(c *fakeReleaseClient, out io.Writer) *cobra.Command {
		return newUpgradeCmd(c, out)
	}

	runReleaseCases(t, tests, cmd)

}
Esempio n. 2
0
func (c *createCmd) run() error {
	fmt.Fprintf(c.out, "Creating %s\n", c.name)

	chartname := filepath.Base(c.name)
	cfile := &chart.Metadata{
		Name:        chartname,
		Description: "A Helm chart for Kubernetes",
		Version:     "0.1.0",
	}

	_, err := chartutil.Create(cfile, filepath.Dir(c.name))
	return err
}
Esempio n. 3
0
func runCreate(cmd *cobra.Command, args []string) error {
	if len(args) == 0 {
		return errors.New("the name of the new chart is required")
	}
	cname := args[0]
	cmd.Printf("Creating %s\n", cname)

	chartname := filepath.Base(cname)
	cfile := &chart.Metadata{
		Name:        chartname,
		Description: "A Helm chart for Kubernetes",
		Version:     "0.1.0",
	}

	_, err := chartutil.Create(cfile, filepath.Dir(cname))
	return err
}
Esempio n. 4
0
func (c *createCmd) run() error {
	fmt.Fprintf(c.out, "Creating %s\n", c.name)

	chartname := filepath.Base(c.name)
	cfile := &chart.Metadata{
		Name:        chartname,
		Description: "A Helm chart for Kubernetes",
		Version:     "0.1.0",
		ApiVersion:  chartutil.ApiVersionV1,
	}

	if c.starter != "" {
		// Create from the starter
		lstarter := filepath.Join(c.home.Starters(), c.starter)
		return chartutil.CreateFrom(cfile, filepath.Dir(c.name), lstarter)
	}

	_, err := chartutil.Create(cfile, filepath.Dir(c.name))
	return err
}
Esempio n. 5
0
// createTestingChart creates a basic chart that depends on reqtest-0.1.0
//
// The baseURL can be used to point to a particular repository server.
func createTestingChart(dest, name, baseURL string) error {
	cfile := &chart.Metadata{
		Name:    name,
		Version: "1.2.3",
	}
	dir := filepath.Join(dest, name)
	_, err := chartutil.Create(cfile, dest)
	if err != nil {
		return err
	}
	req := &chartutil.Requirements{
		Dependencies: []*chartutil.Dependency{
			{Name: "reqtest", Version: "0.1.0", Repository: baseURL},
		},
	}
	data, err := yaml.Marshal(req)
	if err != nil {
		return err
	}

	return ioutil.WriteFile(filepath.Join(dir, "requirements.yaml"), data, 0655)
}
Esempio n. 6
0
func TestCreateStarterCmd(t *testing.T) {
	cname := "testchart"
	// Make a temp dir
	tdir, err := ioutil.TempDir("", "helm-create-")
	if err != nil {
		t.Fatal(err)
	}
	defer os.Remove(tdir)

	thome, err := tempHelmHome(t)
	if err != nil {
		t.Fatal(err)
	}
	old := homePath()
	helmHome = thome
	defer func() {
		helmHome = old
		os.RemoveAll(thome)
	}()

	// Create a starter.
	starterchart := filepath.Join(thome, "starters")
	os.Mkdir(starterchart, 0755)
	if dest, err := chartutil.Create(&chart.Metadata{Name: "starterchart"}, starterchart); err != nil {
		t.Fatalf("Could not create chart: %s", err)
	} else {
		t.Logf("Created %s", dest)
	}
	tplpath := filepath.Join(starterchart, "starterchart", "templates", "foo.tpl")
	if err := ioutil.WriteFile(tplpath, []byte("test"), 0755); err != nil {
		t.Fatalf("Could not write template: %s", err)
	}

	// CD into it
	pwd, err := os.Getwd()
	if err != nil {
		t.Fatal(err)
	}
	if err := os.Chdir(tdir); err != nil {
		t.Fatal(err)
	}
	defer os.Chdir(pwd)

	// Run a create
	cmd := newCreateCmd(os.Stdout)
	cmd.ParseFlags([]string{"--starter", "starterchart"})
	if err := cmd.RunE(cmd, []string{cname}); err != nil {
		t.Errorf("Failed to run create: %s", err)
		return
	}

	// Test that the chart is there
	if fi, err := os.Stat(cname); err != nil {
		t.Fatalf("no chart directory: %s", err)
	} else if !fi.IsDir() {
		t.Fatalf("chart is not directory")
	}

	c, err := chartutil.LoadDir(cname)
	if err != nil {
		t.Fatal(err)
	}

	if c.Metadata.Name != cname {
		t.Errorf("Expected %q name, got %q", cname, c.Metadata.Name)
	}
	if c.Metadata.ApiVersion != chartutil.ApiVersionV1 {
		t.Errorf("Wrong API version: %q", c.Metadata.ApiVersion)
	}

	if l := len(c.Templates); l != 5 {
		t.Errorf("Expected 5 templates, got %d", l)
	}

	found := false
	for _, tpl := range c.Templates {
		if tpl.Name == "templates/foo.tpl" {
			found = true
			data := tpl.Data
			if string(data) != "test" {
				t.Errorf("Expected template 'test', got %q", string(data))
			}
		}
	}
	if !found {
		t.Error("Did not find foo.tpl")
	}

}