func (m *Manager) loadChartDir() (*chart.Chart, error) { if fi, err := os.Stat(m.ChartPath); err != nil { return nil, fmt.Errorf("could not find %s: %s", m.ChartPath, err) } else if !fi.IsDir() { return nil, errors.New("only unpacked charts can be updated") } return chartutil.LoadDir(m.ChartPath) }
func TestCreateCmd(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) // 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) 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) } }
func runPackage(cmd *cobra.Command, args []string) error { path := "." if len(args) > 0 { path = args[0] } else { return fmt.Errorf("This command needs at least one argument, the path to the chart.") } path, err := filepath.Abs(path) if err != nil { return err } ch, err := chartutil.LoadDir(path) if err != nil { return err } if filepath.Base(path) != ch.Metadata.Name { return fmt.Errorf("directory name (%s) and Chart.yaml name (%s) must match", filepath.Base(path), ch.Metadata.Name) } // Save to the current working directory. cwd, err := os.Getwd() if err != nil { return err } name, err := chartutil.Save(ch, cwd) if err == nil && flagDebug { cmd.Printf("Saved %s to current directory\n", name) } // Save to $HELM_HOME/local directory. This is second, because we don't want // the case where we saved here, but didn't save to the default destination. if save { if err := repo.AddChartToLocalRepo(ch, localRepoDirectory()); err != nil { return err } else if flagDebug { cmd.Printf("Saved %s to %s\n", name, localRepoDirectory()) } } return err }
func (p *packageCmd) run(cmd *cobra.Command, args []string) error { path, err := filepath.Abs(p.path) if err != nil { return err } ch, err := chartutil.LoadDir(path) if err != nil { return err } if filepath.Base(path) != ch.Metadata.Name { return fmt.Errorf("directory name (%s) and Chart.yaml name (%s) must match", filepath.Base(path), ch.Metadata.Name) } // Save to the current working directory. cwd, err := os.Getwd() if err != nil { return err } name, err := chartutil.Save(ch, cwd) if err == nil && flagDebug { fmt.Fprintf(p.out, "Saved %s to current directory\n", name) } // Save to $HELM_HOME/local directory. This is second, because we don't want // the case where we saved here, but didn't save to the default destination. if p.save { lr := p.home.LocalRepository() if err := repo.AddChartToLocalRepo(ch, lr); err != nil { return err } else if flagDebug { fmt.Fprintf(p.out, "Saved %s to %s\n", name, lr) } } if p.sign { err = p.clearsign(name) } return err }
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") } }