Merge pull request #31560 from mattfarina/fix-kube-client-logging

Fix kube client logging
pull/31566/head
George Jenkins 8 months ago committed by GitHub
commit 00e12b8477
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -179,6 +179,16 @@ func newRootCmdWithConfig(actionConfig *action.Configuration, out io.Writer, arg
logSetup(settings.Debug)
// newRootCmdWithConfig is only called from NewRootCmd. NewRootCmd sets up
// NewConfiguration without a custom logger. So, the slog default is used. logSetup
// can change the default logger to the one in the logger package. This happens for
// the Helm client. This means the actionConfig logger is different from the slog
// default logger. If they are different we sync the actionConfig logger to the slog
// current default one.
if actionConfig.Logger() != slog.Default() {
actionConfig.SetLogger(slog.Default().Handler())
}
// Validate color mode setting
switch settings.ColorMode {
case "never", "auto", "always":

@ -17,11 +17,14 @@ limitations under the License.
package cmd
import (
"bytes"
"log/slog"
"os"
"path/filepath"
"testing"
"helm.sh/helm/v4/internal/test/ensure"
"helm.sh/helm/v4/pkg/action"
"helm.sh/helm/v4/pkg/helmpath"
"helm.sh/helm/v4/pkg/helmpath/xdg"
)
@ -129,3 +132,20 @@ func TestUnknownSubCmd(t *testing.T) {
// func TestRootFileCompletion(t *testing.T) {
// checkFileCompletion(t, "", false)
// }
func TestRootCmdLogger(t *testing.T) {
args := []string{}
buf := new(bytes.Buffer)
actionConfig := action.NewConfiguration()
_, err := newRootCmdWithConfig(actionConfig, buf, args, SetupLogging)
if err != nil {
t.Errorf("expected no error, got: '%v'", err)
}
l1 := actionConfig.Logger()
l2 := slog.Default()
if l1.Handler() != l2.Handler() {
t.Error("expected actionConfig logger to be the slog default logger")
}
}

Loading…
Cancel
Save