Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to k8s.io/klog from glog #36

Merged
merged 1 commit into from
Feb 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 42 additions & 12 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@
name = "github.com/container-storage-interface/spec"
version = "1.0.0-rc2"

[[constraint]]
branch = "master"
name = "github.com/golang/glog"

[[constraint]]
branch = "master"
name = "github.com/kubernetes-csi/csi-test"
Expand Down
23 changes: 12 additions & 11 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"net/http"
"time"

"github.com/golang/glog"
"k8s.io/klog"

"github.com/kubernetes-csi/livenessprobe/pkg/connection"
)
Expand All @@ -43,32 +43,32 @@ var (

func runProbe(ctx context.Context, csiConn connection.CSIConnection) error {
// Get CSI driver name.
glog.Infof("Calling CSI driver to discover driver name.")
klog.Infof("Calling CSI driver to discover driver name.")
csiDriverName, err := csiConn.GetDriverName(ctx)
if err != nil {
return err
}
glog.Infof("CSI driver name: %q", csiDriverName)
klog.Infof("CSI driver name: %q", csiDriverName)
// Sending Probe request
glog.Infof("Sending probe request to CSI driver.")
klog.Infof("Sending probe request to CSI driver.")
err = csiConn.LivenessProbe(ctx)
return err
}

func getCSIConnection() (connection.CSIConnection, error) {
// Connect to CSI.
glog.Infof("Attempting to open a gRPC connection with: %s", *csiAddress)
klog.Infof("Attempting to open a gRPC connection with: %s", *csiAddress)
csiConn, err := connection.NewConnection(*csiAddress, *connectionTimeout)
return csiConn, err
}

func checkHealth(w http.ResponseWriter, req *http.Request) {
glog.Infof("Request: %s from: %s\n", req.URL.Path, req.RemoteAddr)
klog.Infof("Request: %s from: %s\n", req.URL.Path, req.RemoteAddr)
csiConn, err := getCSIConnection()
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
glog.Errorf("Failed to get connection to CSI with error: %v.", err)
klog.Errorf("Failed to get connection to CSI with error: %v.", err)
return
}
defer csiConn.Close()
Expand All @@ -77,23 +77,24 @@ func checkHealth(w http.ResponseWriter, req *http.Request) {
if err := runProbe(ctx, csiConn); err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
glog.Errorf("Health check failed with: %v.", err)
klog.Errorf("Health check failed with: %v.", err)
} else {
w.WriteHeader(http.StatusOK)
w.Write([]byte(`ok`))
glog.Infof("Health check succeeded.")
klog.Infof("Health check succeeded.")
}
}

func main() {
klog.InitFlags(nil)
flag.Set("logtostderr", "true")
flag.Parse()

addr := net.JoinHostPort("0.0.0.0", *healthzPort)
http.HandleFunc("/healthz", checkHealth)
glog.Infof("Serving requests to /healthz on: %s", addr)
klog.Infof("Serving requests to /healthz on: %s", addr)
err := http.ListenAndServe(addr, nil)
if err != nil {
glog.Fatalf("failed to start http server with error: %v", err)
klog.Fatalf("failed to start http server with error: %v", err)
}
}
18 changes: 9 additions & 9 deletions pkg/connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import (
"time"

"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/golang/glog"
"github.com/kubernetes-csi/csi-lib-utils/protosanitizer"
"google.golang.org/grpc"
"google.golang.org/grpc/connectivity"
"k8s.io/klog"
)

// CSIConnection is gRPC connection to a remote CSI driver and abstracts all
Expand Down Expand Up @@ -65,7 +65,7 @@ func NewConnection(
}

func connect(address string, timeout time.Duration) (*grpc.ClientConn, error) {
glog.Infof("Connecting to %s", address)
klog.Infof("Connecting to %s", address)
dialOptions := []grpc.DialOption{
grpc.WithInsecure(),
grpc.WithBackoffMaxDelay(time.Second),
Expand All @@ -85,14 +85,14 @@ func connect(address string, timeout time.Duration) (*grpc.ClientConn, error) {
defer cancel()
for {
if !conn.WaitForStateChange(ctx, conn.GetState()) {
glog.Infof("Connection timed out")
klog.Infof("Connection timed out")
return conn, nil // return nil, subsequent GetPluginInfo will show the real connection error
}
if conn.GetState() == connectivity.Ready {
glog.Infof("Connected")
klog.Infof("Connected")
return conn, nil
}
glog.Infof("Still trying, connection is %s", conn.GetState())
klog.Infof("Still trying, connection is %s", conn.GetState())
}
}

Expand Down Expand Up @@ -126,10 +126,10 @@ func (c *csiConnection) Close() error {
}

func logGRPC(ctx context.Context, method string, req, reply interface{}, cc *grpc.ClientConn, invoker grpc.UnaryInvoker, opts ...grpc.CallOption) error {
glog.Infof("GRPC call: %s", method)
glog.Infof("GRPC request: %s", protosanitizer.StripSecrets(req))
klog.Infof("GRPC call: %s", method)
klog.Infof("GRPC request: %s", protosanitizer.StripSecrets(req))
err := invoker(ctx, method, req, reply, cc, opts...)
glog.Infof("GRPC response: %s", protosanitizer.StripSecrets(reply))
glog.Infof("GRPC error: %v", err)
klog.Infof("GRPC response: %s", protosanitizer.StripSecrets(reply))
klog.Infof("GRPC error: %v", err)
return err
}
Loading