Skip to content

Commit

Permalink
Merge pull request #15 from norwoodj/add-ignore-file
Browse files Browse the repository at this point in the history
feat: adds support for an ignore file to exclude charts from processing
  • Loading branch information
norwoodj authored Aug 7, 2019
2 parents 3eff51f + 68966e5 commit 14ff149
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 11 deletions.
1 change: 1 addition & 0 deletions .helmdocsignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
example-charts/ignored
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ The tool includes the [sprig templating library](https://github.com/Masterminds/
in the templates you supply.


## Ignoring Chart Directories
helm-docs supports a `.helmdocsignore` file, exactly like a `.gitignore` file in which one can specify directories to ignore
when searching for charts. Directories specified need not be charts themselves, so parent directories containing potentially
many charts can be ignored and none of the charts underneath them will be processed.


## values.yaml metadata
This tool can parse descriptions and defaults of values from `values.yaml` files. The defaults are pulled directly from
the yaml in the file. Descriptions can be added for parameters by specifying the full path of the value and
Expand Down
3 changes: 2 additions & 1 deletion cmd/helm-docs/command_line.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ func newHelmDocsCommand(run func(cmd *cobra.Command, args []string)) (*cobra.Com

logLevelUsage := fmt.Sprintf("Level of logs that should printed, one of (%s)", strings.Join(possibleLogLevels(), ", "))
command.PersistentFlags().BoolP("dry-run", "d", false, "don't actually render any markdown files just print to stdout passed")
command.PersistentFlags().StringP("template-file", "t", "README.md.gotmpl", "gotemplate file to use to generate documentation for charts")
command.PersistentFlags().StringP("ignore-file", "i", ".helmdocsignore", "The filename to use as an ignore file to exclude chart directories")
command.PersistentFlags().StringP("log-level", "l", "info", logLevelUsage)
command.PersistentFlags().StringP("template-file", "t", "README.md.gotmpl", "gotemplate file to use to generate documentation for charts")

viper.AutomaticEnv()
viper.SetEnvPrefix("HELM_DOCS")
Expand Down
10 changes: 10 additions & 0 deletions example-charts/ignored/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
name: ignored
description: ingored chart
version: "0.2.0"
home: "https://github.com/norwoodj/helm-docs/example-charts/ignored"
sources: ["https://github.com/norwoodj/helm-docs/example-charts/ignored"]
engine: gotpl
maintainers:
- email: [email protected]
name: John Norwood
1 change: 1 addition & 0 deletions example-charts/ignored/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ require (
github.com/imdario/mergo v0.3.7 // indirect
github.com/sirupsen/logrus v1.2.0
github.com/spf13/cobra v0.0.5
github.com/spf13/pflag v1.0.3
github.com/spf13/viper v1.4.0
github.com/stretchr/testify v1.2.2
gopkg.in/yaml.v2 v2.2.2
k8s.io/helm v2.14.3+incompatible
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,5 @@ gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
k8s.io/helm v2.14.3+incompatible h1:uzotTcZXa/b2SWVoUzM1xiCXVjI38TuxMujS/1s+3Gw=
k8s.io/helm v2.14.3+incompatible/go.mod h1:LZzlS4LQBHfciFOurYBFkCMTaZ0D1l+p0teMg7TSULI=
32 changes: 24 additions & 8 deletions pkg/helm/chart_finder.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,45 @@
package helm

import (
"bufio"
"os"
"path/filepath"
"strings"

log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
"k8s.io/helm/pkg/ignore"
)

var ignoreDirectories = map[string]bool{
".git": true,
"templates": true,
var defaultIgnore = map[string]bool{
".git": true,
}

func FindChartDirectories() ([]string, error) {
chartDirs := make([]string, 0)
ignoreRules := ignore.Empty()
ignoreFilename := viper.GetString("ignore-file")
ignoreFile, err := os.Open(ignoreFilename)

err := filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
if err == nil {
ignoreRules, err = ignore.Parse(bufio.NewReader(ignoreFile))

if err != nil {
log.Warnf("Failed to parse ignore rules from file %s", ignoreFilename)
ignoreRules = ignore.Empty()
}
}

chartDirs := make([]string, 0)
err = filepath.Walk(".", func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}

if info.IsDir() && ignoreDirectories[path] {
if info.IsDir() && (ignoreRules.Ignore(path, info) || defaultIgnore[path]) {
log.Debugf("Ignoring directory %s", path)
return filepath.SkipDir
}

if strings.HasSuffix(path, "Chart.yaml") {
if filepath.Base(path) == "Chart.yaml" {
chartDirs = append(chartDirs, filepath.Dir(path))
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/helm/chart_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ type ChartDocumentationInfo struct {
ChartMeta
ChartRequirements

ChartValues map[interface{}]interface{}
ChartDirectory string
ChartValues map[interface{}]interface{}
ChartValuesDescriptions map[string]string
}

Expand Down

0 comments on commit 14ff149

Please sign in to comment.