feat(helm): adding helm install feature
now we can ask bootstraper to install helm charts as "packages"
This commit is contained in:
@ -14,9 +14,22 @@ type SystemPackage struct {
|
||||
Action string `json:"action"`
|
||||
OS string `json:"os"`
|
||||
Distribution string `json:"distribution"`
|
||||
NameSpace string `json:"namespace"`
|
||||
Repository string `json:"repository"`
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
func (p *SystemPackage) SetDistribution() error {
|
||||
|
||||
// If the package type is helm or kubectl we set distribution to k8s
|
||||
if p.Type == "helm" || p.Type == "kubectl" {
|
||||
p.Distribution = p.Type
|
||||
if len(p.NameSpace) == 0 {
|
||||
p.NameSpace = p.Name
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
OSConfig, err := utils.ReadOSRelease()
|
||||
if err != nil {
|
||||
return err
|
||||
@ -56,6 +69,12 @@ func (p *SystemPackage) Manage() error {
|
||||
_, stdErr, pkErr = utils.RunSystemCommand("yum", "install", "-y", p.Name)
|
||||
case "arch":
|
||||
_, stdErr, pkErr = utils.RunSystemCommand("pacman", "-Suy", p.Name)
|
||||
case "helm":
|
||||
toInstall := fmt.Sprintf("%s/%s", p.Repository, p.Name)
|
||||
nameSpaceOPT := fmt.Sprintf("--namespace=%s", p.NameSpace)
|
||||
_, stdErr, pkErr = utils.RunSystemCommand("helm", "upgrade", "--install", p.Name, nameSpaceOPT, toInstall)
|
||||
case "kubectl":
|
||||
_, stdErr, pkErr = utils.RunSystemCommand("kubectl", "apply", p.URL)
|
||||
default:
|
||||
pkErr = fmt.Errorf("Unsupported OS %s [%s]", p.OS, stdErr)
|
||||
}
|
||||
|
@ -1,11 +1,54 @@
|
||||
package templater
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"forge.cadoles.com/pcaseiro/templatefile/pkg/utils"
|
||||
)
|
||||
|
||||
type HelmRepository struct {
|
||||
Repository
|
||||
}
|
||||
|
||||
func (hr *HelmRepository) repoExists() (bool, error) {
|
||||
var repos []HelmRepository
|
||||
|
||||
stdOut, stdErr, err := utils.RunSystemCommand("helm", "repo", "list", "-o", "json")
|
||||
if err != nil {
|
||||
return false, fmt.Errorf("%s %v", stdErr, err)
|
||||
}
|
||||
err = json.Unmarshal(stdOut, &repos)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
for _, repo := range repos {
|
||||
if repo.Name == hr.Name {
|
||||
return true, nil
|
||||
}
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func (hr *HelmRepository) Add() error {
|
||||
|
||||
repoExists, err := hr.repoExists()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if repoExists {
|
||||
return nil
|
||||
} else {
|
||||
_, stdErr, err := utils.RunSystemCommand("helm", "repo", "add", hr.Name, hr.URL)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%s %v", stdErr, err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
|
||||
func (hr *HelmRepository) Update() error {
|
||||
|
Reference in New Issue
Block a user