Skip to content

Commit e43459d

Browse files
mrueghakman
authored andcommitted
Move glog/klog logging to klog/v2
1 parent eeab0ab commit e43459d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+233
-2530
lines changed

cmd/healthchecker/health_checker.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,21 @@ import (
2323

2424
"github.com/spf13/pflag"
2525

26+
"k8s.io/klog/v2"
2627
"k8s.io/node-problem-detector/cmd/healthchecker/options"
2728
"k8s.io/node-problem-detector/pkg/custompluginmonitor/types"
2829
"k8s.io/node-problem-detector/pkg/healthchecker"
2930
)
3031

3132
func main() {
32-
// Set glog flag so that it does not log to files.
33+
// Set klog flag so that it does not log to files.
34+
klog.InitFlags(nil)
3335
if err := flag.Set("logtostderr", "true"); err != nil {
3436
fmt.Printf("Failed to set logtostderr=true: %v", err)
3537
os.Exit(int(types.Unknown))
3638
}
3739

40+
3841
hco := options.NewHealthCheckerOptions()
3942
hco.AddFlags(pflag.CommandLine)
4043
pflag.Parse()

cmd/logcounter/log_counter.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,16 @@ import (
2626

2727
"github.com/spf13/pflag"
2828

29+
"k8s.io/klog/v2"
2930
"k8s.io/node-problem-detector/cmd/logcounter/options"
3031
"k8s.io/node-problem-detector/pkg/custompluginmonitor/types"
3132
"k8s.io/node-problem-detector/pkg/logcounter"
3233
)
3334

3435
func main() {
35-
// Set glog flag so that it does not log to files.
36+
// Set klog flag so that it does not log to files.
37+
klog.InitFlags(nil)
38+
3639
if err := flag.Set("logtostderr", "true"); err != nil {
3740
fmt.Printf("Failed to set logtostderr=true: %v", err)
3841
os.Exit(int(types.Unknown))

cmd/nodeproblemdetector/node_problem_detector.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package main
1919
import (
2020
"context"
2121

22-
"github.com/golang/glog"
22+
"k8s.io/klog/v2"
2323

2424
_ "k8s.io/node-problem-detector/cmd/nodeproblemdetector/exporterplugins"
2525
_ "k8s.io/node-problem-detector/cmd/nodeproblemdetector/problemdaemonplugins"
@@ -46,18 +46,18 @@ func npdMain(ctx context.Context, npdo *options.NodeProblemDetectorOptions) erro
4646
// Initialize problem daemons.
4747
problemDaemons := problemdaemon.NewProblemDaemons(npdo.MonitorConfigPaths)
4848
if len(problemDaemons) == 0 {
49-
glog.Fatalf("No problem daemon is configured")
49+
klog.Fatalf("No problem daemon is configured")
5050
}
5151

5252
// Initialize exporters.
5353
defaultExporters := []types.Exporter{}
5454
if ke := k8sexporter.NewExporterOrDie(ctx, npdo); ke != nil {
5555
defaultExporters = append(defaultExporters, ke)
56-
glog.Info("K8s exporter started.")
56+
klog.Info("K8s exporter started.")
5757
}
5858
if pe := prometheusexporter.NewExporterOrDie(npdo); pe != nil {
5959
defaultExporters = append(defaultExporters, pe)
60-
glog.Info("Prometheus exporter started.")
60+
klog.Info("Prometheus exporter started.")
6161
}
6262

6363
plugableExporters := exporters.NewExporters()
@@ -67,7 +67,7 @@ func npdMain(ctx context.Context, npdo *options.NodeProblemDetectorOptions) erro
6767
npdExporters = append(npdExporters, plugableExporters...)
6868

6969
if len(npdExporters) == 0 {
70-
glog.Fatalf("No exporter is successfully setup")
70+
klog.Fatalf("No exporter is successfully setup")
7171
}
7272

7373
// Initialize NPD core.

cmd/nodeproblemdetector/node_problem_detector_linux.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ package main
1919
import (
2020
"context"
2121

22-
"github.com/golang/glog"
2322
"github.com/spf13/pflag"
23+
"k8s.io/klog/v2"
2424
"k8s.io/node-problem-detector/cmd/options"
2525
)
2626

@@ -30,6 +30,6 @@ func main() {
3030

3131
pflag.Parse()
3232
if err := npdMain(context.Background(), npdo); err != nil {
33-
glog.Fatalf("Problem detector failed with error: %v", err)
33+
klog.Fatalf("Problem detector failed with error: %v", err)
3434
}
3535
}

cmd/nodeproblemdetector/node_problem_detector_windows.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ import (
2222
"sync"
2323
"time"
2424

25-
"github.com/golang/glog"
2625
"github.com/spf13/pflag"
2726
"golang.org/x/sys/windows/svc"
2827
"golang.org/x/sys/windows/svc/debug"
2928
"golang.org/x/sys/windows/svc/eventlog"
29+
"k8s.io/klog/v2"
3030
"k8s.io/node-problem-detector/cmd/options"
3131
)
3232

@@ -62,7 +62,7 @@ func main() {
6262
func isRunningAsWindowsService() bool {
6363
runningAsService, err := svc.IsWindowsService()
6464
if err != nil {
65-
glog.Errorf("cannot determine if running as Windows Service assuming standalone, %v", err)
65+
klog.Errorf("cannot determine if running as Windows Service assuming standalone, %v", err)
6666
return false
6767
}
6868
return runningAsService

cmd/nodeproblemdetector/node_problem_detector_windows_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ limitations under the License.
2020
package main
2121

2222
import (
23-
"context"
2423
"testing"
2524

2625
"golang.org/x/sys/windows/svc"

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ require (
1111
github.com/avast/retry-go v3.0.0+incompatible
1212
github.com/coreos/go-systemd v0.0.0-20191104093116-d3cd4ed1dbcf
1313
github.com/euank/go-kmsg-parser v2.0.0+incompatible
14-
github.com/golang/glog v1.1.2
1514
github.com/hpcloud/tail v1.0.0
1615
github.com/prometheus/client_model v0.4.0
1716
github.com/prometheus/common v0.44.0
@@ -25,7 +24,7 @@ require (
2524
k8s.io/api v0.28.2
2625
k8s.io/apimachinery v0.28.2
2726
k8s.io/client-go v0.28.2
28-
k8s.io/klog v1.0.0
27+
k8s.io/klog/v2 v2.100.1
2928
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
3029
)
3130

@@ -96,7 +95,6 @@ require (
9695
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
9796
gopkg.in/yaml.v2 v2.4.0 // indirect
9897
gopkg.in/yaml.v3 v3.0.1 // indirect
99-
k8s.io/klog/v2 v2.100.1 // indirect
10098
k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
10199
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
102100
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect

go.sum

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,7 @@ 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.2 h1:DVjP2PbBOzHyzA+dn3WhHIq4NdVu3Q+pvivFICf/7fo=
528-
github.com/golang/glog v1.1.2/go.mod h1:zR+okUeTbrL6EL3xHUDxZuEtGv04p5shwip1+mL/rLQ=
527+
github.com/golang/glog v1.1.0/go.mod h1:pfYeQZ3JWZoXTV5sFc986z3HTpwQs9At6P4ImfuP3NQ=
529528
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
530529
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
531530
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=

pkg/custompluginmonitor/custom_plugin_monitor.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"os"
2222
"time"
2323

24-
"github.com/golang/glog"
24+
"k8s.io/klog/v2"
2525

2626
"k8s.io/node-problem-detector/pkg/custompluginmonitor/plugin"
2727
cpmtypes "k8s.io/node-problem-detector/pkg/custompluginmonitor/types"
@@ -59,25 +59,25 @@ func NewCustomPluginMonitorOrDie(configPath string) types.Monitor {
5959
}
6060
f, err := os.ReadFile(configPath)
6161
if err != nil {
62-
glog.Fatalf("Failed to read configuration file %q: %v", configPath, err)
62+
klog.Fatalf("Failed to read configuration file %q: %v", configPath, err)
6363
}
6464
err = json.Unmarshal(f, &c.config)
6565
if err != nil {
66-
glog.Fatalf("Failed to unmarshal configuration file %q: %v", configPath, err)
66+
klog.Fatalf("Failed to unmarshal configuration file %q: %v", configPath, err)
6767
}
6868
// Apply configurations
6969
err = (&c.config).ApplyConfiguration()
7070
if err != nil {
71-
glog.Fatalf("Failed to apply configuration for %q: %v", configPath, err)
71+
klog.Fatalf("Failed to apply configuration for %q: %v", configPath, err)
7272
}
7373

7474
// Validate configurations
7575
err = c.config.Validate()
7676
if err != nil {
77-
glog.Fatalf("Failed to validate custom plugin config %+v: %v", c.config, err)
77+
klog.Fatalf("Failed to validate custom plugin config %+v: %v", c.config, err)
7878
}
7979

80-
glog.Infof("Finish parsing custom plugin monitor config file %s: %+v", c.configPath, c.config)
80+
klog.Infof("Finish parsing custom plugin monitor config file %s: %+v", c.configPath, c.config)
8181

8282
c.plugin = plugin.NewPlugin(c.config)
8383
// A 1000 size channel should be big enough.
@@ -96,26 +96,26 @@ func initializeProblemMetricsOrDie(rules []*cpmtypes.CustomRule) {
9696
if rule.Type == types.Perm {
9797
err := problemmetrics.GlobalProblemMetricsManager.SetProblemGauge(rule.Condition, rule.Reason, false)
9898
if err != nil {
99-
glog.Fatalf("Failed to initialize problem gauge metrics for problem %q, reason %q: %v",
99+
klog.Fatalf("Failed to initialize problem gauge metrics for problem %q, reason %q: %v",
100100
rule.Condition, rule.Reason, err)
101101
}
102102
}
103103
err := problemmetrics.GlobalProblemMetricsManager.IncrementProblemCounter(rule.Reason, 0)
104104
if err != nil {
105-
glog.Fatalf("Failed to initialize problem counter metrics for %q: %v", rule.Reason, err)
105+
klog.Fatalf("Failed to initialize problem counter metrics for %q: %v", rule.Reason, err)
106106
}
107107
}
108108
}
109109

110110
func (c *customPluginMonitor) Start() (<-chan *types.Status, error) {
111-
glog.Infof("Start custom plugin monitor %s", c.configPath)
111+
klog.Infof("Start custom plugin monitor %s", c.configPath)
112112
go c.plugin.Run()
113113
go c.monitorLoop()
114114
return c.statusChan, nil
115115
}
116116

117117
func (c *customPluginMonitor) Stop() {
118-
glog.Infof("Stop custom plugin monitor %s", c.configPath)
118+
klog.Infof("Stop custom plugin monitor %s", c.configPath)
119119
c.tomb.Stop()
120120
}
121121

@@ -133,16 +133,16 @@ func (c *customPluginMonitor) monitorLoop() {
133133
select {
134134
case result, ok := <-resultChan:
135135
if !ok {
136-
glog.Errorf("Result channel closed: %s", c.configPath)
136+
klog.Errorf("Result channel closed: %s", c.configPath)
137137
return
138138
}
139-
glog.V(3).Infof("Receive new plugin result for %s: %+v", c.configPath, result)
139+
klog.V(3).Infof("Receive new plugin result for %s: %+v", c.configPath, result)
140140
status := c.generateStatus(result)
141-
glog.V(3).Infof("New status generated: %+v", status)
141+
klog.V(3).Infof("New status generated: %+v", status)
142142
c.statusChan <- status
143143
case <-c.tomb.Stopping():
144144
c.plugin.Stop()
145-
glog.Infof("Custom plugin monitor stopped: %s", c.configPath)
145+
klog.Infof("Custom plugin monitor stopped: %s", c.configPath)
146146
c.tomb.Done()
147147
return
148148
}
@@ -256,15 +256,15 @@ func (c *customPluginMonitor) generateStatus(result cpmtypes.Result) *types.Stat
256256
err := problemmetrics.GlobalProblemMetricsManager.IncrementProblemCounter(
257257
event.Reason, 1)
258258
if err != nil {
259-
glog.Errorf("Failed to update problem counter metrics for %q: %v",
259+
klog.Errorf("Failed to update problem counter metrics for %q: %v",
260260
event.Reason, err)
261261
}
262262
}
263263
for _, condition := range c.conditions {
264264
err := problemmetrics.GlobalProblemMetricsManager.SetProblemGauge(
265265
condition.Type, condition.Reason, condition.Status == types.True)
266266
if err != nil {
267-
glog.Errorf("Failed to update problem gauge metrics for problem %q, reason %q: %v",
267+
klog.Errorf("Failed to update problem gauge metrics for problem %q, reason %q: %v",
268268
condition.Type, condition.Reason, err)
269269
}
270270
}
@@ -277,7 +277,7 @@ func (c *customPluginMonitor) generateStatus(result cpmtypes.Result) *types.Stat
277277
}
278278
// Log only if condition has changed
279279
if len(activeProblemEvents) != 0 || len(inactiveProblemEvents) != 0 {
280-
glog.V(0).Infof("New status generated: %+v", status)
280+
klog.V(0).Infof("New status generated: %+v", status)
281281
}
282282
return status
283283
}
@@ -297,7 +297,7 @@ func toConditionStatus(s cpmtypes.Status) types.ConditionStatus {
297297
func (c *customPluginMonitor) initializeStatus() {
298298
// Initialize the default node conditions
299299
c.conditions = initialConditions(c.config.DefaultConditions)
300-
glog.Infof("Initialize condition generated: %+v", c.conditions)
300+
klog.Infof("Initialize condition generated: %+v", c.conditions)
301301
// Update the initial status
302302
c.statusChan <- &types.Status{
303303
Source: c.config.Source,

0 commit comments

Comments
 (0)