Esempio n. 1
0
// Fetch gets a chart from the source repo and copies to the workdir.
//
// - chartName is the source
// - lname is the local name for that chart (chart-name); if blank, it is set to the chart.
// - homedir is the home directory for the user
func Fetch(chartName, lname, homedir string) {

	r := mustConfig(homedir).Repos
	repository, chartName := r.RepoChart(chartName)

	if lname == "" {
		lname = chartName
	}

	fetch(chartName, lname, homedir, repository)

	chartFilePath := helm.WorkspaceChartDirectory(homedir, lname, Chartfile)
	cfile, err := chart.LoadChartfile(chartFilePath)
	if err != nil {
		log.Die("Source is not a valid chart. Missing Chart.yaml: %s", err)
	}

	deps, err := dependency.Resolve(cfile, helm.WorkspaceChartDirectory(homedir))
	if err != nil {
		log.Warn("Could not check dependencies: %s", err)
		return
	}

	if len(deps) > 0 {
		log.Warn("Unsatisfied dependencies:")
		for _, d := range deps {
			log.Msg("\t%s %s", d.Name, d.Version)
		}
	}

	log.Info("Fetched chart into workspace %s", helm.WorkspaceChartDirectory(homedir, lname))
	log.Info("Done")
}
Esempio n. 2
0
// dependencyCache builds a map of chart and Chartfile.
func dependencyCache(chartdir string) (map[string]*chart.Chartfile, error) {
	cache := map[string]*chart.Chartfile{}
	dir, err := os.Open(chartdir)
	if err != nil {
		return cache, err
	}
	defer dir.Close()

	fis, err := dir.Readdir(0)
	if err != nil {
		return cache, err
	}

	for _, fi := range fis {
		if !fi.IsDir() {
			continue
		}
		cf, err := chart.LoadChartfile(filepath.Join(chartdir, fi.Name(), "Chart.yaml"))
		if err != nil {
			// If the chartfile does not load, we ignore it.
			continue
		}

		cache[fi.Name()] = cf
	}
	return cache, nil
}
Esempio n. 3
0
// NewIndex creats a new Index.
//
// NewIndex indexes all of the chart tables configured in the config.yaml file.
// For that reason, it may cause substantial overhead on a large set of repos.
func NewIndex(cfg *config.Configfile, cachedir string) *Index {
	lines := map[string]string{}
	charts := map[string]*chart.Chartfile{}
	for _, table := range cfg.Repos.Tables {
		def := cfg.Repos.Default == table.Name

		base := filepath.Join(cachedir, table.Name, "*/")
		dirs, err := filepath.Glob(base)
		if err != nil {
			log.Err("Failed to read table %s: %s", table.Name, err)
		}

		for _, dir := range dirs {
			bname := filepath.Base(dir)
			c, err := chart.LoadChartfile(filepath.Join(dir, "Chart.yaml"))
			if err != nil {
				// This is not a chart. Skip it.
				continue
			}
			name := table.Name + "/" + c.Name
			if def {
				name = c.Name
			}
			line := c.Name + sep + table.Name + "/" + bname + sep + c.Description + sep + c.Details
			lines[name] = strings.ToLower(line)
			charts[name] = c
		}
	}
	return &Index{lines: lines, charts: charts}
}
Esempio n. 4
0
func updateChartfile(src, dest, lname string) error {
	sc, err := chart.LoadChartfile(filepath.Join(src, Chartfile))
	if err != nil {
		return err
	}

	dc, err := chart.LoadChartfile(filepath.Join(dest, Chartfile))
	if err != nil {
		return err
	}

	dc.Name = lname
	dc.From = &chart.Dependency{
		Name:    sc.Name,
		Version: sc.Version,
		Repo:    chart.RepoName(src),
	}

	return dc.Save(filepath.Join(dest, Chartfile))
}
Esempio n. 5
0
// List lists all of the local charts.
func List(homedir string) {
	md := helm.WorkspaceChartDirectory(homedir, "*")
	charts, err := filepath.Glob(md)
	if err != nil {
		log.Warn("Could not find any charts in %q: %s", md, err)
	}
	for _, c := range charts {
		cname := filepath.Base(c)
		if ch, err := chart.LoadChartfile(filepath.Join(c, Chartfile)); err == nil {
			log.Info("\t%s (%s %s) - %s", cname, ch.Name, ch.Version, ch.Description)
			continue
		}
		log.Info("\t%s (unknown)", cname)
	}
}
Esempio n. 6
0
func TestResolve(t *testing.T) {
	cf, err := chart.LoadChartfile(filepath.Join(testInstalldir, "deptest/Chart.yaml"))
	if err != nil {
		t.Errorf("Could not load chartfile deptest/Chart.yaml: %s", err)
	}

	missed, err := Resolve(cf, testInstalldir)
	if err != nil {
		t.Errorf("could not resolve deps in %s: %s", testInstalldir, err)
	}
	if len(missed) != 2 {
		t.Fatalf("Expected dep3 and honkIfYouLoveDucks to be returned")
	}

	if missed[0].Name != "dep3" {
		t.Errorf("Expected dep3 in slot 0. Got %s", missed[0].Name)
	}
	if missed[1].Name != "honkIfYouLoveDucks" {
		t.Errorf("Expected honkIfYouLoveDucks in slot 1. Got %s", missed[1].Name)
	}
}
Esempio n. 7
0
// Info prints information about a chart.
//
// - chartName to display
// - homeDir is the helm home directory for the user
// - format is a optional Go template
func Info(chartName, homedir, format string) {
	r := mustConfig(homedir).Repos
	table, chartLocal := r.RepoChart(chartName)
	chartPath := helm.CacheDirectory(homedir, table, chartLocal, Chartfile)

	if format == "" {
		format = defaultInfoFormat
	}

	chart, err := chart.LoadChartfile(chartPath)
	if err != nil {
		log.Die("Could not find chart %s: %s", chartName, err.Error())
	}

	tmpl, err := template.New("info").Parse(format)
	if err != nil {
		log.Die("%s", err)
	}

	if err = tmpl.Execute(log.Stdout, chart); err != nil {
		log.Die("%s", err)
	}
}