|
|
@ -1,19 +1,3 @@
|
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright The Helm Authors.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
|
|
|
limitations under the License.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
package action
|
|
|
|
package action
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
import (
|
|
|
@ -25,12 +9,11 @@ import (
|
|
|
|
|
|
|
|
|
|
|
|
"helm.sh/helm/v3/pkg/chartutil"
|
|
|
|
"helm.sh/helm/v3/pkg/chartutil"
|
|
|
|
"helm.sh/helm/v3/pkg/lint"
|
|
|
|
"helm.sh/helm/v3/pkg/lint"
|
|
|
|
|
|
|
|
"helm.sh/helm/v3/pkg/lint/rules"
|
|
|
|
"helm.sh/helm/v3/pkg/lint/support"
|
|
|
|
"helm.sh/helm/v3/pkg/lint/support"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
// Lint is the action for checking that the semantics of a chart are well-formed.
|
|
|
|
// Lint is the action for checking that the semantics of a chart are well-formed.
|
|
|
|
//
|
|
|
|
|
|
|
|
// It provides the implementation of 'helm lint'.
|
|
|
|
|
|
|
|
type Lint struct {
|
|
|
|
type Lint struct {
|
|
|
|
Strict bool
|
|
|
|
Strict bool
|
|
|
|
Namespace string
|
|
|
|
Namespace string
|
|
|
@ -39,25 +22,20 @@ type Lint struct {
|
|
|
|
KubeVersion *chartutil.KubeVersion
|
|
|
|
KubeVersion *chartutil.KubeVersion
|
|
|
|
IgnoreFilePath string
|
|
|
|
IgnoreFilePath string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// LintResult is the result of Lint
|
|
|
|
|
|
|
|
type LintResult struct {
|
|
|
|
type LintResult struct {
|
|
|
|
TotalChartsLinted int
|
|
|
|
TotalChartsLinted int
|
|
|
|
Messages []support.Message
|
|
|
|
Messages []support.Message
|
|
|
|
Errors []error
|
|
|
|
Errors []error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// NewLint creates a new Lint object with the given configuration.
|
|
|
|
|
|
|
|
func NewLint() *Lint {
|
|
|
|
func NewLint() *Lint {
|
|
|
|
return &Lint{}
|
|
|
|
return &Lint{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (l *Lint) Run(paths []string, vals map[string]interface{}) *LintResult {
|
|
|
|
func (l *Lint) Run(paths []string, vals map[string]interface{}) *LintResult {
|
|
|
|
lowestTolerance := support.ErrorSev
|
|
|
|
lowestTolerance := support.ErrorSev
|
|
|
|
if l.Strict {
|
|
|
|
if l.Strict {
|
|
|
|
lowestTolerance = support.WarningSev
|
|
|
|
lowestTolerance = support.WarningSev
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
result := &LintResult{}
|
|
|
|
result := &LintResult{}
|
|
|
|
for _, path := range paths {
|
|
|
|
for _, path := range paths {
|
|
|
|
linter, err := lintChart(path, vals, l.Namespace, l.KubeVersion, l.IgnoreFilePath)
|
|
|
|
linter, err := lintChart(path, vals, l.Namespace, l.KubeVersion, l.IgnoreFilePath)
|
|
|
@ -76,16 +54,6 @@ func (l *Lint) Run(paths []string, vals map[string]interface{}) *LintResult {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func HasWarningsOrErrors(result *LintResult) bool {
|
|
|
|
|
|
|
|
for _, msg := range result.Messages {
|
|
|
|
|
|
|
|
if msg.Severity > support.InfoSev {
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return len(result.Errors) > 0
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func lintChart(path string, vals map[string]interface{}, namespace string, kubeVersion *chartutil.KubeVersion, ignoreFilePath string) (support.Linter, error) {
|
|
|
|
func lintChart(path string, vals map[string]interface{}, namespace string, kubeVersion *chartutil.KubeVersion, ignoreFilePath string) (support.Linter, error) {
|
|
|
|
var chartPath string
|
|
|
|
var chartPath string
|
|
|
|
linter := support.Linter{}
|
|
|
|
linter := support.Linter{}
|
|
|
@ -120,10 +88,12 @@ func lintChart(path string, vals map[string]interface{}, namespace string, kubeV
|
|
|
|
chartPath = path
|
|
|
|
chartPath = path
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Guard: Error out if this is not a chart.
|
|
|
|
|
|
|
|
if _, err := os.Stat(filepath.Join(chartPath, "Chart.yaml")); err != nil {
|
|
|
|
if _, err := os.Stat(filepath.Join(chartPath, "Chart.yaml")); err != nil {
|
|
|
|
return linter, errors.Wrap(err, "unable to check Chart.yaml file in chart")
|
|
|
|
return linter, errors.Wrap(err, "Chart.yaml file not found in chart")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ignorePatterns, err := rules.ParseIgnoreFile(ignoreFilePath)
|
|
|
|
return lint.AllWithKubeVersion(chartPath, vals, namespace, kubeVersion, ignoreFilePath), nil
|
|
|
|
if err != nil {
|
|
|
|
|
|
|
|
return linter, errors.Wrap(err, "failed to parse .helmlintignore file")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return lint.AllWithKubeVersion(chartPath, vals, namespace, kubeVersion, ignorePatterns), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|