Skip to content

Commit

Permalink
Merge pull request #124415 from pohly/automated-cherry-pick-of-#12428…
Browse files Browse the repository at this point in the history
…9-origin-release-1.30

Automated cherry pick of #124289: e2e node: fix -v support
  • Loading branch information
k8s-ci-robot committed May 10, 2024
2 parents 4183998 + 7e5e4c3 commit 7d9aab8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
23 changes: 20 additions & 3 deletions test/e2e/framework/ginkgologger.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,16 @@ var (

func init() {
// ktesting and testinit already registered the -v and -vmodule
// command line flags. To configure the textlogger instead, we
// need to swap out the flag.Value for those.
// command line flags. To configure the textlogger and klog
// consistently, we need to intercept the Set call. This
// can be done by swapping out the flag.Value for the -v and
// -vmodule flags with a wrapper which calls both.
var fs flag.FlagSet
logConfig.AddFlags(&fs)
fs.VisitAll(func(loggerFlag *flag.Flag) {
klogFlag := flag.CommandLine.Lookup(loggerFlag.Name)
if klogFlag != nil {
klogFlag.Value = loggerFlag.Value
klogFlag.Value = &valueChain{Value: loggerFlag.Value, parentValue: klogFlag.Value}
}
})

Expand All @@ -75,6 +77,21 @@ func init() {
klog.SetLoggerWithOptions(ginkgoLogger, opts...)
}

type valueChain struct {
flag.Value
parentValue flag.Value
}

func (v *valueChain) Set(value string) error {
if err := v.Value.Set(value); err != nil {
return err
}
if err := v.parentValue.Set(value); err != nil {
return err
}
return nil
}

func unwind(skip int) (string, int) {
location := ginkgotypes.NewCodeLocation(skip + 1)
return location.FileName, location.LineNumber
Expand Down
2 changes: 0 additions & 2 deletions test/e2e_node/e2e_node_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ import (
utilfeature "k8s.io/apiserver/pkg/util/feature"
clientset "k8s.io/client-go/kubernetes"
cliflag "k8s.io/component-base/cli/flag"
"k8s.io/component-base/logs"
"k8s.io/kubernetes/pkg/util/rlimit"
commontest "k8s.io/kubernetes/test/e2e/common"
"k8s.io/kubernetes/test/e2e/framework"
Expand Down Expand Up @@ -123,7 +122,6 @@ func TestMain(m *testing.M) {
e2econfig.CopyFlags(e2econfig.Flags, flag.CommandLine)
framework.RegisterCommonFlags(flag.CommandLine)
registerNodeFlags(flag.CommandLine)
logs.AddFlags(pflag.CommandLine)
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
// Mark the run-services-mode flag as hidden to prevent user from using it.
pflag.CommandLine.MarkHidden("run-services-mode")
Expand Down

0 comments on commit 7d9aab8

Please sign in to comment.