Skip to content

Commit

Permalink
testenv: Allow klog and glog to coexist
Browse files Browse the repository at this point in the history
This change allows tests environments with glog to work with testenv.

Signed-off-by: Sunny <darkowlzz@protonmail.com>
  • Loading branch information
darkowlzz committed Sep 16, 2021
1 parent d726dea commit 7c6d0e3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion runtime/testenv/testenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ package testenv

import (
"context"
"flag"
"fmt"
"sync"
"time"
Expand Down Expand Up @@ -53,7 +54,14 @@ var (
)

func init() {
klog.InitFlags(nil)
// NOTE: The following enables glog and klog to coexist. If a test depends
// on a package that uses glog, klog flag initialization here would result
// in redeclaration of some flags. The following creates a new FlagSet and
// uses it to initializes klog.
// Refer: https://github.com/kubernetes/klog/blob/f8e668dbaa5f6f0e6a5c24ffd7667263840d79ae/examples/coexist_glog/coexist_glog.go
klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
klog.InitFlags(klogFlags)

logger := klogr.New()
log.SetLogger(logger)
ctrl.SetLogger(logger)
Expand Down

0 comments on commit 7c6d0e3

Please sign in to comment.