Skip to content

Commit bd1de93

Browse files
authored
Merge pull request #36 from humblec/klog
Migrate to k8s.io/klog from glog
2 parents 6fd6b65 + c24c115 commit bd1de93

File tree

7 files changed

+146
-58
lines changed

7 files changed

+146
-58
lines changed

Gopkg.lock

Lines changed: 42 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@
2525
name = "github.com/container-storage-interface/spec"
2626
version = "1.0.0-rc2"
2727

28-
[[constraint]]
29-
branch = "master"
30-
name = "github.com/golang/glog"
31-
3228
[[constraint]]
3329
branch = "master"
3430
name = "github.com/kubernetes-csi/csi-test"

cmd/main.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
"net/http"
2424
"time"
2525

26-
"github.com/golang/glog"
26+
"k8s.io/klog"
2727

2828
"github.com/kubernetes-csi/livenessprobe/pkg/connection"
2929
)
@@ -43,32 +43,32 @@ var (
4343

4444
func runProbe(ctx context.Context, csiConn connection.CSIConnection) error {
4545
// Get CSI driver name.
46-
glog.Infof("Calling CSI driver to discover driver name.")
46+
klog.Infof("Calling CSI driver to discover driver name.")
4747
csiDriverName, err := csiConn.GetDriverName(ctx)
4848
if err != nil {
4949
return err
5050
}
51-
glog.Infof("CSI driver name: %q", csiDriverName)
51+
klog.Infof("CSI driver name: %q", csiDriverName)
5252
// Sending Probe request
53-
glog.Infof("Sending probe request to CSI driver.")
53+
klog.Infof("Sending probe request to CSI driver.")
5454
err = csiConn.LivenessProbe(ctx)
5555
return err
5656
}
5757

5858
func getCSIConnection() (connection.CSIConnection, error) {
5959
// Connect to CSI.
60-
glog.Infof("Attempting to open a gRPC connection with: %s", *csiAddress)
60+
klog.Infof("Attempting to open a gRPC connection with: %s", *csiAddress)
6161
csiConn, err := connection.NewConnection(*csiAddress, *connectionTimeout)
6262
return csiConn, err
6363
}
6464

6565
func checkHealth(w http.ResponseWriter, req *http.Request) {
66-
glog.Infof("Request: %s from: %s\n", req.URL.Path, req.RemoteAddr)
66+
klog.Infof("Request: %s from: %s\n", req.URL.Path, req.RemoteAddr)
6767
csiConn, err := getCSIConnection()
6868
if err != nil {
6969
w.WriteHeader(http.StatusInternalServerError)
7070
w.Write([]byte(err.Error()))
71-
glog.Errorf("Failed to get connection to CSI with error: %v.", err)
71+
klog.Errorf("Failed to get connection to CSI with error: %v.", err)
7272
return
7373
}
7474
defer csiConn.Close()
@@ -77,23 +77,24 @@ func checkHealth(w http.ResponseWriter, req *http.Request) {
7777
if err := runProbe(ctx, csiConn); err != nil {
7878
w.WriteHeader(http.StatusInternalServerError)
7979
w.Write([]byte(err.Error()))
80-
glog.Errorf("Health check failed with: %v.", err)
80+
klog.Errorf("Health check failed with: %v.", err)
8181
} else {
8282
w.WriteHeader(http.StatusOK)
8383
w.Write([]byte(`ok`))
84-
glog.Infof("Health check succeeded.")
84+
klog.Infof("Health check succeeded.")
8585
}
8686
}
8787

8888
func main() {
89+
klog.InitFlags(nil)
8990
flag.Set("logtostderr", "true")
9091
flag.Parse()
9192

9293
addr := net.JoinHostPort("0.0.0.0", *healthzPort)
9394
http.HandleFunc("/healthz", checkHealth)
94-
glog.Infof("Serving requests to /healthz on: %s", addr)
95+
klog.Infof("Serving requests to /healthz on: %s", addr)
9596
err := http.ListenAndServe(addr, nil)
9697
if err != nil {
97-
glog.Fatalf("failed to start http server with error: %v", err)
98+
klog.Fatalf("failed to start http server with error: %v", err)
9899
}
99100
}

pkg/connection/connection.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ import (
2424
"time"
2525

2626
"github.com/container-storage-interface/spec/lib/go/csi"
27-
"github.com/golang/glog"
2827
"github.com/kubernetes-csi/csi-lib-utils/protosanitizer"
2928
"google.golang.org/grpc"
3029
"google.golang.org/grpc/connectivity"
30+
"k8s.io/klog"
3131
)
3232

3333
// CSIConnection is gRPC connection to a remote CSI driver and abstracts all
@@ -65,7 +65,7 @@ func NewConnection(
6565
}
6666

6767
func connect(address string, timeout time.Duration) (*grpc.ClientConn, error) {
68-
glog.Infof("Connecting to %s", address)
68+
klog.Infof("Connecting to %s", address)
6969
dialOptions := []grpc.DialOption{
7070
grpc.WithInsecure(),
7171
grpc.WithBackoffMaxDelay(time.Second),
@@ -85,14 +85,14 @@ func connect(address string, timeout time.Duration) (*grpc.ClientConn, error) {
8585
defer cancel()
8686
for {
8787
if !conn.WaitForStateChange(ctx, conn.GetState()) {
88-
glog.Infof("Connection timed out")
88+
klog.Infof("Connection timed out")
8989
return conn, nil // return nil, subsequent GetPluginInfo will show the real connection error
9090
}
9191
if conn.GetState() == connectivity.Ready {
92-
glog.Infof("Connected")
92+
klog.Infof("Connected")
9393
return conn, nil
9494
}
95-
glog.Infof("Still trying, connection is %s", conn.GetState())
95+
klog.Infof("Still trying, connection is %s", conn.GetState())
9696
}
9797
}
9898

@@ -126,10 +126,10 @@ func (c *csiConnection) Close() error {
126126
}
127127

128128
func logGRPC(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
129-
glog.Infof("GRPC call: %s", method)
130-
glog.Infof("GRPC request: %s", protosanitizer.StripSecrets(req))
129+
klog.Infof("GRPC call: %s", method)
130+
klog.Infof("GRPC request: %s", protosanitizer.StripSecrets(req))
131131
err := invoker(ctx, method, req, reply, cc, opts...)
132-
glog.Infof("GRPC response: %s", protosanitizer.StripSecrets(reply))
133-
glog.Infof("GRPC error: %v", err)
132+
klog.Infof("GRPC response: %s", protosanitizer.StripSecrets(reply))
133+
klog.Infof("GRPC error: %v", err)
134134
return err
135135
}

0 commit comments

Comments
 (0)