fix(logging): address review feedback and rebase against origin/main

- Revert ProcessDependencies, ValidateAgainstSchema, ValidateAgainstSingleSchema
  to original 2-arg public signatures; use slog.Default() internally
- Use slog.Warn in cmd/helm/helm.go instead of fmt.Fprintf(os.Stderr)
- Call slog.SetDefault(logger) in newRootCmdWithConfig so global slog
  functions (e.g. LogIgnorePluginLoadErrorFilterFunc) use the configured handler
- Fix callers that still passed nil logger after public API revert
- Resolve rebase conflicts with origin/main (map[string]any, slices.Backward,
  plugin.LoadAllDir improvements)

Signed-off-by: JaeguKim <rlaworn1993@gmail.com>
pull/31833/head
JaeguKim 5 months ago
parent 5d84ee32ce
commit c65584458c

@ -88,7 +88,7 @@ func TemplatesWithSkipSchemaValidation(linter *support.Linter, values map[string
// lint ignores import-values // lint ignores import-values
// See https://github.com/helm/helm/issues/9658 // See https://github.com/helm/helm/issues/9658
if err := chartutil.ProcessDependencies(chart, values, nil); err != nil { if err := chartutil.ProcessDependencies(chart, values); err != nil {
return return
} }

@ -78,7 +78,7 @@ func validateValuesFile(valuesPath string, overrides map[string]any, skipSchemaV
} }
if !skipSchemaValidation { if !skipSchemaValidation {
return util.ValidateAgainstSingleSchema(coalescedValues, schema, nil) return util.ValidateAgainstSingleSchema(coalescedValues, schema)
} }
return nil return nil

@ -347,7 +347,7 @@ func (cfg *Configuration) renderResources(ch *chart.Chart, values common.Values,
// that is also declared in the chart's regular templates). For // that is also declared in the chart's regular templates). For
// "nohooks", hooks skip the post-renderer entirely, matching the // "nohooks", hooks skip the post-renderer entirely, matching the
// Helm 3 behavior. // Helm 3 behavior.
sortedHooks, sortedManifests, err := releaseutil.SortManifests(files, nil, releaseutil.InstallOrder) sortedHooks, sortedManifests, err := releaseutil.SortManifests(files, nil, releaseutil.InstallOrder, cfg.Logger())
if err != nil { if err != nil {
for name, content := range files { for name, content := range files {
if strings.TrimSpace(content) == "" { if strings.TrimSpace(content) == "" {

@ -277,7 +277,7 @@ func (u *Upgrade) prepareUpgrade(name string, chart *chartv2.Chart, vals map[str
return nil, nil, false, err return nil, nil, false, err
} }
if err := chartutil.ProcessDependencies(chart, vals, nil); err != nil { if err := chartutil.ProcessDependencies(chart, vals); err != nil {
return nil, nil, false, err return nil, nil, false, err
} }

@ -235,13 +235,8 @@ func TestValidateAgainstSchema2020Negative(t *testing.T) {
} }
var errString string var errString string
<<<<<<< HEAD
if err := ValidateAgainstSchema(chrt, vals); err == nil { if err := ValidateAgainstSchema(chrt, vals); err == nil {
t.Fatal("Expected an error, but got nil") t.Fatal("Expected an error, but got nil")
=======
if err := ValidateAgainstSchema(chrt, vals, nil); err == nil {
t.Fatalf("Expected an error, but got nil")
>>>>>>> 6f8673662 (fix(logging): replace global slog usage with dependency-injected loggers)
} else { } else {
errString = err.Error() errString = err.Error()
} }
@ -300,7 +295,7 @@ func TestValidateAgainstSingleSchema_UnresolvedURN_Ignored(t *testing.T) {
"$ref": "urn:example:helm:schemas:v1:helm-schema-validation-conditions:v1/helmSchemaValidation-true" "$ref": "urn:example:helm:schemas:v1:helm-schema-validation-conditions:v1/helmSchemaValidation-true"
}`) }`)
vals := map[string]any{"any": "value"} vals := map[string]any{"any": "value"}
if err := ValidateAgainstSingleSchema(vals, schema, nil); err != nil { if err := ValidateAgainstSingleSchema(vals, schema); err != nil {
t.Fatalf("expected no error when URN unresolved is ignored, got: %v", err) t.Fatalf("expected no error when URN unresolved is ignored, got: %v", err)
} }
} }
@ -333,7 +328,7 @@ func TestValidateAgainstSchema_MissingSubchartValues_NoPanic(t *testing.T) {
} }
}() }()
if err := ValidateAgainstSchema(chrt, vals, nil); err != nil { if err := ValidateAgainstSchema(chrt, vals); err != nil {
t.Fatalf("expected no error when subchart values are missing, got: %v", err) t.Fatalf("expected no error when subchart values are missing, got: %v", err)
} }
} }
@ -361,7 +356,7 @@ func TestValidateAgainstSchema_SubchartNil_NoPanic(t *testing.T) {
} }
}() }()
if err := ValidateAgainstSchema(chrt, vals, nil); err != nil { if err := ValidateAgainstSchema(chrt, vals); err != nil {
t.Fatalf("expected no error when subchart values are nil, got: %v", err) t.Fatalf("expected no error when subchart values are nil, got: %v", err)
} }
} }
@ -390,12 +385,7 @@ func TestValidateAgainstSchema_InvalidSubchartValuesType_NoPanic(t *testing.T) {
}() }()
// We expect a non-nil error (invalid type), but crucially no panic. // We expect a non-nil error (invalid type), but crucially no panic.
<<<<<<< HEAD
if err := ValidateAgainstSchema(chrt, vals); err == nil { if err := ValidateAgainstSchema(chrt, vals); err == nil {
t.Fatal("expected an error when subchart values have invalid type, got nil") t.Fatal("expected an error when subchart values have invalid type, got nil")
=======
if err := ValidateAgainstSchema(chrt, vals, nil); err == nil {
t.Fatalf("expected an error when subchart values have invalid type, got nil")
>>>>>>> 6f8673662 (fix(logging): replace global slog usage with dependency-injected loggers)
} }
} }

