mr feedback

Signed-off-by: bartem <bartem@ozon.ru>
pull/12280/head
bartem 2 years ago
parent 6531f093fe
commit a9694a1dcc

@ -22,6 +22,7 @@ import (
"strings" "strings"
"github.com/pkg/errors" "github.com/pkg/errors"
"helm.sh/helm/v3/pkg/lint/rules"
"helm.sh/helm/v3/pkg/chartutil" "helm.sh/helm/v3/pkg/chartutil"
"helm.sh/helm/v3/pkg/lint" "helm.sh/helm/v3/pkg/lint"
@ -126,5 +127,5 @@ func lintChart(path string, vals map[string]interface{}, releaseName, namespace
return linter, errors.Wrap(err, "unable to check Chart.yaml file in chart") return linter, errors.Wrap(err, "unable to check Chart.yaml file in chart")
} }
return lint.AllWithKubeVersion(chartPath, vals, releaseName, namespace, kubeVersion), nil return lint.AllWithKubeVersion(chartPath, vals, namespace, kubeVersion, rules.WithReleaseName(releaseName)), nil
} }

@ -25,19 +25,19 @@ import (
) )
// All runs all of the available linters on the given base directory. // All runs all of the available linters on the given base directory.
func All(basedir string, values map[string]interface{}, releaseName, namespace string, _ bool) support.Linter { func All(basedir string, values map[string]interface{}, namespace string, _ bool, opts ...rules.TemplateOption) support.Linter {
return AllWithKubeVersion(basedir, values, releaseName, namespace, nil) return AllWithKubeVersion(basedir, values, namespace, nil, opts...)
} }
// AllWithKubeVersion runs all the available linters on the given base directory, allowing to specify the kubernetes version. // AllWithKubeVersion runs all the available linters on the given base directory, allowing to specify the kubernetes version.
func AllWithKubeVersion(basedir string, values map[string]interface{}, releaseName, namespace string, kubeVersion *chartutil.KubeVersion) support.Linter { func AllWithKubeVersion(basedir string, values map[string]interface{}, namespace string, kubeVersion *chartutil.KubeVersion, opts ...rules.TemplateOption) support.Linter {
// Using abs path to get directory context // Using abs path to get directory context
chartDir, _ := filepath.Abs(basedir) chartDir, _ := filepath.Abs(basedir)
linter := support.Linter{ChartDir: chartDir} linter := support.Linter{ChartDir: chartDir}
rules.Chartfile(&linter) rules.Chartfile(&linter)
rules.ValuesWithOverrides(&linter, values) rules.ValuesWithOverrides(&linter, values)
rules.TemplatesWithKubeVersion(&linter, values, releaseName, namespace, kubeVersion) rules.TemplatesWithKubeVersion(&linter, values, namespace, kubeVersion, opts...)
rules.Dependencies(&linter) rules.Dependencies(&linter)
return linter return linter
} }

@ -45,12 +45,12 @@ var (
) )
// Templates lints the templates in the Linter. // Templates lints the templates in the Linter.
func Templates(linter *support.Linter, values map[string]interface{}, releaseName, namespace string, _ bool) { func Templates(linter *support.Linter, values map[string]interface{}, namespace string, _ bool, opts ...TemplateOption) {
TemplatesWithKubeVersion(linter, values, releaseName, namespace, nil) TemplatesWithKubeVersion(linter, values, namespace, nil, opts...)
} }
// TemplatesWithKubeVersion lints the templates in the Linter, allowing to specify the kubernetes version. // TemplatesWithKubeVersion lints the templates in the Linter, allowing to specify the kubernetes version.
func TemplatesWithKubeVersion(linter *support.Linter, values map[string]interface{}, releaseName, namespace string, kubeVersion *chartutil.KubeVersion) { func TemplatesWithKubeVersion(linter *support.Linter, values map[string]interface{}, namespace string, kubeVersion *chartutil.KubeVersion, opts ...TemplateOption) {
fpath := "templates/" fpath := "templates/"
templatesPath := filepath.Join(linter.ChartDir, fpath) templatesPath := filepath.Join(linter.ChartDir, fpath)
@ -70,8 +70,13 @@ func TemplatesWithKubeVersion(linter *support.Linter, values map[string]interfac
return return
} }
o := defaultTemplateOptions
for _, optFn := range opts {
optFn(o)
}
options := chartutil.ReleaseOptions{ options := chartutil.ReleaseOptions{
Name: releaseName, Name: o.releaseName,
Namespace: namespace, Namespace: namespace,
} }

@ -0,0 +1,20 @@
package rules
type (
templateOptions struct {
releaseName string
}
TemplateOption func(o *templateOptions)
)
var defaultTemplateOptions = &templateOptions{
releaseName: "test-release",
}
// WithReleaseName specify release name for linter
func WithReleaseName(name string) TemplateOption {
return func(o *templateOptions) {
o.releaseName = name
}
}
Loading…
Cancel
Save