squadron/internal/helm/chart.go
2023-09-21 10:25:54 +02:00

42 lines
1.1 KiB
Go

package helm
import (
"fmt"
"path"
"github.com/foomo/squadron/internal/util"
)
type Chart struct {
APIVersion string `yaml:"apiVersion"`
Name string `yaml:"name,omitempty"`
Description string `yaml:"description,omitempty"`
Type string `yaml:"type,omitempty"`
Version string `yaml:"version,omitempty"`
Dependencies []Dependency `yaml:"dependencies,omitempty"`
}
func NewChart(name, version string) *Chart {
return &Chart{
APIVersion: chartAPIVersionV2,
Name: name,
Description: fmt.Sprintf("A helm parent chart for squadron %v", name),
Type: defaultChartType,
Version: version,
}
}
func (c *Chart) AddDependency(alias string, cd Dependency) {
cd.Alias = alias
c.Dependencies = append(c.Dependencies, cd)
}
func (c *Chart) Generate(chartPath string, overrides interface{}) error {
// generate Chart.yaml
if err := util.GenerateYaml(path.Join(chartPath, chartFile), c); err != nil {
return err
}
// generate values.yaml
return util.GenerateYaml(path.Join(chartPath, valuesFile), overrides)
}