mirror of
https://github.com/helmfile/helmfile.git
synced 2026-10-04 16:45:43 +02:00
initial helmfile impl
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
package helmexec
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
command = "helm"
|
||||
)
|
||||
|
||||
type execer struct {
|
||||
writer io.Writer
|
||||
extra []string
|
||||
}
|
||||
|
||||
func NewHelmExec(writer io.Writer) Interface {
|
||||
return &execer{writer: writer}
|
||||
}
|
||||
|
||||
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) 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.writer != nil {
|
||||
helm.writer.Write([]byte(fmt.Sprintf("exec: helm %s\n", strings.Join(cmdargs, " "))))
|
||||
}
|
||||
|
||||
cmd := exec.Command(command, args...)
|
||||
cmd.Dir = dir
|
||||
return cmd.CombinedOutput()
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package helmexec
|
||||
|
||||
type Interface interface {
|
||||
SetExtraArgs(args ...string)
|
||||
|
||||
AddRepo(name, repository string) error
|
||||
UpdateRepo() error
|
||||
|
||||
SyncChart(name, chart string, flags ...string) error
|
||||
DeleteChart(name string) error
|
||||
}
|
||||
Reference in New Issue
Block a user