Esempio n. 1
0
// Resolve takes a chart and a location and checks whether the chart's dependencies are satisfied.
//
// The `installdir` is the location where installed charts are located. Typically
// this is in $HELM_HOME/workspace/charts.
//
// This returns a list of unsatisfied dependencies (NOT an error condition).
//
// It returns an error only if it cannot perform the task of resolving dependencies.
// Failed dependencies to not constitute an error.
func Resolve(cf *model.Chartfile, installdir string) ([]*model.Dependency, error) {
	if len(cf.Dependencies) == 0 {
		log.Debug("No dependencies to check. :achievement-unlocked:")
		return []*model.Dependency{}, nil
	}

	cache, err := dependencyCache(installdir)
	if err != nil {
		log.Debug("Failed to build dependency cache: %s", err)
		return []*model.Dependency{}, err
	}

	res := []*model.Dependency{}

	// TODO: This could be made more efficient.
	for _, check := range cf.Dependencies {
		resolved := false
		for n, chart := range cache {
			log.Debug("Checking if %s (%s) %s meets %s %s", chart.Name, n, chart.Version, check.Name, check.Version)
			if chart.Name == check.Name && check.VersionOK(chart.Version) {
				log.Debug("✔︎")
				resolved = true
				break
			}
		}
		if !resolved {
			log.Debug("No matches found for %s %s", check.Name, check.Version)
			res = append(res, check)
		}
	}
	return res, nil
}
Esempio n. 2
0
// Check by chart directory name whether a chart is installed.
//
// This does NOT check the Chart.yaml file.
func chartInstalled(chart, home string) bool {
	p := filepath.Join(home, WorkspaceChartPath, chart, "Chart.yaml")
	log.Debug("Looking for %q", p)
	if fi, err := os.Stat(p); err != nil || fi.IsDir() {
		log.Debug("No chart: %s", err)
		return false
	}
	return true
}
Esempio n. 3
0
func kubectlDelete(name, ktype, ns string) error {
	log.Debug("Deleting %s (%s)", name, ktype)
	a := []string{"delete", ktype, name}
	if ns != "" {
		a = append([]string{fmt.Sprintf("--namespace=%q", ns)}, a...)
	}

	cmd := exec.Command("kubectl", a...)

	if d, err := cmd.CombinedOutput(); err != nil {
		return fmt.Errorf("%s: %s", string(d), err)
	}
	return nil
}
Esempio n. 4
0
// ParseDir parses all of the manifests inside of a chart directory.
//
// The directory should be the Chart directory (contains Chart.yaml and manifests/)
//
// This will return an error if the directory does not exist, or if there is an
// error parsing or decoding any yaml files.
func ParseDir(chartDir string) ([]*Manifest, error) {
	dir := filepath.Join(chartDir, "manifests")
	files := []*Manifest{}

	if _, err := os.Stat(dir); err != nil {
		return files, err
	}

	// add manifest files
	walker := func(fname string, fi os.FileInfo, e error) error {
		log.Debug("Parsing %s", fname)
		// Chauncey was right.
		if e != nil {
			return e
		}

		if fi.IsDir() {
			return nil
		}

		if filepath.Ext(fname) != ".yaml" {
			log.Debug("Skipping %s. Not a YAML file.", fname)
			return nil
		}

		m, err := Parse(fname)
		if err != nil {
			return err
		}

		files = append(files, m...)

		return nil
	}

	return files, filepath.Walk(dir, walker)
}
Esempio n. 5
0
// PrintREADME prints the README file (if it exists) to the console.
func PrintREADME(chart, home string) {
	p := filepath.Join(home, WorkspaceChartPath, chart, "README.*")
	files, err := filepath.Glob(p)
	if err != nil || len(files) == 0 {
		// No README. Skip.
		log.Debug("No readme in %s", p)
		return
	}

	f, err := os.Open(files[0])
	if err != nil {
		log.Warn("Could not read README: %s", err)
		return
	}
	log.Msg(strings.Repeat("=", 40))
	io.Copy(log.Stdout, f)
	log.Msg(strings.Repeat("=", 40))
	f.Close()

}
Esempio n. 6
0
func Install(chart, home, namespace string) {
	Fetch(chart, chart, home)
	log.Info("kubectl --namespace=%q create -f %s.yaml", namespace, chart)
	if !chartInstalled(chart, home) {
		log.Info("No installed chart named %q. Installing now.", chart)
		Fetch(chart, chart, home)
	}

	d := filepath.Join(home, WorkspaceChartPath, chart, "manifests")
	log.Debug("Looking for manifests in %q", d)
	files, err := manifestFiles(d)
	if err != nil {
		log.Die("No manifests to install: %s", err)
	}

	for _, f := range files {
		if err := kubectlCreate(f, namespace); err != nil {
			log.Warn("Failed to install manifest %q: %s", f, err)
		}
	}
}