@ -119,7 +119,7 @@ func (t *templateLinter) Lint() {
// lint ignores import-values // lint ignores import-values
// See https://github.com/helm/helm/issues/9658 // See https://github.com/helm/helm/issues/9658
if err := chartutil.ProcessDependencies(chart, t.values, nil); err != nil { if err := chartutil.ProcessDependencies(chart, t.values); err != nil {
return return
} }

@ -78,7 +78,7 @@ func validateValuesFile(valuesPath string, overrides map[string]any, skipSchemaV
} }
if !skipSchemaValidation { if !skipSchemaValidation {
return util.ValidateAgainstSingleSchema(coalescedValues, schema, nil) return util.ValidateAgainstSingleSchema(coalescedValues, schema)
} }
return nil return nil

@ -177,6 +177,7 @@ func newRootCmdWithConfig(actionConfig *action.Configuration, out io.Writer, arg
flags.Parse(args) flags.Parse(args)
logger := logSetup(settings.Debug) logger := logSetup(settings.Debug)
slog.SetDefault(logger)
actionConfig.SetLogger(logger.Handler()) actionConfig.SetLogger(logger.Handler())
// Validate color mode setting // Validate color mode setting

@ -149,9 +149,9 @@ func TestRootCmdLogger(t *testing.T) {
t.Error("expected actionConfig logger to be set, got discard handler") t.Error("expected actionConfig logger to be set, got discard handler")
} }
// The actionConfig logger should NOT be the global default (we no longer set slog.SetDefault) // slog.SetDefault is called so the global default should use the same handler
if l.Handler() == slog.Default().Handler() { if l.Handler() != slog.Default().Handler() {
t.Error("expected actionConfig logger to NOT be the slog default logger") t.Error("expected actionConfig logger to match the global slog default logger")
} }
} }

@ -21,6 +21,7 @@ import (
"context" "context"
"errors" "errors"
"io" "io"
"log/slog"
"net/http" "net/http"
"strings" "strings"
"sync" "sync"
@ -1664,7 +1665,7 @@ func TestPatchResourceClientSide(t *testing.T) {
original := resourceListOriginal[0] original := resourceListOriginal[0]
target := resourceListTarget[0] target := resourceListTarget[0]
err = patchResourceClientSide(original.Object, target, tc.ThreeWayMergeForUnstructured) err = patchResourceClientSide(original.Object, target, tc.ThreeWayMergeForUnstructured, slog.Default())
if tc.ExpectedErrorContains != "" { if tc.ExpectedErrorContains != "" {
require.ErrorContains(t, err, tc.ExpectedErrorContains) require.ErrorContains(t, err, tc.ExpectedErrorContains)
} else { } else {

Loading…
Cancel
Save