Beispiel #1
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
}
Beispiel #2
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 := filepath.Join(homedir, WorkspaceChartPath, lname, "Chart.yaml")
	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, filepath.Join(homedir, WorkspaceChartPath))
	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", filepath.Join(homedir, WorkspaceChartPath, lname))
	log.Info("Done")
}
Beispiel #3
0
func search(term, base, table string, charts map[string]*chart.Chartfile) error {
	dirs, err := filepath.Glob(base)
	if err != nil {
		return fmt.Errorf("No results found. %s", err)
	} else if len(dirs) == 0 {
		return errors.New("No results found.")
	}

	r, err := regexp.Compile(term)
	if err != nil {
		log.Die("Invalid expression %q: %s", term, err)
	}

	for _, dir := range dirs {
		cname := filepath.Join(table, filepath.Base(dir))
		chrt, err := chart.LoadChartfile(filepath.Join(dir, "Chart.yaml"))

		if err != nil {
			// This dir is not a chart. Skip it.
			continue
		} else if r.MatchString(chrt.Name) || r.MatchString(chrt.Description) {
			charts[cname] = chrt
		}
	}

	return nil
}
Beispiel #4
0
// List lists all of the local charts.
func List(homedir string) {
	md := filepath.Join(homedir, WorkspaceChartPath, "*")
	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, "Chart.yaml")); err == nil {
			log.Info("\t%s (%s %s) - %s", cname, ch.Name, ch.Version, ch.Description)
			continue
		}
		log.Info("\t%s (unknown)", cname)
	}
}
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)
	}
}
Beispiel #6
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 := filepath.Join(homedir, CachePath, table, chartLocal, "Chart.yaml")

	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)
	}
}