From fb39ebf0c938937c459c9e8b5017b3ee6ffb8f9b Mon Sep 17 00:00:00 2001 From: lazychanger Date: Thu, 17 Nov 2022 16:45:03 +0800 Subject: [PATCH 1/2] Fix package dependence and add more panic Signed-off-by: lazychanger --- cmd/helm-variable-in-values/main.go | 2 +- go.mod | 2 +- pkg/engine/engine.go | 14 ++++++++------ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/cmd/helm-variable-in-values/main.go b/cmd/helm-variable-in-values/main.go index 8ea5c18..04d1dfa 100644 --- a/cmd/helm-variable-in-values/main.go +++ b/cmd/helm-variable-in-values/main.go @@ -183,7 +183,7 @@ func buildVIVEngine(args []string) (*vivEngine.Engine, error) { } e := vivEngine.NewEngine(&vivEngine.Config{ - WorkDir: strings.TrimRight(workdir[0:len(workdir)-len(chartRequested.Name())], "/"), + WorkDir: strings.TrimRight(workdir, "/"), Values: values, Chart: chartRequested, }) diff --git a/go.mod b/go.mod index 472e052..b83fc27 100644 --- a/go.mod +++ b/go.mod @@ -8,6 +8,7 @@ require ( github.com/pkg/errors v0.9.1 github.com/spf13/cobra v1.6.0 github.com/stretchr/testify v1.8.0 + gopkg.in/yaml.v2 v2.4.0 helm.sh/helm/v3 v3.10.1 k8s.io/client-go v0.25.3 sigs.k8s.io/yaml v1.3.0 @@ -117,7 +118,6 @@ require ( google.golang.org/grpc v1.47.0 // indirect google.golang.org/protobuf v1.28.0 // indirect gopkg.in/inf.v0 v0.9.1 // indirect - gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect k8s.io/api v0.25.3 // indirect k8s.io/apiextensions-apiserver v0.25.2 // indirect diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go index 8336696..962cf54 100644 --- a/pkg/engine/engine.go +++ b/pkg/engine/engine.go @@ -26,7 +26,7 @@ func NewEngine(cfg *Config) *Engine { func (e *Engine) RenderTo(dst string) []string { if !path.IsAbs(dst) { - dst = path.Join(e.cfg.WorkDir, e.cfg.Chart.ChartFullPath(), dst) + dst = path.Join(e.cfg.WorkDir, dst) } if err := os.MkdirAll(dst, os.ModePerm); err != nil { @@ -37,15 +37,16 @@ func (e *Engine) RenderTo(dst string) []string { outputFiles, err := e.eachChart(e.cfg.Chart, "") if err != nil { - log.Println(err) - return []string{} + panic(errors.Wrap(err, "eachChart failed")) } - e.cfg.Chart.Templates = append(e.cfg.Chart.Templates, outputFiles...) - + //e.cfg.Chart.Templates = append(e.cfg.Chart.Templates, outputFiles...) + //e.cfg.Chart.Files = append(e.cfg.Chart.Files, outputFiles...) + //e.cfg.Chart.Raw = append(e.cfg.Chart.Raw, outputFiles...) + // tmpls, err := engine.Render(e.cfg.Chart, e.cfg.Values) if err != nil { - return []string{} + panic(errors.Wrap(err, "vivs render failed")) } outputRealFilepath := make([]string, len(outputFiles)) @@ -80,6 +81,7 @@ func (e *Engine) eachChart(ch *chart.Chart, node string) ([]*chart.File, error) continue } f.Name = path.Join(ch.ChartFullPath()[len(e.cfg.Chart.Name()):], f.Name) + log.Printf("load viv files: %s", f.Name) renderFiles = append(renderFiles, f) } From 33130ec7a723e760e8c142f46c5e411e4373a307 Mon Sep 17 00:00:00 2001 From: lazychanger Date: Thu, 17 Nov 2022 17:41:52 +0800 Subject: [PATCH 2/2] Fix missinq library template Signed-off-by: lazychanger --- pkg/engine/engine.go | 7 ++++--- plugin.yaml | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go index 962cf54..a1e2a16 100644 --- a/pkg/engine/engine.go +++ b/pkg/engine/engine.go @@ -40,10 +40,11 @@ func (e *Engine) RenderTo(dst string) []string { panic(errors.Wrap(err, "eachChart failed")) } - //e.cfg.Chart.Templates = append(e.cfg.Chart.Templates, outputFiles...) - //e.cfg.Chart.Files = append(e.cfg.Chart.Files, outputFiles...) - //e.cfg.Chart.Raw = append(e.cfg.Chart.Raw, outputFiles...) + e.cfg.Chart.Templates = append(e.cfg.Chart.Templates, outputFiles...) + e.cfg.Chart.Files = append(e.cfg.Chart.Files, outputFiles...) + e.cfg.Chart.Raw = append(e.cfg.Chart.Raw, outputFiles...) // + tmpls, err := engine.Render(e.cfg.Chart, e.cfg.Values) if err != nil { panic(errors.Wrap(err, "vivs render failed")) diff --git a/plugin.yaml b/plugin.yaml index 9972d5c..2634df6 100644 --- a/plugin.yaml +++ b/plugin.yaml @@ -1,5 +1,5 @@ name: "viv" -version: "0.2.3" +version: "0.2.4" usage: "get the last release name" command: "$HELM_PLUGIN_DIR/bin/helm-viv" description: "get the last release name"