Adding in diff plugin execution
- Simple copy-paste for the most part from sync job. I had started down the path of adding in a meta PluginCommand directive and trying to make it more modular, but in the end there are some small differences between the execution that were a bit difficult to model and it just got ugly. Figured keeping it simple would be easier to manage
This commit is contained in:
parent
2abc93cc62
commit
e0b324b69b
|
|
@ -76,6 +76,18 @@ func (helm *execer) SyncChart(name, chart string, flags ...string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (helm *execer) DiffChart(name, chart string, flags ...string) error {
|
||||||
|
chart, err := normalizeChart(chart)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
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 {
|
func (helm *execer) DeleteChart(name string) error {
|
||||||
out, err := helm.exec("delete", name)
|
out, err := helm.exec("delete", name)
|
||||||
if helm.writer != nil {
|
if helm.writer != nil {
|
||||||
|
|
|
||||||
|
|
@ -7,5 +7,6 @@ type Interface interface {
|
||||||
UpdateRepo() error
|
UpdateRepo() error
|
||||||
|
|
||||||
SyncChart(name, chart string, flags ...string) error
|
SyncChart(name, chart string, flags ...string) error
|
||||||
|
DiffChart(name, chart string, flags ...string) error
|
||||||
DeleteChart(name string) error
|
DeleteChart(name string) error
|
||||||
}
|
}
|
||||||
|
|
|
||||||
39
main.go
39
main.go
|
|
@ -107,6 +107,45 @@ func main() {
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "diff",
|
||||||
|
Usage: "diff charts from state file against env (helm diff)",
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
cli.StringSliceFlag{
|
||||||
|
Name: "values",
|
||||||
|
Usage: "additional value files to be merged into the command",
|
||||||
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "sync-repos",
|
||||||
|
Usage: "enable a repo sync prior to diffing",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Action: func(c *cli.Context) error {
|
||||||
|
state, helm, err := before(c)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if c.Bool("sync-repos") {
|
||||||
|
if errs := state.SyncRepos(helm); errs != nil && len(errs) > 0 {
|
||||||
|
for _, err := range errs {
|
||||||
|
fmt.Printf("err: %s\n", err.Error())
|
||||||
|
}
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
values := c.StringSlice("values")
|
||||||
|
|
||||||
|
if errs := state.DiffCharts(helm, values); errs != nil && len(errs) > 0 {
|
||||||
|
for _, err := range errs {
|
||||||
|
fmt.Printf("err: %s\n", err.Error())
|
||||||
|
}
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "sync",
|
Name: "sync",
|
||||||
Usage: "sync all resources from state file (repos && charts)",
|
Usage: "sync all resources from state file (repos && charts)",
|
||||||
|
|
|
||||||
|
|
@ -115,6 +115,44 @@ func (state *HelmState) SyncCharts(helm helmexec.Interface, additonalValues []st
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (state *HelmState) DiffCharts(helm helmexec.Interface, additonalValues []string) []error {
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
errs := []error{}
|
||||||
|
|
||||||
|
for _, chart := range state.Charts {
|
||||||
|
wg.Add(1)
|
||||||
|
go func(wg *sync.WaitGroup, chart ChartSpec) {
|
||||||
|
// Plugin command doesn't support explicit namespace
|
||||||
|
chart.Namespace = ""
|
||||||
|
flags, flagsErr := flagsForChart(&chart)
|
||||||
|
if flagsErr != nil {
|
||||||
|
errs = append(errs, flagsErr)
|
||||||
|
}
|
||||||
|
for _, value := range additonalValues {
|
||||||
|
wd, wdErr := os.Getwd()
|
||||||
|
if wdErr != nil {
|
||||||
|
errs = append(errs, wdErr)
|
||||||
|
}
|
||||||
|
valfile := filepath.Join(wd, value)
|
||||||
|
flags = append(flags, "--values", valfile)
|
||||||
|
}
|
||||||
|
if len(errs) == 0 {
|
||||||
|
if err := helm.DiffChart(chart.Name, chart.Chart, flags...); err != nil {
|
||||||
|
errs = append(errs, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
wg.Done()
|
||||||
|
}(&wg, chart)
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
|
if len(errs) != 0 {
|
||||||
|
return errs
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (state *HelmState) DeleteCharts(helm helmexec.Interface) []error {
|
func (state *HelmState) DeleteCharts(helm helmexec.Interface) []error {
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
errs := []error{}
|
errs := []error{}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue