Skip to content

Commit 5210373

Browse files
committed
Init useful flags for klog/v2
1 parent e43459d commit 5210373

File tree

20 files changed

+69
-1869
lines changed

20 files changed

+69
-1869
lines changed

cmd/healthchecker/health_checker.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,17 @@ import (
3030
)
3131

3232
func main() {
33-
// Set klog flag so that it does not log to files.
34-
klog.InitFlags(nil)
35-
if err := flag.Set("logtostderr", "true"); err != nil {
36-
fmt.Printf("Failed to set logtostderr=true: %v", err)
37-
os.Exit(int(types.Unknown))
38-
}
39-
33+
klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
34+
klog.InitFlags(klogFlags)
35+
klogFlags.VisitAll(func(f *flag.Flag) {
36+
switch f.Name {
37+
case "v", "vmodule", "logtostderr":
38+
flag.CommandLine.Var(f.Value, f.Name, f.Usage)
39+
}
40+
})
41+
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
42+
pflag.CommandLine.MarkHidden("vmodule")
43+
pflag.CommandLine.MarkHidden("logtostderr")
4044

4145
hco := options.NewHealthCheckerOptions()
4246
hco.AddFlags(pflag.CommandLine)

cmd/logcounter/log_counter.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,17 @@ import (
3333
)
3434

3535
func main() {
36-
// Set klog flag so that it does not log to files.
37-
klog.InitFlags(nil)
38-
39-
if err := flag.Set("logtostderr", "true"); err != nil {
40-
fmt.Printf("Failed to set logtostderr=true: %v", err)
41-
os.Exit(int(types.Unknown))
42-
}
36+
klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
37+
klog.InitFlags(klogFlags)
38+
klogFlags.VisitAll(func(f *flag.Flag) {
39+
switch f.Name {
40+
case "v", "vmodule", "logtostderr":
41+
flag.CommandLine.Var(f.Value, f.Name, f.Usage)
42+
}
43+
})
44+
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
45+
pflag.CommandLine.MarkHidden("vmodule")
46+
pflag.CommandLine.MarkHidden("logtostderr")
4347

4448
fedo := options.NewLogCounterOptions()
4549
fedo.AddFlags(pflag.CommandLine)

cmd/nodeproblemdetector/node_problem_detector_linux.go renamed to cmd/nodeproblemdetector/node_problem_detector_unix.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build unix
2+
13
/*
24
Copyright 2021 The Kubernetes Authors All rights reserved.
35
@@ -18,13 +20,26 @@ package main
1820

1921
import (
2022
"context"
23+
"flag"
2124

2225
"github.com/spf13/pflag"
2326
"k8s.io/klog/v2"
2427
"k8s.io/node-problem-detector/cmd/options"
2528
)
2629

2730
func main() {
31+
klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
32+
klog.InitFlags(klogFlags)
33+
klogFlags.VisitAll(func(f *flag.Flag) {
34+
switch f.Name {
35+
case "v", "vmodule", "logtostderr":
36+
flag.CommandLine.Var(f.Value, f.Name, f.Usage)
37+
}
38+
})
39+
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
40+
pflag.CommandLine.MarkHidden("vmodule")
41+
pflag.CommandLine.MarkHidden("logtostderr")
42+
2843
npdo := options.NewNodeProblemDetectorOptions()
2944
npdo.AddFlags(pflag.CommandLine)
3045

cmd/nodeproblemdetector/node_problem_detector_windows.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package main
1818

1919
import (
2020
"context"
21+
"flag"
2122
"fmt"
2223
"sync"
2324
"time"
@@ -43,6 +44,18 @@ var (
4344
)
4445

4546
func main() {
47+
klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
48+
klog.InitFlags(klogFlags)
49+
klogFlags.VisitAll(func(f *flag.Flag) {
50+
switch f.Name {
51+
case "v", "vmodule", "logtostderr":
52+
flag.CommandLine.Var(f.Value, f.Name, f.Usage)
53+
}
54+
})
55+
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
56+
pflag.CommandLine.MarkHidden("vmodule")
57+
pflag.CommandLine.MarkHidden("logtostderr")
58+
4659
npdo := options.NewNodeProblemDetectorOptions()
4760
npdo.AddFlags(pflag.CommandLine)
4861

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,6 @@ github.com/golang-jwt/jwt/v4 v4.0.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzw
524524
github.com/golang-jwt/jwt/v4 v4.2.0/go.mod h1:/xlHOz8bRuivTWchD4jCa+NbatV+wEUSzwAxVc6locg=
525525
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
526526
github.com/golang/glog v1.0.0/go.mod h1:EWib/APOK0SL3dFbYqvxE3UYd8E6s1ouQ7iEp/0LWV4=
527-
github.com/golang/glog v1.1.0/go.mod h1:pfYeQZ3JWZoXTV5sFc986z3HTpwQs9At6P4ImfuP3NQ=
528527
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
529528
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
530529
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
@@ -1870,7 +1869,6 @@ k8s.io/gengo v0.0.0-20200413195148-3a45101e95ac/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8
18701869
k8s.io/gengo v0.0.0-20200428234225-8167cfdcfc14/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
18711870
k8s.io/gengo v0.0.0-20201113003025-83324d819ded/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
18721871
k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
1873-
k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8=
18741872
k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
18751873
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
18761874
k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y=

pkg/healthchecker/health_checker_darwin.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,30 @@ import (
2020
"runtime"
2121
"time"
2222

23-
"github.com/golang/glog"
24-
23+
"k8s.io/klog/v2"
2524
"k8s.io/node-problem-detector/cmd/healthchecker/options"
2625
)
2726

2827
// getUptimeFunc returns the time for which the given service has been running.
2928
func getUptimeFunc(service string) func() (time.Duration, error) {
30-
glog.Fatalf("getUptimeFunc is not supported in %s", runtime.GOOS)
29+
klog.Fatalf("getUptimeFunc is not supported in %s", runtime.GOOS)
3130
return func() (time.Duration, error) { return time.Second, nil }
3231
}
3332

3433
// getRepairFunc returns the repair function based on the component.
3534
func getRepairFunc(hco *options.HealthCheckerOptions) func() {
36-
glog.Fatalf("getRepairFunc is not supported in %s", runtime.GOOS)
35+
klog.Fatalf("getRepairFunc is not supported in %s", runtime.GOOS)
3736
return func() {}
3837
}
3938

4039
// checkForPattern returns (true, nil) if logPattern occurs less than logCountThreshold number of times since last
4140
// service restart. (false, nil) otherwise.
4241
func checkForPattern(service, logStartTime, logPattern string, logCountThreshold int) (bool, error) {
43-
glog.Fatalf("checkForPattern is not supported in %s", runtime.GOOS)
42+
klog.Fatalf("checkForPattern is not supported in %s", runtime.GOOS)
4443
return false, nil
4544
}
4645

4746
func getDockerPath() string {
48-
glog.Fatalf("getDockerPath is not supported in %s", runtime.GOOS)
47+
klog.Fatalf("getDockerPath is not supported in %s", runtime.GOOS)
4948
return ""
5049
}

pkg/systemlogmonitor/logwatchers/kmsg/log_watcher_darwin.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@ package kmsg
1919
import (
2020
"runtime"
2121

22-
"github.com/golang/glog"
23-
22+
"k8s.io/klog/v2"
2423
"k8s.io/node-problem-detector/pkg/systemlogmonitor/logwatchers/types"
2524
)
2625

2726
// NewKmsgWatcher creates a watcher which will read messages from /dev/kmsg
2827
func NewKmsgWatcher(cfg types.WatcherConfig) types.LogWatcher {
29-
glog.Fatalf("kmsg parser is not supported in %s", runtime.GOOS)
28+
klog.Fatalf("kmsg parser is not supported in %s", runtime.GOOS)
3029
return nil
3130
}

test/e2e/problemmaker/problem_maker.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package main
1919
import (
2020
"flag"
2121
"fmt"
22-
"os"
2322
"strings"
2423
"time"
2524

@@ -29,10 +28,6 @@ import (
2928
"k8s.io/node-problem-detector/test/e2e/problemmaker/makers"
3029
)
3130

32-
func init() {
33-
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
34-
}
35-
3631
type options struct {
3732
// Command line options. See flag descriptions for the description
3833
Rate float32
@@ -54,12 +49,17 @@ func (o *options) AddFlags(fs *pflag.FlagSet) {
5449
}
5550

5651
func main() {
57-
// Set klog flag so that it does not log to files.
58-
klog.InitFlags(nil)
59-
if err := flag.Set("logtostderr", "true"); err != nil {
60-
fmt.Printf("Failed to set logtostderr=true: %v\n", err)
61-
os.Exit(1)
62-
}
52+
klogFlags := flag.NewFlagSet("klog", flag.ExitOnError)
53+
klog.InitFlags(klogFlags)
54+
klogFlags.VisitAll(func(f *flag.Flag) {
55+
switch f.Name {
56+
case "v", "vmodule", "logtostderr":
57+
flag.CommandLine.Var(f.Value, f.Name, f.Usage)
58+
}
59+
})
60+
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
61+
pflag.CommandLine.MarkHidden("vmodule")
62+
pflag.CommandLine.MarkHidden("logtostderr")
6363

6464
o := options{}
6565
o.AddFlags(pflag.CommandLine)

third_party/forked/cadvisor/tail/tail_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
"sync"
2525
"time"
2626

27-
"k8s.io/klog"
27+
"k8s.io/klog/v2"
2828
inotify "k8s.io/utils/inotify"
2929
)
3030

vendor/k8s.io/klog/.travis.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

vendor/k8s.io/klog/CONTRIBUTING.md

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)