Skip to content

Commit

Permalink
Merge pull request #24 from humblec/klog
Browse files Browse the repository at this point in the history
Migrate to k8s.io/klog from glog.
  • Loading branch information
k8s-ci-robot authored Feb 7, 2019
2 parents a50f9cb + cd23fcc commit db1a662
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 65 deletions.
64 changes: 51 additions & 13 deletions Gopkg.lock

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

3 changes: 0 additions & 3 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
name = "github.com/kubernetes-csi/csi-test"
version = "v1.0.0-1"

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

[[override]]
name = "github.com/json-iterator/go"
Expand Down
23 changes: 12 additions & 11 deletions cmd/csi-node-driver-registrar/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"os"
"time"

"github.com/golang/glog"
"k8s.io/klog"
registerapi "k8s.io/kubernetes/pkg/kubelet/apis/pluginregistration/v1alpha1"

"github.com/kubernetes-csi/node-driver-registrar/pkg/connection"
Expand Down Expand Up @@ -73,7 +73,7 @@ func newRegistrationServer(driverName string, endpoint string, versions []string

// GetInfo is the RPC invoked by plugin watcher
func (e registrationServer) GetInfo(ctx context.Context, req *registerapi.InfoRequest) (*registerapi.PluginInfo, error) {
glog.Infof("Received GetInfo call: %+v", req)
klog.Infof("Received GetInfo call: %+v", req)
return &registerapi.PluginInfo{
Type: registerapi.CSIPlugin,
Name: e.driverName,
Expand All @@ -83,52 +83,53 @@ func (e registrationServer) GetInfo(ctx context.Context, req *registerapi.InfoRe
}

func (e registrationServer) NotifyRegistrationStatus(ctx context.Context, status *registerapi.RegistrationStatus) (*registerapi.RegistrationStatusResponse, error) {
glog.Infof("Received NotifyRegistrationStatus call: %+v", status)
klog.Infof("Received NotifyRegistrationStatus call: %+v", status)
if !status.PluginRegistered {
glog.Errorf("Registration process failed with error: %+v, restarting registration container.", status.Error)
klog.Errorf("Registration process failed with error: %+v, restarting registration container.", status.Error)
os.Exit(1)
}

return &registerapi.RegistrationStatusResponse{}, nil
}

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

if *kubeletRegistrationPath == "" {
glog.Error("kubelet-registration-path is a required parameter")
klog.Error("kubelet-registration-path is a required parameter")
os.Exit(1)
}

if *showVersion {
fmt.Println(os.Args[0], version)
return
}
glog.Infof("Version: %s", version)
klog.Infof("Version: %s", version)

// Once https://github.com/container-storage-interface/spec/issues/159 is
// resolved, if plugin does not support PUBLISH_UNPUBLISH_VOLUME, then we
// can skip adding mapping to "csi.volume.kubernetes.io/nodeid" annotation.

// Connect to CSI.
glog.V(1).Infof("Attempting to open a gRPC connection with: %q", *csiAddress)
klog.V(1).Infof("Attempting to open a gRPC connection with: %q", *csiAddress)
csiConn, err := connection.NewConnection(*csiAddress, *connectionTimeout)
if err != nil {
glog.Error(err.Error())
klog.Error(err.Error())
os.Exit(1)
}

// Get CSI driver name.
glog.V(1).Infof("Calling CSI driver to discover driver name.")
klog.V(1).Infof("Calling CSI driver to discover driver name.")
ctx, cancel := context.WithTimeout(context.Background(), csiTimeout)
defer cancel()
csiDriverName, err := csiConn.GetDriverName(ctx)
if err != nil {
glog.Error(err.Error())
klog.Error(err.Error())
os.Exit(1)
}
glog.V(2).Infof("CSI driver name: %q", csiDriverName)
klog.V(2).Infof("CSI driver name: %q", csiDriverName)

// Run forever
nodeRegister(csiDriverName)
Expand Down
14 changes: 7 additions & 7 deletions cmd/csi-node-driver-registrar/node_register.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (

"google.golang.org/grpc"

"github.com/golang/glog"
"golang.org/x/sys/unix"
"k8s.io/klog"
registerapi "k8s.io/kubernetes/pkg/kubelet/apis/pluginregistration/v1alpha1"
)

Expand All @@ -40,32 +40,32 @@ func nodeRegister(
if err == nil && (fi.Mode()&os.ModeSocket) != 0 {
// Remove any socket, stale or not, but fall through for other files
if err := os.Remove(socketPath); err != nil {
glog.Errorf("failed to remove stale socket %s with error: %+v", socketPath, err)
klog.Errorf("failed to remove stale socket %s with error: %+v", socketPath, err)
os.Exit(1)
}
}
if err != nil && !os.IsNotExist(err) {
glog.Errorf("failed to stat the socket %s with error: %+v", socketPath, err)
klog.Errorf("failed to stat the socket %s with error: %+v", socketPath, err)
os.Exit(1)
}
// Default to only user accessible socket, caller can open up later if desired
oldmask := unix.Umask(0077)

glog.Infof("Starting Registration Server at: %s\n", socketPath)
klog.Infof("Starting Registration Server at: %s\n", socketPath)
lis, err := net.Listen("unix", socketPath)
if err != nil {
glog.Errorf("failed to listen on socket: %s with error: %+v", socketPath, err)
klog.Errorf("failed to listen on socket: %s with error: %+v", socketPath, err)
os.Exit(1)
}
unix.Umask(oldmask)
glog.Infof("Registration Server started at: %s\n", socketPath)
klog.Infof("Registration Server started at: %s\n", socketPath)
grpcServer := grpc.NewServer()
// Registers kubelet plugin watcher api.
registerapi.RegisterRegistrationServer(grpcServer, registrar)

// Starts service
if err := grpcServer.Serve(lis); err != nil {
glog.Errorf("Registration Server stopped serving: %v", err)
klog.Errorf("Registration Server stopped serving: %v", err)
os.Exit(1)
}
// If gRPC server is gracefully shutdown, exit
Expand Down
18 changes: 9 additions & 9 deletions pkg/connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ 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/codes"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/status"
"k8s.io/klog"
)

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

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

Expand Down Expand Up @@ -135,11 +135,11 @@ 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.V(5).Infof("GRPC call: %s", method)
glog.V(5).Infof("GRPC request: %s", protosanitizer.StripSecrets(req))
klog.V(5).Infof("GRPC call: %s", method)
klog.V(5).Infof("GRPC request: %s", protosanitizer.StripSecrets(req))
err := invoker(ctx, method, req, reply, cc, opts...)
glog.V(5).Infof("GRPC response: %s", protosanitizer.StripSecrets(reply))
glog.V(5).Infof("GRPC error: %v", err)
klog.V(5).Infof("GRPC response: %s", protosanitizer.StripSecrets(reply))
klog.V(5).Infof("GRPC error: %v", err)
return err
}

Expand Down
File renamed without changes.
Loading

0 comments on commit db1a662

Please sign in to comment.