Skip to content

Commit

Permalink
Discover chart name and version from Chart.yaml file
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha committed Feb 28, 2022
1 parent c78eaef commit 935291a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/spf13/pflag v1.0.5
k8s.io/apimachinery v0.21.1
sigs.k8s.io/kustomize/kyaml v0.1.12
sigs.k8s.io/yaml v1.2.0
)

require (
Expand All @@ -24,5 +25,4 @@ require (
golang.org/x/text v0.3.4 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
)
29 changes: 24 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
iofs "io/fs"
"io/ioutil"
"os"
"path/filepath"
"strings"
"text/template"

Expand All @@ -31,14 +32,16 @@ import (

"github.com/olekukonko/tablewriter"
flag "github.com/spf13/pflag"
y2 "k8s.io/apimachinery/pkg/util/yaml"
ylib "k8s.io/apimachinery/pkg/util/yaml"
"sigs.k8s.io/kustomize/kyaml/yaml"
yaml2 "sigs.k8s.io/yaml"
)

var (
docFile *string = flag.StringP("doc", "d", "", "Path to a project's doc.{json|yaml} info file")
valuesFile *string = flag.StringP("values", "v", "", "Path to chart values file")
tplFile *string = flag.StringP("template", "t", "readme2.tpl", "Path to a doc template file")
docFile = flag.StringP("doc", "d", "", "Path to a project's doc.{json|yaml} info file")
chartFile = flag.StringP("chart", "c", "", "Path to Chart.yaml file")
valuesFile = flag.StringP("values", "v", "", "Path to chart values file")
tplFile = flag.StringP("template", "t", "readme2.tpl", "Path to a doc template file")
)

func main() {
Expand All @@ -48,7 +51,7 @@ func main() {
if err != nil {
panic(err)
}
reader := y2.NewYAMLOrJSONDecoder(f, 2048)
reader := ylib.NewYAMLOrJSONDecoder(f, 2048)
var doc api.DocInfo
err = reader.Decode(&doc)
if err != nil && err != io.EOF {
Expand Down Expand Up @@ -115,6 +118,22 @@ func main() {
panic(err)
}

{
if *chartFile == "" {
*chartFile = filepath.Join(filepath.Dir(*valuesFile), "Chart.yaml")
}
data, err := ioutil.ReadFile(*chartFile)
if err != nil {
panic(err)
}
var ci api.ChartInfo
if err = yaml2.Unmarshal(data, &ci); err != nil {
panic(err)
}
doc.Chart.Name = ci.Name
doc.Chart.Version = ci.Version
}

tplReadme, err := ioutil.ReadFile(*tplFile)
if err != nil {
if os.IsNotExist(err) {
Expand Down
3 changes: 2 additions & 1 deletion walk/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ func (l Walker) walkMap() (*yaml.RNode, error) {
Visitor: l,
Schema: s,
Source: fv,
Path: append(l.Path, key)}.Walk()
Path: append(l.Path, key),
}.Walk()
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 935291a

Please sign in to comment.