mirror of
https://github.com/helmfile/helmfile.git
synced 2026-10-02 18:41:56 +02:00
This aims to improve on relative, absolute and <repo>/<chart> resolution for several of Helmfile manifest attributes as well as command line arguments. - Uusers may now utilize the `-f <filepath>` flag to reference a helmfile manifest outside of their PWD and have relative paths in the the `charts[*].values` and `charts[*].chart` attribute resolve relative to the manfiest's location properly - Values provided in the `--values` argument are no longer automatically assumed as relative path references from PWD but instead are conditionally joined with the PWD if it is determined they are relative file paths - Users may still signify a chart in the `.charts[*].chart` attribute as they do now by having an explicit `<repo>/<chart>` value
95 lines
1.9 KiB
Go
95 lines
1.9 KiB
Go
package helmexec
|
|
|
|
import (
|
|
"fmt"
|
|
"io"
|
|
"io/ioutil"
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
)
|
|
|
|
const (
|
|
command = "helm"
|
|
)
|
|
|
|
type execer struct {
|
|
writer io.Writer
|
|
kubeContext string
|
|
extra []string
|
|
}
|
|
|
|
func NewHelmExec(writer io.Writer, kubeContext string) Interface {
|
|
return &execer{
|
|
writer: writer,
|
|
kubeContext: kubeContext,
|
|
}
|
|
}
|
|
|
|
func (helm *execer) SetExtraArgs(args ...string) {
|
|
helm.extra = args
|
|
}
|
|
|
|
func (helm *execer) AddRepo(name, repository string) error {
|
|
out, err := helm.exec("repo", "add", name, repository)
|
|
if helm.writer != nil {
|
|
helm.writer.Write(out)
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (helm *execer) UpdateRepo() error {
|
|
out, err := helm.exec("repo", "update")
|
|
if helm.writer != nil {
|
|
helm.writer.Write(out)
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (helm *execer) SyncChart(name, chart string, flags ...string) error {
|
|
out, err := helm.exec(append([]string{"upgrade", "--install", name, chart}, flags...)...)
|
|
if helm.writer != nil {
|
|
helm.writer.Write(out)
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (helm *execer) DiffChart(name, chart string, flags ...string) error {
|
|
out, err := helm.exec(append([]string{"diff", name, chart}, flags...)...)
|
|
if helm.writer != nil {
|
|
helm.writer.Write(out)
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (helm *execer) DeleteChart(name string) error {
|
|
out, err := helm.exec("delete", name)
|
|
if helm.writer != nil {
|
|
helm.writer.Write(out)
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (helm *execer) exec(args ...string) ([]byte, error) {
|
|
dir, err := ioutil.TempDir("", "helmfile-exec")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer os.RemoveAll(dir)
|
|
|
|
cmdargs := args
|
|
if len(helm.extra) > 0 {
|
|
cmdargs = append(cmdargs, helm.extra...)
|
|
}
|
|
if helm.kubeContext != "" {
|
|
cmdargs = append(cmdargs, "--kube-context", helm.kubeContext)
|
|
}
|
|
if helm.writer != nil {
|
|
helm.writer.Write([]byte(fmt.Sprintf("exec: helm %s\n", strings.Join(cmdargs, " "))))
|
|
}
|
|
|
|
cmd := exec.Command(command, cmdargs...)
|
|
cmd.Dir = dir
|
|
return cmd.CombinedOutput()
|
|
}
|