github.com/caos/orbos@v1.5.14-0.20221103111702-e6cd0cea7ad4/internal/operator/boom/templator/helm/helmcommand/helm.go (about) 1 package helmcommand 2 3 import ( 4 "bytes" 5 "fmt" 6 "os/exec" 7 "strings" 8 9 helper2 "github.com/caos/orbos/internal/utils/helper" 10 ) 11 12 var ( 13 helmHomeFolder string = "helm" 14 chartsFolder string = "charts" 15 ) 16 17 func Init(basePath string) error { 18 return doHelmCommand(basePath, "init --client-only") 19 } 20 21 func addIfNotEmpty(one, two string) string { 22 if two != "" { 23 return strings.Join([]string{one, two}, " ") 24 } 25 return one 26 } 27 28 func doHelmCommand(basePath, command string) error { 29 30 helmHomeFolderPathAbs, err := helper2.GetAbsPath(basePath, helmHomeFolder) 31 if err != nil { 32 return err 33 } 34 35 helm := strings.Join([]string{"helm", "--home", helmHomeFolderPathAbs, command}, " ") 36 37 stderr := new(bytes.Buffer) 38 defer stderr.Reset() 39 cmd := exec.Command("/bin/sh", "-c", helm) 40 cmd.Stderr = stderr 41 if err := cmd.Run(); err != nil { 42 return fmt.Errorf("error while executing helm command \"%s\": %s: %w", helm, stderr.String(), err) 43 } 44 return nil 45 } 46 47 func doHelmCommandOutput(basePath, command string) ([]byte, error) { 48 helmHomeFolderPathAbs, err := helper2.GetAbsPath(basePath, helmHomeFolder) 49 if err != nil { 50 return nil, err 51 } 52 53 helm := strings.Join([]string{"helm", "--home", helmHomeFolderPathAbs, command}, " ") 54 55 cmd := exec.Command("/bin/sh", "-c", helm) 56 return cmd.Output() 57 }