mirror of
https://github.com/helm/helm.git
synced 2026-05-28 04:35:48 -04:00
chore(pkg): fix modernize linter
#### Description fix modernize linter in pkg/chart/common/util Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
This commit is contained in:
parent
fbb8de54be
commit
111d4e6e0e
7 changed files with 54 additions and 54 deletions
|
|
@ -156,13 +156,13 @@ func (u *Upgrade) SetRegistryClient(client *registry.Client) {
|
|||
}
|
||||
|
||||
// Run executes the upgrade on the given release.
|
||||
func (u *Upgrade) Run(name string, chart chart.Charter, vals map[string]interface{}) (ri.Releaser, error) {
|
||||
func (u *Upgrade) Run(name string, chart chart.Charter, vals map[string]any) (ri.Releaser, error) {
|
||||
ctx := context.Background()
|
||||
return u.RunWithContext(ctx, name, chart, vals)
|
||||
}
|
||||
|
||||
// RunWithContext executes the upgrade on the given release with context.
|
||||
func (u *Upgrade) RunWithContext(ctx context.Context, name string, ch chart.Charter, vals map[string]interface{}) (ri.Releaser, error) {
|
||||
func (u *Upgrade) RunWithContext(ctx context.Context, name string, ch chart.Charter, vals map[string]any) (ri.Releaser, error) {
|
||||
if err := u.cfg.KubeClient.IsReachable(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -213,7 +213,7 @@ func (u *Upgrade) RunWithContext(ctx context.Context, name string, ch chart.Char
|
|||
}
|
||||
|
||||
// prepareUpgrade builds an upgraded release for an upgrade operation.
|
||||
func (u *Upgrade) prepareUpgrade(name string, chart *chartv2.Chart, vals map[string]interface{}) (*release.Release, *release.Release, bool, error) {
|
||||
func (u *Upgrade) prepareUpgrade(name string, chart *chartv2.Chart, vals map[string]any) (*release.Release, *release.Release, bool, error) {
|
||||
if chart == nil {
|
||||
return nil, nil, false, errMissingChart
|
||||
}
|
||||
|
|
@ -408,7 +408,7 @@ func (u *Upgrade) performUpgrade(ctx context.Context, originalRelease, upgradedR
|
|||
}
|
||||
rChan := make(chan resultMessage)
|
||||
ctxChan := make(chan resultMessage)
|
||||
doneChan := make(chan interface{})
|
||||
doneChan := make(chan any)
|
||||
defer close(doneChan)
|
||||
go u.releasingUpgrade(rChan, upgradedRelease, current, target, originalRelease, serverSideApply)
|
||||
go u.handleContext(ctx, doneChan, ctxChan, upgradedRelease)
|
||||
|
|
@ -434,7 +434,7 @@ func (u *Upgrade) reportToPerformUpgrade(c chan<- resultMessage, rel *release.Re
|
|||
}
|
||||
|
||||
// Setup listener for SIGINT and SIGTERM
|
||||
func (u *Upgrade) handleContext(ctx context.Context, done chan interface{}, c chan<- resultMessage, upgradedRelease *release.Release) {
|
||||
func (u *Upgrade) handleContext(ctx context.Context, done chan any, c chan<- resultMessage, upgradedRelease *release.Release) {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
err := ctx.Err()
|
||||
|
|
@ -601,7 +601,7 @@ func (u *Upgrade) failRelease(rel *release.Release, created kube.ResourceList, e
|
|||
//
|
||||
// This is skipped if the u.ResetValues flag is set, in which case the
|
||||
// request values are not altered.
|
||||
func (u *Upgrade) reuseValues(chart *chartv2.Chart, current *release.Release, newVals map[string]interface{}) (map[string]interface{}, error) {
|
||||
func (u *Upgrade) reuseValues(chart *chartv2.Chart, current *release.Release, newVals map[string]any) (map[string]any, error) {
|
||||
if u.ResetValues {
|
||||
// If ResetValues is set, we completely ignore current.Config.
|
||||
u.cfg.Logger().Debug("resetting values to the chart's original version")
|
||||
|
|
|
|||
|
|
@ -56,8 +56,8 @@ func (r *v2Accessor) IsRoot() bool {
|
|||
return r.chrt.IsRoot()
|
||||
}
|
||||
|
||||
func (r *v2Accessor) MetadataAsMap() map[string]interface{} {
|
||||
var ret map[string]interface{}
|
||||
func (r *v2Accessor) MetadataAsMap() map[string]any {
|
||||
var ret map[string]any
|
||||
if r.chrt.Metadata == nil {
|
||||
return ret
|
||||
}
|
||||
|
|
@ -101,7 +101,7 @@ func (r *v2Accessor) MetaDependencies() []Dependency {
|
|||
return deps
|
||||
}
|
||||
|
||||
func (r *v2Accessor) Values() map[string]interface{} {
|
||||
func (r *v2Accessor) Values() map[string]any {
|
||||
return r.chrt.Values
|
||||
}
|
||||
|
||||
|
|
@ -125,8 +125,8 @@ func (r *v3Accessor) IsRoot() bool {
|
|||
return r.chrt.IsRoot()
|
||||
}
|
||||
|
||||
func (r *v3Accessor) MetadataAsMap() map[string]interface{} {
|
||||
var ret map[string]interface{}
|
||||
func (r *v3Accessor) MetadataAsMap() map[string]any {
|
||||
var ret map[string]any
|
||||
if r.chrt.Metadata == nil {
|
||||
return ret
|
||||
}
|
||||
|
|
@ -170,7 +170,7 @@ func (r *v3Accessor) MetaDependencies() []Dependency {
|
|||
return deps
|
||||
}
|
||||
|
||||
func (r *v3Accessor) Values() map[string]interface{} {
|
||||
func (r *v3Accessor) Values() map[string]any {
|
||||
return r.chrt.Values
|
||||
}
|
||||
|
||||
|
|
@ -182,7 +182,7 @@ func (r *v3Accessor) Deprecated() bool {
|
|||
return r.chrt.Metadata.Deprecated
|
||||
}
|
||||
|
||||
func structToMap(obj interface{}) (map[string]interface{}, error) {
|
||||
func structToMap(obj any) (map[string]any, error) {
|
||||
objValue := reflect.ValueOf(obj)
|
||||
|
||||
// If the value is a pointer, dereference it
|
||||
|
|
@ -195,7 +195,7 @@ func structToMap(obj interface{}) (map[string]interface{}, error) {
|
|||
return nil, fmt.Errorf("input must be a struct or a pointer to a struct")
|
||||
}
|
||||
|
||||
result := make(map[string]interface{})
|
||||
result := make(map[string]any)
|
||||
objType := objValue.Type()
|
||||
|
||||
for i := 0; i < objValue.NumField(); i++ {
|
||||
|
|
@ -221,7 +221,7 @@ func structToMap(obj interface{}) (map[string]interface{}, error) {
|
|||
result[field.Name] = nestedMap
|
||||
}
|
||||
case reflect.Slice:
|
||||
sliceOfMaps := make([]interface{}, value.Len())
|
||||
sliceOfMaps := make([]any, value.Len())
|
||||
for j := 0; j < value.Len(); j++ {
|
||||
sliceElement := value.Index(j)
|
||||
if sliceElement.Kind() == reflect.Struct || sliceElement.Kind() == reflect.Pointer {
|
||||
|
|
|
|||
|
|
@ -138,9 +138,9 @@ func TestValidateAgainstSchema(t *testing.T) {
|
|||
}
|
||||
chrt.AddDependency(subchart)
|
||||
|
||||
vals := map[string]interface{}{
|
||||
vals := map[string]any{
|
||||
"name": "John",
|
||||
"subchart": map[string]interface{}{
|
||||
"subchart": map[string]any{
|
||||
"age": 25,
|
||||
},
|
||||
}
|
||||
|
|
@ -165,9 +165,9 @@ func TestValidateAgainstSchemaNegative(t *testing.T) {
|
|||
}
|
||||
chrt.AddDependency(subchart)
|
||||
|
||||
vals := map[string]interface{}{
|
||||
vals := map[string]any{
|
||||
"name": "John",
|
||||
"subchart": map[string]interface{}{},
|
||||
"subchart": map[string]any{},
|
||||
}
|
||||
|
||||
var errString string
|
||||
|
|
@ -200,9 +200,9 @@ func TestValidateAgainstSchema2020(t *testing.T) {
|
|||
}
|
||||
chrt.AddDependency(subchart)
|
||||
|
||||
vals := map[string]interface{}{
|
||||
vals := map[string]any{
|
||||
"name": "John",
|
||||
"subchart": map[string]interface{}{
|
||||
"subchart": map[string]any{
|
||||
"data": []any{"hello", 12},
|
||||
},
|
||||
}
|
||||
|
|
@ -227,9 +227,9 @@ func TestValidateAgainstSchema2020Negative(t *testing.T) {
|
|||
}
|
||||
chrt.AddDependency(subchart)
|
||||
|
||||
vals := map[string]interface{}{
|
||||
vals := map[string]any{
|
||||
"name": "John",
|
||||
"subchart": map[string]interface{}{
|
||||
"subchart": map[string]any{
|
||||
"data": []any{12},
|
||||
},
|
||||
}
|
||||
|
|
@ -294,7 +294,7 @@ func TestValidateAgainstSingleSchema_UnresolvedURN_Ignored(t *testing.T) {
|
|||
"$schema": "https://json-schema.org/draft-07/schema#",
|
||||
"$ref": "urn:example:helm:schemas:v1:helm-schema-validation-conditions:v1/helmSchemaValidation-true"
|
||||
}`)
|
||||
vals := map[string]interface{}{"any": "value"}
|
||||
vals := map[string]any{"any": "value"}
|
||||
if err := ValidateAgainstSingleSchema(vals, schema); err != nil {
|
||||
t.Fatalf("expected no error when URN unresolved is ignored, got: %v", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,17 +26,17 @@ import (
|
|||
|
||||
func TestToRenderValues(t *testing.T) {
|
||||
|
||||
chartValues := map[string]interface{}{
|
||||
chartValues := map[string]any{
|
||||
"name": "al Rashid",
|
||||
"where": map[string]interface{}{
|
||||
"where": map[string]any{
|
||||
"city": "Basrah",
|
||||
"title": "caliph",
|
||||
},
|
||||
}
|
||||
|
||||
overrideValues := map[string]interface{}{
|
||||
overrideValues := map[string]any{
|
||||
"name": "Haroun",
|
||||
"where": map[string]interface{}{
|
||||
"where": map[string]any{
|
||||
"city": "Baghdad",
|
||||
"date": "809 CE",
|
||||
},
|
||||
|
|
@ -67,11 +67,11 @@ func TestToRenderValues(t *testing.T) {
|
|||
}
|
||||
|
||||
// Ensure that the top-level values are all set.
|
||||
metamap := res["Chart"].(map[string]interface{})
|
||||
metamap := res["Chart"].(map[string]any)
|
||||
if name := metamap["Name"]; name.(string) != "test" {
|
||||
t.Errorf("Expected chart name 'test', got %q", name)
|
||||
}
|
||||
relmap := res["Release"].(map[string]interface{})
|
||||
relmap := res["Release"].(map[string]any)
|
||||
if name := relmap["Name"]; name.(string) != "Seven Voyages" {
|
||||
t.Errorf("Expected release name 'Seven Voyages', got %q", name)
|
||||
}
|
||||
|
|
@ -98,7 +98,7 @@ func TestToRenderValues(t *testing.T) {
|
|||
if vals["name"] != "Haroun" {
|
||||
t.Errorf("Expected 'Haroun', got %q (%v)", vals["name"], vals)
|
||||
}
|
||||
where := vals["where"].(map[string]interface{})
|
||||
where := vals["where"].(map[string]any)
|
||||
expects := map[string]string{
|
||||
"city": "Baghdad",
|
||||
"date": "809 CE",
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ func TestValidateValuesFileWellFormed(t *testing.T) {
|
|||
`
|
||||
tmpdir := ensure.TempFile(t, "values.yaml", []byte(badYaml))
|
||||
valfile := filepath.Join(tmpdir, "values.yaml")
|
||||
if err := validateValuesFile(valfile, map[string]interface{}{}, false); err == nil {
|
||||
if err := validateValuesFile(valfile, map[string]any{}, false); err == nil {
|
||||
t.Fatal("expected values file to fail parsing")
|
||||
}
|
||||
}
|
||||
|
|
@ -78,7 +78,7 @@ func TestValidateValuesFileSchema(t *testing.T) {
|
|||
createTestingSchema(t, tmpdir)
|
||||
|
||||
valfile := filepath.Join(tmpdir, "values.yaml")
|
||||
if err := validateValuesFile(valfile, map[string]interface{}{}, false); err != nil {
|
||||
if err := validateValuesFile(valfile, map[string]any{}, false); err != nil {
|
||||
t.Fatalf("Failed validation with %s", err)
|
||||
}
|
||||
}
|
||||
|
|
@ -91,7 +91,7 @@ func TestValidateValuesFileSchemaFailure(t *testing.T) {
|
|||
|
||||
valfile := filepath.Join(tmpdir, "values.yaml")
|
||||
|
||||
err := validateValuesFile(valfile, map[string]interface{}{}, false)
|
||||
err := validateValuesFile(valfile, map[string]any{}, false)
|
||||
if err == nil {
|
||||
t.Fatal("expected values file to fail parsing")
|
||||
}
|
||||
|
|
@ -107,7 +107,7 @@ func TestValidateValuesFileSchemaFailureButWithSkipSchemaValidation(t *testing.T
|
|||
|
||||
valfile := filepath.Join(tmpdir, "values.yaml")
|
||||
|
||||
err := validateValuesFile(valfile, map[string]interface{}{}, true)
|
||||
err := validateValuesFile(valfile, map[string]any{}, true)
|
||||
if err != nil {
|
||||
t.Fatal("expected values file to pass parsing because of skipSchemaValidation")
|
||||
}
|
||||
|
|
@ -115,7 +115,7 @@ func TestValidateValuesFileSchemaFailureButWithSkipSchemaValidation(t *testing.T
|
|||
|
||||
func TestValidateValuesFileSchemaOverrides(t *testing.T) {
|
||||
yaml := "username: admin"
|
||||
overrides := map[string]interface{}{
|
||||
overrides := map[string]any{
|
||||
"password": "swordfish",
|
||||
}
|
||||
tmpdir := ensure.TempFile(t, "values.yaml", []byte(yaml))
|
||||
|
|
@ -131,24 +131,24 @@ func TestValidateValuesFile(t *testing.T) {
|
|||
tests := []struct {
|
||||
name string
|
||||
yaml string
|
||||
overrides map[string]interface{}
|
||||
overrides map[string]any
|
||||
errorMessage string
|
||||
}{
|
||||
{
|
||||
name: "value added",
|
||||
yaml: "username: admin",
|
||||
overrides: map[string]interface{}{"password": "swordfish"},
|
||||
overrides: map[string]any{"password": "swordfish"},
|
||||
},
|
||||
{
|
||||
name: "value not overridden",
|
||||
yaml: "username: admin\npassword:",
|
||||
overrides: map[string]interface{}{"username": "anotherUser"},
|
||||
overrides: map[string]any{"username": "anotherUser"},
|
||||
errorMessage: "- at '/password': got null, want string",
|
||||
},
|
||||
{
|
||||
name: "value overridden",
|
||||
yaml: "username: admin\npassword:",
|
||||
overrides: map[string]interface{}{"username": "anotherUser", "password": "swordfish"},
|
||||
overrides: map[string]any{"username": "anotherUser", "password": "swordfish"},
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -209,11 +209,11 @@ func LoadFiles(files []*archive.BufferedFile) (*chart.Chart, error) {
|
|||
//
|
||||
// The reader is expected to contain one or more YAML documents, the values of which are merged.
|
||||
// And the values can be either a chart's default values or user-supplied values.
|
||||
func LoadValues(data io.Reader) (map[string]interface{}, error) {
|
||||
values := map[string]interface{}{}
|
||||
func LoadValues(data io.Reader) (map[string]any, error) {
|
||||
values := map[string]any{}
|
||||
reader := utilyaml.NewYAMLReader(bufio.NewReader(data))
|
||||
for {
|
||||
currentMap := map[string]interface{}{}
|
||||
currentMap := map[string]any{}
|
||||
raw, err := reader.Read()
|
||||
if err != nil {
|
||||
if errors.Is(err, io.EOF) {
|
||||
|
|
@ -231,13 +231,13 @@ func LoadValues(data io.Reader) (map[string]interface{}, error) {
|
|||
|
||||
// MergeMaps merges two maps. If a key exists in both maps, the value from b will be used.
|
||||
// If the value is a map, the maps will be merged recursively.
|
||||
func MergeMaps(a, b map[string]interface{}) map[string]interface{} {
|
||||
out := make(map[string]interface{}, len(a))
|
||||
func MergeMaps(a, b map[string]any) map[string]any {
|
||||
out := make(map[string]any, len(a))
|
||||
maps.Copy(out, a)
|
||||
for k, v := range b {
|
||||
if v, ok := v.(map[string]interface{}); ok {
|
||||
if v, ok := v.(map[string]any); ok {
|
||||
if bv, ok := out[k]; ok {
|
||||
if bv, ok := bv.(map[string]interface{}); ok {
|
||||
if bv, ok := bv.(map[string]any); ok {
|
||||
out[k] = MergeMaps(bv, v)
|
||||
continue
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ import (
|
|||
"k8s.io/client-go/rest"
|
||||
)
|
||||
|
||||
type lookupFunc = func(apiversion string, resource string, namespace string, name string) (map[string]interface{}, error)
|
||||
type lookupFunc = func(apiversion string, resource string, namespace string, name string) (map[string]any, error)
|
||||
|
||||
// NewLookupFunction returns a function for looking up objects in the cluster.
|
||||
//
|
||||
|
|
@ -55,11 +55,11 @@ func (c clientProviderFromConfig) GetClientFor(apiVersion, kind string) (dynamic
|
|||
}
|
||||
|
||||
func newLookupFunction(clientProvider ClientProvider) lookupFunc {
|
||||
return func(apiversion string, kind string, namespace string, name string) (map[string]interface{}, error) {
|
||||
return func(apiversion string, kind string, namespace string, name string) (map[string]any, error) {
|
||||
var client dynamic.ResourceInterface
|
||||
c, namespaced, err := clientProvider.GetClientFor(apiversion, kind)
|
||||
if err != nil {
|
||||
return map[string]interface{}{}, err
|
||||
return map[string]any{}, err
|
||||
}
|
||||
if namespaced && namespace != "" {
|
||||
client = c.Namespace(namespace)
|
||||
|
|
@ -73,9 +73,9 @@ func newLookupFunction(clientProvider ClientProvider) lookupFunc {
|
|||
if apierrors.IsNotFound(err) {
|
||||
// Just return an empty interface when the object was not found.
|
||||
// That way, users can use `if not (lookup ...)` in their templates.
|
||||
return map[string]interface{}{}, nil
|
||||
return map[string]any{}, nil
|
||||
}
|
||||
return map[string]interface{}{}, err
|
||||
return map[string]any{}, err
|
||||
}
|
||||
return obj.UnstructuredContent(), nil
|
||||
}
|
||||
|
|
@ -85,9 +85,9 @@ func newLookupFunction(clientProvider ClientProvider) lookupFunc {
|
|||
if apierrors.IsNotFound(err) {
|
||||
// Just return an empty interface when the object was not found.
|
||||
// That way, users can use `if not (lookup ...)` in their templates.
|
||||
return map[string]interface{}{}, nil
|
||||
return map[string]any{}, nil
|
||||
}
|
||||
return map[string]interface{}{}, err
|
||||
return map[string]any{}, err
|
||||
}
|
||||
return obj.UnstructuredContent(), nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue