Adds HIP0019 readme, consolidates on main.debug()

pull/13205/head
Daniel J. Pritchett 1 year ago
parent 951178a4a4
commit 9e6a329545
No known key found for this signature in database

@ -30,8 +30,8 @@ import (
"helm.sh/helm/v3/pkg/chartutil" "helm.sh/helm/v3/pkg/chartutil"
"helm.sh/helm/v3/pkg/cli/values" "helm.sh/helm/v3/pkg/cli/values"
"helm.sh/helm/v3/pkg/getter" "helm.sh/helm/v3/pkg/getter"
"helm.sh/helm/v3/pkg/lint/support"
"helm.sh/helm/v3/pkg/lint/rules" "helm.sh/helm/v3/pkg/lint/rules"
"helm.sh/helm/v3/pkg/lint/support"
) )
var longLintHelp = ` var longLintHelp = `
@ -48,7 +48,6 @@ func newLintCmd(out io.Writer) *cobra.Command {
valueOpts := &values.Options{} valueOpts := &values.Options{}
var kubeVersion string var kubeVersion string
var lintIgnoreFile string var lintIgnoreFile string
var debug bool
cmd := &cobra.Command{ cmd := &cobra.Command{
Use: "lint PATH", Use: "lint PATH",
@ -87,16 +86,14 @@ func newLintCmd(out io.Writer) *cobra.Command {
} }
var ignorePatterns map[string][]string var ignorePatterns map[string][]string
if lintIgnoreFile != "" { if lintIgnoreFile != "" {
if debug { debug("\nUsing ignore file: %s\n", lintIgnoreFile)
fmt.Printf("\nUsing ignore file: %s\n", lintIgnoreFile)
}
ignorePatterns, err = rules.ParseIgnoreFile(lintIgnoreFile) ignorePatterns, err = rules.ParseIgnoreFile(lintIgnoreFile)
} }
var message strings.Builder var message strings.Builder
failed := 0 failed := 0
for _, path := range paths { for _, path := range paths {
result := client.Run([]string{path}, vals) result := client.Run([]string{path}, vals)
filteredResult := FilterIgnoredMessages(result, ignorePatterns, debug) filteredResult := FilterIgnoredMessages(result, ignorePatterns, settings.Debug)
fmt.Fprintf(&message, "==> Linting %s\n", path) fmt.Fprintf(&message, "==> Linting %s\n", path)
for _, msg := range filteredResult.Messages { for _, msg := range filteredResult.Messages {
fmt.Fprintf(&message, "%s\n", msg) fmt.Fprintf(&message, "%s\n", msg)
@ -125,7 +122,6 @@ func newLintCmd(out io.Writer) *cobra.Command {
f.BoolVar(&client.Quiet, "quiet", false, "print only warnings and errors") f.BoolVar(&client.Quiet, "quiet", false, "print only warnings and errors")
f.StringVar(&kubeVersion, "kube-version", "", "Kubernetes version used for capabilities and deprecation checks") f.StringVar(&kubeVersion, "kube-version", "", "Kubernetes version used for capabilities and deprecation checks")
f.StringVar(&lintIgnoreFile, "lint-ignore-file", "", "path to .helmlintignore file to specify ignore patterns") f.StringVar(&lintIgnoreFile, "lint-ignore-file", "", "path to .helmlintignore file to specify ignore patterns")
f.BoolVar(&debug, "debug", false, "enable debug output")
return cmd return cmd
} }
@ -171,3 +167,15 @@ func extractFullPathFromError(errorString string) string {
} }
return "" return ""
} }
/* TODO HIP-0019
- find ignore file path for a subchart
- add a chart or two for the end to end tests via testdata like in pkg/lint/lint_test.go
- review debug / output patterns across the helm project
Later/never
- XDG support
- helm config file support
- ignore file validation
-
*/

@ -0,0 +1,52 @@
## HIP-0019 helm lint ignore file
### manual test
```bash
go run ./cmd/helm lint ~/repositories/gitlab/chart/ --lint-ignore-file ~/repositories/gitlab/chart/.helmlintignore --with-subcharts --debug
```
```
go run ./cmd/helm lint ../gitlab/chart/ --lint-ignore-file ../gitlab/chart/.helmlintignore --with-subcharts --debug
```
### code flow diagram
```mermaid
flowchart LR
classDef lintIgnores fill:#f9f,stroke:#333,stroke-width:4px;
subgraph main["package main"]
Filter:::lintIgnores
root --> cmdHelmLint
cmdHelmLint[cmd/helm/lint.go] --> action
cmdHelmLint[cmd/helm/lint.go] --> lint/rules
cmdHelmLint[cmd/helm/lint.go] --> lint/support
cmdHelmLint --> Filter["FilterIgnoredMessages()"]
cmdHelmLint --> action
end
subgraph action["package action"]
action --> aNewLint["action.NewLint()"]
action --> typeLint["type action.Lint"]
action --> typeLintResult["type action.LintResult"]
end
subgraph lint["package lint"]
subgraph support["package lint/support"]
lint/support
lint/support --> Message["type support.Message"]
end
subgraph rules
parseIgnore:::lintIgnores
lint/rules
lint/rules --> parseIgnore["rules.ParseIgnoreFile()"]
end
end
```

@ -2,7 +2,9 @@ package rules
import ( import (
"bufio" "bufio"
"fmt"
"os" "os"
"path/filepath"
"strings" "strings"
) )
@ -31,3 +33,19 @@ func ParseIgnoreFile(filePath string) (map[string][]string, error) {
return patterns, scanner.Err() return patterns, scanner.Err()
} }
func IsIgnored(errorMessage string, patterns map[string][]string) bool {
for path, pathPatterns := range patterns {
cleanedPath := filepath.Clean(path)
if strings.Contains(errorMessage, cleanedPath) {
for _, pattern := range pathPatterns {
if strings.Contains(errorMessage, pattern) {
fmt.Printf("Ignoring error related to path: %s with pattern: %s\n", path, pattern)
return true
}
}
}
}
return false
}

@ -1,27 +0,0 @@
package rules
import (
"path/filepath"
"strings"
"fmt"
)
type LintResult struct {
Messages []string
}
func IsIgnored(errorMessage string, patterns map[string][]string) bool {
for path, pathPatterns := range patterns {
cleanedPath := filepath.Clean(path)
if strings.Contains(errorMessage, cleanedPath) {
for _, pattern := range pathPatterns {
if strings.Contains(errorMessage, pattern) {
fmt.Printf("Ignoring error related to path: %s with pattern: %s\n", path, pattern)
return true
}
}
}
}
return false
}
Loading…
Cancel
Save