Visitar URL original
chore(pkg): fix modernize linter · helm/helm@111d4e6 · GitHub
Skip to content

Commit 111d4e6

Browse files
committed
chore(pkg): fix modernize linter
#### Description fix modernize linter in pkg/chart/common/util Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
1 parent fbb8de5 commit 111d4e6

7 files changed

Lines changed: 54 additions & 54 deletions

File tree

‎pkg/action/upgrade.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,13 @@ func (u *Upgrade) SetRegistryClient(client *registry.Client) {
156156
}
157157

158158
// Run executes the upgrade on the given release.
159-
func (u *Upgrade) Run(name string, chart chart.Charter, vals map[string]interface{}) (ri.Releaser, error) {
159+
func (u *Upgrade) Run(name string, chart chart.Charter, vals map[string]any) (ri.Releaser, error) {
160160
ctx := context.Background()
161161
return u.RunWithContext(ctx, name, chart, vals)
162162
}
163163

164164
// RunWithContext executes the upgrade on the given release with context.
165-
func (u *Upgrade) RunWithContext(ctx context.Context, name string, ch chart.Charter, vals map[string]interface{}) (ri.Releaser, error) {
165+
func (u *Upgrade) RunWithContext(ctx context.Context, name string, ch chart.Charter, vals map[string]any) (ri.Releaser, error) {
166166
if err := u.cfg.KubeClient.IsReachable(); err != nil {
167167
return nil, err
168168
}
@@ -213,7 +213,7 @@ func (u *Upgrade) RunWithContext(ctx context.Context, name string, ch chart.Char
213213
}
214214

215215
// prepareUpgrade builds an upgraded release for an upgrade operation.
216-
func (u *Upgrade) prepareUpgrade(name string, chart *chartv2.Chart, vals map[string]interface{}) (*release.Release, *release.Release, bool, error) {
216+
func (u *Upgrade) prepareUpgrade(name string, chart *chartv2.Chart, vals map[string]any) (*release.Release, *release.Release, bool, error) {
217217
if chart == nil {
218218
return nil, nil, false, errMissingChart
219219
}
@@ -408,7 +408,7 @@ func (u *Upgrade) performUpgrade(ctx context.Context, originalRelease, upgradedR
408408
}
409409
rChan := make(chan resultMessage)
410410
ctxChan := make(chan resultMessage)
411-
doneChan := make(chan interface{})
411+
doneChan := make(chan any)
412412
defer close(doneChan)
413413
go u.releasingUpgrade(rChan, upgradedRelease, current, target, originalRelease, serverSideApply)
414414
go u.handleContext(ctx, doneChan, ctxChan, upgradedRelease)
@@ -434,7 +434,7 @@ func (u *Upgrade) reportToPerformUpgrade(c chan<- resultMessage, rel *release.Re
434434
}
435435

436436
// Setup listener for SIGINT and SIGTERM
437-
func (u *Upgrade) handleContext(ctx context.Context, done chan interface{}, c chan<- resultMessage, upgradedRelease *release.Release) {
437+
func (u *Upgrade) handleContext(ctx context.Context, done chan any, c chan<- resultMessage, upgradedRelease *release.Release) {
438438
select {
439439
case <-ctx.Done():
440440
err := ctx.Err()
@@ -601,7 +601,7 @@ func (u *Upgrade) failRelease(rel *release.Release, created kube.ResourceList, e
601601
//
602602
// This is skipped if the u.ResetValues flag is set, in which case the
603603
// request values are not altered.
604-
func (u *Upgrade) reuseValues(chart *chartv2.Chart, current *release.Release, newVals map[string]interface{}) (map[string]interface{}, error) {
604+
func (u *Upgrade) reuseValues(chart *chartv2.Chart, current *release.Release, newVals map[string]any) (map[string]any, error) {
605605
if u.ResetValues {
606606
// If ResetValues is set, we completely ignore current.Config.
607607
u.cfg.Logger().Debug("resetting values to the chart's original version")

‎pkg/chart/common.go‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ func (r *v2Accessor) IsRoot() bool {
5656
return r.chrt.IsRoot()
5757
}
5858

59-
func (r *v2Accessor) MetadataAsMap() map[string]interface{} {
60-
var ret map[string]interface{}
59+
func (r *v2Accessor) MetadataAsMap() map[string]any {
60+
var ret map[string]any
6161
if r.chrt.Metadata == nil {
6262
return ret
6363
}
@@ -101,7 +101,7 @@ func (r *v2Accessor) MetaDependencies() []Dependency {
101101
return deps
102102
}
103103

104-
func (r *v2Accessor) Values() map[string]interface{} {
104+
func (r *v2Accessor) Values() map[string]any {
105105
return r.chrt.Values
106106
}
107107

@@ -125,8 +125,8 @@ func (r *v3Accessor) IsRoot() bool {
125125
return r.chrt.IsRoot()
126126
}
127127

128-
func (r *v3Accessor) MetadataAsMap() map[string]interface{} {
129-
var ret map[string]interface{}
128+
func (r *v3Accessor) MetadataAsMap() map[string]any {
129+
var ret map[string]any
130130
if r.chrt.Metadata == nil {
131131
return ret
132132
}
@@ -170,7 +170,7 @@ func (r *v3Accessor) MetaDependencies() []Dependency {
170170
return deps
171171
}
172172

173-
func (r *v3Accessor) Values() map[string]interface{} {
173+
func (r *v3Accessor) Values() map[string]any {
174174
return r.chrt.Values
175175
}
176176

@@ -182,7 +182,7 @@ func (r *v3Accessor) Deprecated() bool {
182182
return r.chrt.Metadata.Deprecated
183183
}
184184

185-
func structToMap(obj interface{}) (map[string]interface{}, error) {
185+
func structToMap(obj any) (map[string]any, error) {
186186
objValue := reflect.ValueOf(obj)
187187

188188
// If the value is a pointer, dereference it
@@ -195,7 +195,7 @@ func structToMap(obj interface{}) (map[string]interface{}, error) {
195195
return nil, fmt.Errorf("input must be a struct or a pointer to a struct")
196196
}
197197

198-
result := make(map[string]interface{})
198+
result := make(map[string]any)
199199
objType := objValue.Type()
200200

201201
for i := 0; i < objValue.NumField(); i++ {
@@ -221,7 +221,7 @@ func structToMap(obj interface{}) (map[string]interface{}, error) {
221221
result[field.Name] = nestedMap
222222
}
223223
case reflect.Slice:
224-
sliceOfMaps := make([]interface{}, value.Len())
224+
sliceOfMaps := make([]any, value.Len())
225225
for j := 0; j < value.Len(); j++ {
226226
sliceElement := value.Index(j)
227227
if sliceElement.Kind() == reflect.Struct || sliceElement.Kind() == reflect.Pointer {

‎pkg/chart/common/util/jsonschema_test.go‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,9 @@ func TestValidateAgainstSchema(t *testing.T) {
138138
}
139139
chrt.AddDependency(subchart)
140140

141-
vals := map[string]interface{}{
141+
vals := map[string]any{
142142
"name": "John",
143-
"subchart": map[string]interface{}{
143+
"subchart": map[string]any{
144144
"age": 25,
145145
},
146146
}
@@ -165,9 +165,9 @@ func TestValidateAgainstSchemaNegative(t *testing.T) {
165165
}
166166
chrt.AddDependency(subchart)
167167

168-
vals := map[string]interface{}{
168+
vals := map[string]any{
169169
"name": "John",
170-
"subchart": map[string]interface{}{},
170+
"subchart": map[string]any{},
171171
}
172172

173173
var errString string
@@ -200,9 +200,9 @@ func TestValidateAgainstSchema2020(t *testing.T) {
200200
}
201201
chrt.AddDependency(subchart)
202202

203-
vals := map[string]interface{}{
203+
vals := map[string]any{
204204
"name": "John",
205-
"subchart": map[string]interface{}{
205+
"subchart": map[string]any{
206206
"data": []any{"hello", 12},
207207
},
208208
}
@@ -227,9 +227,9 @@ func TestValidateAgainstSchema2020Negative(t *testing.T) {
227227
}
228228
chrt.AddDependency(subchart)
229229

230-
vals := map[string]interface{}{
230+
vals := map[string]any{
231231
"name": "John",
232-
"subchart": map[string]interface{}{
232+
"subchart": map[string]any{
233233
"data": []any{12},
234234
},
235235
}
@@ -294,7 +294,7 @@ func TestValidateAgainstSingleSchema_UnresolvedURN_Ignored(t *testing.T) {
294294
"$schema": "https://json-schema.org/draft-07/schema#",
295295
"$ref": "urn:example:helm:schemas:v1:helm-schema-validation-conditions:v1/helmSchemaValidation-true"
296296
}`)
297-
vals := map[string]interface{}{"any": "value"}
297+
vals := map[string]any{"any": "value"}
298298
if err := ValidateAgainstSingleSchema(vals, schema); err != nil {
299299
t.Fatalf("expected no error when URN unresolved is ignored, got: %v", err)
300300
}

‎pkg/chart/common/util/values_test.go‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ import (
2626

2727
func TestToRenderValues(t *testing.T) {
2828

29-
chartValues := map[string]interface{}{
29+
chartValues := map[string]any{
3030
"name": "al Rashid",
31-
"where": map[string]interface{}{
31+
"where": map[string]any{
3232
"city": "Basrah",
3333
"title": "caliph",
3434
},
3535
}
3636

37-
overrideValues := map[string]interface{}{
37+
overrideValues := map[string]any{
3838
"name": "Haroun",
39-
"where": map[string]interface{}{
39+
"where": map[string]any{
4040
"city": "Baghdad",
4141
"date": "809 CE",
4242
},
@@ -67,11 +67,11 @@ func TestToRenderValues(t *testing.T) {
6767
}
6868

6969
// Ensure that the top-level values are all set.
70-
metamap := res["Chart"].(map[string]interface{})
70+
metamap := res["Chart"].(map[string]any)
7171
if name := metamap["Name"]; name.(string) != "test" {
7272
t.Errorf("Expected chart name 'test', got %q", name)
7373
}
74-
relmap := res["Release"].(map[string]interface{})
74+
relmap := res["Release"].(map[string]any)
7575
if name := relmap["Name"]; name.(string) != "Seven Voyages" {
7676
t.Errorf("Expected release name 'Seven Voyages', got %q", name)
7777
}
@@ -98,7 +98,7 @@ func TestToRenderValues(t *testing.T) {
9898
if vals["name"] != "Haroun" {
9999
t.Errorf("Expected 'Haroun', got %q (%v)", vals["name"], vals)
100100
}
101-
where := vals["where"].(map[string]interface{})
101+
where := vals["where"].(map[string]any)
102102
expects := map[string]string{
103103
"city": "Baghdad",
104104
"date": "809 CE",

‎pkg/chart/v2/lint/rules/values_test.go‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func TestValidateValuesFileWellFormed(t *testing.T) {
6767
`
6868
tmpdir := ensure.TempFile(t, "values.yaml", []byte(badYaml))
6969
valfile := filepath.Join(tmpdir, "values.yaml")
70-
if err := validateValuesFile(valfile, map[string]interface{}{}, false); err == nil {
70+
if err := validateValuesFile(valfile, map[string]any{}, false); err == nil {
7171
t.Fatal("expected values file to fail parsing")
7272
}
7373
}
@@ -78,7 +78,7 @@ func TestValidateValuesFileSchema(t *testing.T) {
7878
createTestingSchema(t, tmpdir)
7979

8080
valfile := filepath.Join(tmpdir, "values.yaml")
81-
if err := validateValuesFile(valfile, map[string]interface{}{}, false); err != nil {
81+
if err := validateValuesFile(valfile, map[string]any{}, false); err != nil {
8282
t.Fatalf("Failed validation with %s", err)
8383
}
8484
}
@@ -91,7 +91,7 @@ func TestValidateValuesFileSchemaFailure(t *testing.T) {
9191

9292
valfile := filepath.Join(tmpdir, "values.yaml")
9393

94-
err := validateValuesFile(valfile, map[string]interface{}{}, false)
94+
err := validateValuesFile(valfile, map[string]any{}, false)
9595
if err == nil {
9696
t.Fatal("expected values file to fail parsing")
9797
}
@@ -107,15 +107,15 @@ func TestValidateValuesFileSchemaFailureButWithSkipSchemaValidation(t *testing.T
107107

108108
valfile := filepath.Join(tmpdir, "values.yaml")
109109

110-
err := validateValuesFile(valfile, map[string]interface{}{}, true)
110+
err := validateValuesFile(valfile, map[string]any{}, true)
111111
if err != nil {
112112
t.Fatal("expected values file to pass parsing because of skipSchemaValidation")
113113
}
114114
}
115115

116116
func TestValidateValuesFileSchemaOverrides(t *testing.T) {
117117
yaml := "username: admin"
118-
overrides := map[string]interface{}{
118+
overrides := map[string]any{
119119
"password": "swordfish",
120120
}
121121
tmpdir := ensure.TempFile(t, "values.yaml", []byte(yaml))
@@ -131,24 +131,24 @@ func TestValidateValuesFile(t *testing.T) {
131131
tests := []struct {
132132
name string
133133
yaml string
134-
overrides map[string]interface{}
134+
overrides map[string]any
135135
errorMessage string
136136
}{
137137
{
138138
name: "value added",
139139
yaml: "username: admin",
140-
overrides: map[string]interface{}{"password": "swordfish"},
140+
overrides: map[string]any{"password": "swordfish"},
141141
},
142142
{
143143
name: "value not overridden",
144144
yaml: "username: admin\npassword:",
145-
overrides: map[string]interface{}{"username": "anotherUser"},
145+
overrides: map[string]any{"username": "anotherUser"},
146146
errorMessage: "- at '/password': got null, want string",
147147
},
148148
{
149149
name: "value overridden",
150150
yaml: "username: admin\npassword:",
151-
overrides: map[string]interface{}{"username": "anotherUser", "password": "swordfish"},
151+
overrides: map[string]any{"username": "anotherUser", "password": "swordfish"},
152152
},
153153
}
154154

‎pkg/chart/v2/loader/load.go‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,11 @@ func LoadFiles(files []*archive.BufferedFile) (*chart.Chart, error) {
209209
//
210210
// The reader is expected to contain one or more YAML documents, the values of which are merged.
211211
// And the values can be either a chart's default values or user-supplied values.
212-
func LoadValues(data io.Reader) (map[string]interface{}, error) {
213-
values := map[string]interface{}{}
212+
func LoadValues(data io.Reader) (map[string]any, error) {
213+
values := map[string]any{}
214214
reader := utilyaml.NewYAMLReader(bufio.NewReader(data))
215215
for {
216-
currentMap := map[string]interface{}{}
216+
currentMap := map[string]any{}
217217
raw, err := reader.Read()
218218
if err != nil {
219219
if errors.Is(err, io.EOF) {
@@ -231,13 +231,13 @@ func LoadValues(data io.Reader) (map[string]interface{}, error) {
231231

232232
// MergeMaps merges two maps. If a key exists in both maps, the value from b will be used.
233233
// If the value is a map, the maps will be merged recursively.
234-
func MergeMaps(a, b map[string]interface{}) map[string]interface{} {
235-
out := make(map[string]interface{}, len(a))
234+
func MergeMaps(a, b map[string]any) map[string]any {
235+
out := make(map[string]any, len(a))
236236
maps.Copy(out, a)
237237
for k, v := range b {
238-
if v, ok := v.(map[string]interface{}); ok {
238+
if v, ok := v.(map[string]any); ok {
239239
if bv, ok := out[k]; ok {
240-
if bv, ok := bv.(map[string]interface{}); ok {
240+
if bv, ok := bv.(map[string]any); ok {
241241
out[k] = MergeMaps(bv, v)
242242
continue
243243
}

‎pkg/engine/lookup_func.go‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import (
3030
"k8s.io/client-go/rest"
3131
)
3232

33-
type lookupFunc = func(apiversion string, resource string, namespace string, name string) (map[string]interface{}, error)
33+
type lookupFunc = func(apiversion string, resource string, namespace string, name string) (map[string]any, error)
3434

3535
// NewLookupFunction returns a function for looking up objects in the cluster.
3636
//
@@ -55,11 +55,11 @@ func (c clientProviderFromConfig) GetClientFor(apiVersion, kind string) (dynamic
5555
}
5656

5757
func newLookupFunction(clientProvider ClientProvider) lookupFunc {
58-
return func(apiversion string, kind string, namespace string, name string) (map[string]interface{}, error) {
58+
return func(apiversion string, kind string, namespace string, name string) (map[string]any, error) {
5959
var client dynamic.ResourceInterface
6060
c, namespaced, err := clientProvider.GetClientFor(apiversion, kind)
6161
if err != nil {
62-
return map[string]interface{}{}, err
62+
return map[string]any{}, err
6363
}
6464
if namespaced && namespace != "" {
6565
client = c.Namespace(namespace)
@@ -73,9 +73,9 @@ func newLookupFunction(clientProvider ClientProvider) lookupFunc {
7373
if apierrors.IsNotFound(err) {
7474
// Just return an empty interface when the object was not found.
7575
// That way, users can use `if not (lookup ...)` in their templates.
76-
return map[string]interface{}{}, nil
76+
return map[string]any{}, nil
7777
}
78-
return map[string]interface{}{}, err
78+
return map[string]any{}, err
7979
}
8080
return obj.UnstructuredContent(), nil
8181
}
@@ -85,9 +85,9 @@ func newLookupFunction(clientProvider ClientProvider) lookupFunc {
8585
if apierrors.IsNotFound(err) {
8686
// Just return an empty interface when the object was not found.
8787
// That way, users can use `if not (lookup ...)` in their templates.
88-
return map[string]interface{}{}, nil
88+
return map[string]any{}, nil
8989
}
90-
return map[string]interface{}{}, err
90+
return map[string]any{}, err
9191
}
9292
return obj.UnstructuredContent(), nil
9393
}

0 commit comments

Comments
 (0)