chore(pkg): fix modernize linter

#### Description

fix modernize linter in pkg/chart/v2/lint/rules

Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
pull/31802/head
Matthieu MOREL 7 months ago
parent fbb8de54be
commit 5cc2e55714

@ -252,7 +252,7 @@ func (i *Install) installCRDs(crds []chart.CRD) error {
// //
// If DryRun is set to true, this will prepare the release, but not install it // If DryRun is set to true, this will prepare the release, but not install it
func (i *Install) Run(chrt ci.Charter, vals map[string]interface{}) (ri.Releaser, error) { func (i *Install) Run(chrt ci.Charter, vals map[string]any) (ri.Releaser, error) {
ctx := context.Background() ctx := context.Background()
return i.RunWithContext(ctx, chrt, vals) return i.RunWithContext(ctx, chrt, vals)
} }
@ -261,7 +261,7 @@ func (i *Install) Run(chrt ci.Charter, vals map[string]interface{}) (ri.Releaser
// //
// When the task is cancelled through ctx, the function returns and the install // When the task is cancelled through ctx, the function returns and the install
// proceeds in the background. // proceeds in the background.
func (i *Install) RunWithContext(ctx context.Context, ch ci.Charter, vals map[string]interface{}) (ri.Releaser, error) { func (i *Install) RunWithContext(ctx context.Context, ch ci.Charter, vals map[string]any) (ri.Releaser, error) {
var chrt *chart.Chart var chrt *chart.Chart
switch c := ch.(type) { switch c := ch.(type) {
case *chart.Chart: case *chart.Chart:
@ -638,7 +638,7 @@ func releaseV1ListToReleaserList(ls []*release.Release) ([]ri.Releaser, error) {
} }
// createRelease creates a new release object // createRelease creates a new release object
func (i *Install) createRelease(chrt *chart.Chart, rawVals map[string]interface{}, labels map[string]string) *release.Release { func (i *Install) createRelease(chrt *chart.Chart, rawVals map[string]any, labels map[string]string) *release.Release {
ts := i.cfg.Now() ts := i.cfg.Now()
r := &release.Release{ r := &release.Release{

@ -26,14 +26,14 @@ import (
// ToRenderValues composes the struct from the data coming from the Releases, Charts and Values files // ToRenderValues composes the struct from the data coming from the Releases, Charts and Values files
// //
// This takes both ReleaseOptions and Capabilities to merge into the render values. // This takes both ReleaseOptions and Capabilities to merge into the render values.
func ToRenderValues(chrt chart.Charter, chrtVals map[string]interface{}, options common.ReleaseOptions, caps *common.Capabilities) (common.Values, error) { func ToRenderValues(chrt chart.Charter, chrtVals map[string]any, options common.ReleaseOptions, caps *common.Capabilities) (common.Values, error) {
return ToRenderValuesWithSchemaValidation(chrt, chrtVals, options, caps, false) return ToRenderValuesWithSchemaValidation(chrt, chrtVals, options, caps, false)
} }
// ToRenderValuesWithSchemaValidation composes the struct from the data coming from the Releases, Charts and Values files // ToRenderValuesWithSchemaValidation composes the struct from the data coming from the Releases, Charts and Values files
// //
// This takes both ReleaseOptions and Capabilities to merge into the render values. // This takes both ReleaseOptions and Capabilities to merge into the render values.
func ToRenderValuesWithSchemaValidation(chrt chart.Charter, chrtVals map[string]interface{}, options common.ReleaseOptions, caps *common.Capabilities, skipSchemaValidation bool) (common.Values, error) { func ToRenderValuesWithSchemaValidation(chrt chart.Charter, chrtVals map[string]any, options common.ReleaseOptions, caps *common.Capabilities, skipSchemaValidation bool) (common.Values, error) {
if caps == nil { if caps == nil {
caps = common.DefaultCapabilities caps = common.DefaultCapabilities
} }
@ -41,10 +41,10 @@ func ToRenderValuesWithSchemaValidation(chrt chart.Charter, chrtVals map[string]
if err != nil { if err != nil {
return nil, err return nil, err
} }
top := map[string]interface{}{ top := map[string]any{
"Chart": accessor.MetadataAsMap(), "Chart": accessor.MetadataAsMap(),
"Capabilities": caps, "Capabilities": caps,
"Release": map[string]interface{}{ "Release": map[string]any{
"Name": options.Name, "Name": options.Name,
"Namespace": options.Namespace, "Namespace": options.Namespace,
"IsUpgrade": options.IsUpgrade, "IsUpgrade": options.IsUpgrade,

@ -19,21 +19,21 @@ import (
common "helm.sh/helm/v4/pkg/chart/common" common "helm.sh/helm/v4/pkg/chart/common"
) )
type Charter interface{} type Charter any
type Dependency interface{} type Dependency any
type Accessor interface { type Accessor interface {
Name() string Name() string
IsRoot() bool IsRoot() bool
MetadataAsMap() map[string]interface{} MetadataAsMap() map[string]any
Files() []*common.File Files() []*common.File
Templates() []*common.File Templates() []*common.File
ChartFullPath() string ChartFullPath() string
IsLibraryChart() bool IsLibraryChart() bool
Dependencies() []Charter Dependencies() []Charter
MetaDependencies() []Dependency MetaDependencies() []Dependency
Values() map[string]interface{} Values() map[string]any
Schema() []byte Schema() []byte
Deprecated() bool Deprecated() bool
} }

@ -70,15 +70,15 @@ func Chartfile(linter *support.Linter) {
linter.RunLinterRule(support.WarningSev, chartFileName, validateChartVersionStrictSemVerV2(chartFile)) linter.RunLinterRule(support.WarningSev, chartFileName, validateChartVersionStrictSemVerV2(chartFile))
} }
func validateChartVersionType(data map[string]interface{}) error { func validateChartVersionType(data map[string]any) error {
return isStringValue(data, "version") return isStringValue(data, "version")
} }
func validateChartAppVersionType(data map[string]interface{}) error { func validateChartAppVersionType(data map[string]any) error {
return isStringValue(data, "appVersion") return isStringValue(data, "appVersion")
} }
func isStringValue(data map[string]interface{}, key string) error { func isStringValue(data map[string]any, key string) error {
value, ok := data[key] value, ok := data[key]
if !ok { if !ok {
return nil return nil
@ -225,12 +225,12 @@ func validateChartType(cf *chart.Metadata) error {
// loadChartFileForTypeCheck loads the Chart.yaml // loadChartFileForTypeCheck loads the Chart.yaml
// in a generic form of a map[string]interface{}, so that the type // in a generic form of a map[string]interface{}, so that the type
// of the values can be checked // of the values can be checked
func loadChartFileForTypeCheck(filename string) (map[string]interface{}, error) { func loadChartFileForTypeCheck(filename string) (map[string]any, error) {
b, err := os.ReadFile(filename) b, err := os.ReadFile(filename)
if err != nil { if err != nil {
return nil, err return nil, err
} }
y := make(map[string]interface{}) y := make(map[string]any)
err = yaml.Unmarshal(b, &y) err = yaml.Unmarshal(b, &y)
return y, err return y, err
} }

@ -32,7 +32,7 @@ import (
// they are only tested for well-formedness. // they are only tested for well-formedness.
// //
// If additional values are supplied, they are coalesced into the values in values.yaml. // If additional values are supplied, they are coalesced into the values in values.yaml.
func ValuesWithOverrides(linter *support.Linter, valueOverrides map[string]interface{}, skipSchemaValidation bool) { func ValuesWithOverrides(linter *support.Linter, valueOverrides map[string]any, skipSchemaValidation bool) {
file := "values.yaml" file := "values.yaml"
vf := filepath.Join(linter.ChartDir, file) vf := filepath.Join(linter.ChartDir, file)
fileExists := linter.RunLinterRule(support.InfoSev, file, validateValuesFileExistence(vf)) fileExists := linter.RunLinterRule(support.InfoSev, file, validateValuesFileExistence(vf))
@ -52,7 +52,7 @@ func validateValuesFileExistence(valuesPath string) error {
return nil return nil
} }
func validateValuesFile(valuesPath string, overrides map[string]interface{}, skipSchemaValidation bool) error { func validateValuesFile(valuesPath string, overrides map[string]any, skipSchemaValidation bool) error {
values, err := common.ReadValuesFile(valuesPath) values, err := common.ReadValuesFile(valuesPath)
if err != nil { if err != nil {
return fmt.Errorf("unable to parse YAML: %w", err) return fmt.Errorf("unable to parse YAML: %w", err)
@ -63,7 +63,7 @@ func validateValuesFile(valuesPath string, overrides map[string]interface{}, ski
// We could change that. For now, though, we retain that strategy, and thus can // We could change that. For now, though, we retain that strategy, and thus can
// coalesce tables (like reuse-values does) instead of doing the full chart // coalesce tables (like reuse-values does) instead of doing the full chart
// CoalesceValues // CoalesceValues
coalescedValues := util.CoalesceTables(make(map[string]interface{}, len(overrides)), overrides) coalescedValues := util.CoalesceTables(make(map[string]any, len(overrides)), overrides)
coalescedValues = util.CoalesceTables(coalescedValues, values) coalescedValues = util.CoalesceTables(coalescedValues, values)
ext := filepath.Ext(valuesPath) ext := filepath.Ext(valuesPath)

@ -42,8 +42,8 @@ type Options struct {
// MergeValues merges values from files specified via -f/--values and directly // MergeValues merges values from files specified via -f/--values and directly
// via --set-json, --set, --set-string, or --set-file, marshaling them to YAML // via --set-json, --set, --set-string, or --set-file, marshaling them to YAML
func (opts *Options) MergeValues(p getter.Providers) (map[string]interface{}, error) { func (opts *Options) MergeValues(p getter.Providers) (map[string]any, error) {
base := map[string]interface{}{} base := map[string]any{}
// User specified a values files via -f/--values // User specified a values files via -f/--values
for _, filePath := range opts.ValueFiles { for _, filePath := range opts.ValueFiles {
@ -64,7 +64,7 @@ func (opts *Options) MergeValues(p getter.Providers) (map[string]interface{}, er
trimmedValue := strings.TrimSpace(value) trimmedValue := strings.TrimSpace(value)
if len(trimmedValue) > 0 && trimmedValue[0] == '{' { if len(trimmedValue) > 0 && trimmedValue[0] == '{' {
// If value is JSON object format, parse it as map // If value is JSON object format, parse it as map
var jsonMap map[string]interface{} var jsonMap map[string]any
if err := json.Unmarshal([]byte(trimmedValue), &jsonMap); err != nil { if err := json.Unmarshal([]byte(trimmedValue), &jsonMap); err != nil {
return nil, fmt.Errorf("failed parsing --set-json data JSON: %s", value) return nil, fmt.Errorf("failed parsing --set-json data JSON: %s", value)
} }
@ -93,7 +93,7 @@ func (opts *Options) MergeValues(p getter.Providers) (map[string]interface{}, er
// User specified a value via --set-file // User specified a value via --set-file
for _, value := range opts.FileValues { for _, value := range opts.FileValues {
reader := func(rs []rune) (interface{}, error) { reader := func(rs []rune) (any, error) {
bytes, err := readFile(string(rs), p) bytes, err := readFile(string(rs), p)
if err != nil { if err != nil {
return nil, err return nil, err

@ -126,24 +126,20 @@ func TestConcurrencyDownloadIndex(t *testing.T) {
// 2) read index.yaml via LoadIndexFile (read operation). // 2) read index.yaml via LoadIndexFile (read operation).
// This checks for race conditions and ensures correct behavior under concurrent read/write access. // This checks for race conditions and ensures correct behavior under concurrent read/write access.
for range 150 { for range 150 {
wg.Add(1)
go func() { wg.Go(func() {
defer wg.Done()
idx, err := repo.DownloadIndexFile() idx, err := repo.DownloadIndexFile()
if err != nil { if err != nil {
t.Errorf("Failed to download index file to %s: %v", idx, err) t.Errorf("Failed to download index file to %s: %v", idx, err)
} }
}() })
wg.Add(1) wg.Go(func() {
go func() {
defer wg.Done()
_, err := LoadIndexFile(indexFName) _, err := LoadIndexFile(indexFName)
if err != nil { if err != nil {
t.Errorf("Failed to load index file: %v", err) t.Errorf("Failed to load index file: %v", err)
} }
}() })
} }
wg.Wait() wg.Wait()
} }

Loading…
Cancel
Save