Skip to content

Commit

Permalink
Merge pull request #81 from ImitationImmortal/lint
Browse files Browse the repository at this point in the history
fix: use --set-json instance of --set in global.nodeSelector
  • Loading branch information
wansir authored Feb 7, 2024
2 parents 6ed28c0 + d046d4c commit 8a2ae61
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ clean: ## clean up environment

PHONY: cover
cover: ## display test coverage
go test -v -race ./... -coverprofile=coverage.out
go test -v ./... -coverprofile=coverage.out
go tool cover -func=coverage.out

PHONY: fmt
Expand Down
20 changes: 10 additions & 10 deletions pkg/extension/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,24 +137,24 @@ func WithBuiltins(paths []string) error {
{
name: "global.imageRegistry",
key: rand.String(12),
valueFunc: func(v *lintValuesValidator) string {
return fmt.Sprintf("global.imageRegistry=%s", v.key)
valueFunc: func(key string, value *values.Options) {
value.Values = append(value.Values, fmt.Sprintf("global.imageRegistry=%s", key))
},
output: make(map[string]string),
},
{
name: "global.nodeSelector",
key: rand.String(12),
valueFunc: func(v *lintValuesValidator) string {
return fmt.Sprintf("global.nodeSelector=\"kubernetes.io/os: %s\"", v.key)
valueFunc: func(key string, value *values.Options) {
value.JSONValues = append(value.JSONValues, fmt.Sprintf("global.nodeSelector={\"kubernetes.io/os\": \"%s\"}", key))
},
output: make(map[string]string),
},
}

valueOpts := &values.Options{}
for _, vt := range valueValidators {
valueOpts.Values = append(valueOpts.Values, vt.InitValue())
vt.InitValue(valueOpts)
}

p := getter.All(cli.New())
Expand Down Expand Up @@ -208,12 +208,12 @@ func WithBuiltins(paths []string) error {
type lintValuesValidator struct {
name string
key string
valueFunc func(v *lintValuesValidator) string
valueFunc func(unique string, value *values.Options)
output map[string]string
}

func (v *lintValuesValidator) InitValue() string {
return v.valueFunc(v)
func (v *lintValuesValidator) InitValue(value *values.Options) {
v.valueFunc(v.key, value)
}

func (v *lintValuesValidator) Validate(fileName string, fileData string) error {
Expand All @@ -224,7 +224,7 @@ func (v *lintValuesValidator) Validate(fileName string, fileData string) error {
if err := yaml.Unmarshal([]byte(y), &yamlMap); err != nil {
return err
}
v.output[fileName] += fmt.Sprintf("name: %s, groupVersion: %s, kind: %s \n", yamlMap["metadata"].(map[string]any)["name"], yamlMap["apiVersion"], yamlMap["kind"])
v.output[fileName] += fmt.Sprintf(" name: %s, groupVersion: %s, kind: %s \n", yamlMap["metadata"].(map[string]any)["name"], yamlMap["apiVersion"], yamlMap["kind"])
}
}
return nil
Expand All @@ -234,7 +234,7 @@ func (v *lintValuesValidator) Output() {
fmt.Printf("INFO: \"%s\" is valid in: \n", v.name)
if len(v.output) != 0 {
for fileName, keyStr := range v.output {
fmt.Printf(" %s: \n%s", fileName, keyStr)
fmt.Printf("%s: \n%s", fileName, keyStr)
}
fmt.Print("\n")
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/helm/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,12 @@ func lintAll(basedir string, values map[string]interface{}, namespace string, st
// For ks-extension it's not exist.
//rules.Chartfile(&linter)
rules.ValuesWithOverrides(&linter, values)
lintTemplates(&linter, values, namespace, strict, metadata)
lintDependencies(&linter, metadata)
lintTemplates(&linter, values, namespace, strict, *metadata)
lintDependencies(&linter, *metadata)
return linter
}

func lintTemplates(linter *support.Linter, values map[string]interface{}, namespace string, strict bool, metadata *chart.Metadata) {
func lintTemplates(linter *support.Linter, values map[string]interface{}, namespace string, strict bool, metadata chart.Metadata) {
fpath := "templates/"
templatesPath := filepath.Join(linter.ChartDir, fpath)

Expand All @@ -124,7 +124,7 @@ func lintTemplates(linter *support.Linter, values map[string]interface{}, namesp

// Load chart and parse templates
//chart, err := LoadHelmCharts(linter.ChartDir)
chart, err := Load(linter.ChartDir, metadata)
chart, err := Load(linter.ChartDir, &metadata)
if err != nil {
return
}
Expand Down Expand Up @@ -233,8 +233,8 @@ func lintTemplates(linter *support.Linter, values map[string]interface{}, namesp
// Dependencies runs lints against a chart's dependencies
//
// See https://github.com/helm/helm/issues/7910
func lintDependencies(linter *support.Linter, metadata *chart.Metadata) {
c, err := Load(linter.ChartDir, metadata)
func lintDependencies(linter *support.Linter, metadata chart.Metadata) {
c, err := Load(linter.ChartDir, &metadata)
if !linter.RunLinterRule(support.ErrorSev, "", validateChartFormat(err)) {
return
}
Expand Down

0 comments on commit 8a2ae61

Please sign in to comment.