Skip to content

Commit

Permalink
Merge pull request kubernetes-csi#119 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 e487a0d + 4099aff commit aeae0f8
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 1,609 deletions.
10 changes: 1 addition & 9 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 @@ -8,9 +8,6 @@
name = "github.com/golang/protobuf"
version = "1.1.0"

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

[[constraint]]
name = "github.com/kubernetes-csi/csi-test"
Expand Down
10 changes: 5 additions & 5 deletions cmd/csi-attacher/leader.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"os"
"time"

"github.com/golang/glog"
"github.com/kubernetes-csi/external-attacher/pkg/controller"
"k8s.io/api/core/v1"
"k8s.io/client-go/kubernetes"
Expand All @@ -31,6 +30,7 @@ import (
"k8s.io/client-go/tools/leaderelection"
"k8s.io/client-go/tools/leaderelection/resourcelock"
"k8s.io/client-go/tools/record"
"k8s.io/klog"
)

const (
Expand All @@ -51,7 +51,7 @@ func runAsLeader(clientset *kubernetes.Clientset, namespace string, identity str
}
lock, err := resourcelock.New(resourcelock.ConfigMapsResourceLock, namespace, controller.SanitizeDriverName(lockName), clientset.CoreV1(), rlConfig)
if err != nil {
glog.Error(err)
klog.Error(err)
os.Exit(1)
}

Expand All @@ -62,14 +62,14 @@ func runAsLeader(clientset *kubernetes.Clientset, namespace string, identity str
RetryPeriod: retryPeriod,
Callbacks: leaderelection.LeaderCallbacks{
OnStartedLeading: func(ctx context.Context) {
glog.V(2).Info("Became leader, starting")
klog.V(2).Info("Became leader, starting")
startFunc(ctx)
},
OnStoppedLeading: func() {
glog.Fatal("Stopped leading")
klog.Fatal("Stopped leading")
},
OnNewLeader: func(identity string) {
glog.V(3).Infof("Current leader: %s", identity)
klog.V(3).Infof("Current leader: %s", identity)
},
},
}
Expand Down
37 changes: 19 additions & 18 deletions cmd/csi-attacher/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ import (
"os"
"time"

"github.com/golang/glog"
"k8s.io/client-go/informers"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
csiclient "k8s.io/csi-api/pkg/client/clientset/versioned"
csiinformers "k8s.io/csi-api/pkg/client/informers/externalversions"
"k8s.io/klog"

"github.com/kubernetes-csi/external-attacher/pkg/connection"
"github.com/kubernetes-csi/external-attacher/pkg/controller"
Expand Down Expand Up @@ -66,31 +66,32 @@ var (
)

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

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

// Create the client config. Use kubeconfig if given, otherwise assume in-cluster.
config, err := buildConfig(*kubeconfig)
if err != nil {
glog.Error(err.Error())
klog.Error(err.Error())
os.Exit(1)
}

clientset, err := kubernetes.NewForConfig(config)
if err != nil {
glog.Error(err.Error())
klog.Error(err.Error())
os.Exit(1)
}

csiClientset, err := csiclient.NewForConfig(config)
if err != nil {
glog.Error(err.Error())
klog.Error(err.Error())
os.Exit(1)
}

Expand All @@ -107,13 +108,13 @@ func main() {
// Connect to CSI.
csiConn, err := connection.New(*csiAddress, *connectionTimeout)
if err != nil {
glog.Error(err.Error())
klog.Error(err.Error())
os.Exit(1)
}

// Check it's ready
if err = waitForDriverReady(csiConn, *connectionTimeout); err != nil {
glog.Error(err.Error())
klog.Error(err.Error())
os.Exit(1)
}

Expand All @@ -122,24 +123,24 @@ func main() {
defer cancel()
attacher, 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", attacher)
klog.V(2).Infof("CSI driver name: %q", attacher)

supportsService, err := csiConn.SupportsPluginControllerService(ctx)
if err != nil {
glog.Error(err.Error())
klog.Error(err.Error())
os.Exit(1)
}
if !supportsService {
handler = controller.NewTrivialHandler(clientset)
glog.V(2).Infof("CSI driver does not support Plugin Controller Service, using trivial handler")
klog.V(2).Infof("CSI driver does not support Plugin Controller Service, using trivial handler")
} else {
// Find out if the driver supports attach/detach.
supportsAttach, supportsReadOnly, err := csiConn.SupportsControllerPublish(ctx)
if err != nil {
glog.Error(err.Error())
klog.Error(err.Error())
os.Exit(1)
}
if supportsAttach {
Expand All @@ -149,10 +150,10 @@ func main() {
csiFactory := csiinformers.NewSharedInformerFactory(csiClientset, *resync)
nodeInfoLister := csiFactory.Csi().V1alpha1().CSINodeInfos().Lister()
handler = controller.NewCSIHandler(clientset, csiClientset, attacher, csiConn, pvLister, nodeLister, nodeInfoLister, vaLister, timeout, supportsReadOnly)
glog.V(2).Infof("CSI driver supports ControllerPublishUnpublish, using real CSI handler")
klog.V(2).Infof("CSI driver supports ControllerPublishUnpublish, using real CSI handler")
} else {
handler = controller.NewTrivialHandler(clientset)
glog.V(2).Infof("CSI driver does not support ControllerPublishUnpublish, using trivial handler")
klog.V(2).Infof("CSI driver does not support ControllerPublishUnpublish, using trivial handler")
}
}
}
Expand All @@ -179,11 +180,11 @@ func main() {
} else {
// Leader election was requested.
if leaderElectionNamespace == nil || *leaderElectionNamespace == "" {
glog.Error("-leader-election-namespace must not be empty")
klog.Error("-leader-election-namespace must not be empty")
os.Exit(1)
}
if leaderElectionIdentity == nil || *leaderElectionIdentity == "" {
glog.Error("-leader-election-identity must not be empty")
klog.Error("-leader-election-identity must not be empty")
os.Exit(1)
}
// Name of config map with leader election lock
Expand All @@ -208,10 +209,10 @@ func waitForDriverReady(csiConn connection.CSIConnection, timeout time.Duration)
defer cancel()
err = csiConn.Probe(ctx)
if err == nil {
glog.V(2).Infof("Probe succeeded")
klog.V(2).Infof("Probe succeeded")
return nil
}
glog.V(2).Infof("Probe failed with %s", err)
klog.V(2).Infof("Probe failed with %s", err)

now := time.Now()
if now.After(finish) {
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 @@ -87,7 +87,7 @@ func New(address string, timeout time.Duration) (CSIConnection, error) {
}

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 @@ -107,14 +107,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 @@ -240,11 +240,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
24 changes: 12 additions & 12 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package controller
import (
"fmt"

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

"k8s.io/api/core/v1"
storage "k8s.io/api/storage/v1beta1"
Expand Down Expand Up @@ -110,11 +110,11 @@ func (ctrl *CSIAttachController) Run(workers int, stopCh <-chan struct{}) {
defer ctrl.vaQueue.ShutDown()
defer ctrl.pvQueue.ShutDown()

glog.Infof("Starting CSI attacher")
defer glog.Infof("Shutting CSI attacher")
klog.Infof("Starting CSI attacher")
defer klog.Infof("Shutting CSI attacher")

if !cache.WaitForCacheSync(stopCh, ctrl.vaListerSynced, ctrl.pvListerSynced) {
glog.Errorf("Cannot sync caches")
klog.Errorf("Cannot sync caches")
return
}
for i := 0; i < workers; i++ {
Expand All @@ -138,7 +138,7 @@ func (ctrl *CSIAttachController) vaUpdated(old, new interface{}) {
if shouldEnqueueVAChange(oldVA, newVA) {
ctrl.vaQueue.Add(newVA.Name)
} else {
glog.V(3).Infof("Ignoring VolumeAttachment %q change", newVA.Name)
klog.V(3).Infof("Ignoring VolumeAttachment %q change", newVA.Name)
}
}

Expand Down Expand Up @@ -172,22 +172,22 @@ func (ctrl *CSIAttachController) syncVA() {
defer ctrl.vaQueue.Done(key)

vaName := key.(string)
glog.V(4).Infof("Started VA processing %q", vaName)
klog.V(4).Infof("Started VA processing %q", vaName)

// get VolumeAttachment to process
va, err := ctrl.vaLister.Get(vaName)
if err != nil {
if apierrs.IsNotFound(err) {
// VolumeAttachment was deleted in the meantime, ignore.
glog.V(3).Infof("VA %q deleted, ignoring", vaName)
klog.V(3).Infof("VA %q deleted, ignoring", vaName)
return
}
glog.Errorf("Error getting VolumeAttachment %q: %v", vaName, err)
klog.Errorf("Error getting VolumeAttachment %q: %v", vaName, err)
ctrl.vaQueue.AddRateLimited(vaName)
return
}
if va.Spec.Attacher != ctrl.attacherName {
glog.V(4).Infof("Skipping VolumeAttachment %s for attacher %s", va.Name, va.Spec.Attacher)
klog.V(4).Infof("Skipping VolumeAttachment %s for attacher %s", va.Name, va.Spec.Attacher)
return
}
ctrl.handler.SyncNewOrUpdatedVolumeAttachment(va)
Expand All @@ -202,17 +202,17 @@ func (ctrl *CSIAttachController) syncPV() {
defer ctrl.pvQueue.Done(key)

pvName := key.(string)
glog.V(4).Infof("Started PV processing %q", pvName)
klog.V(4).Infof("Started PV processing %q", pvName)

// get PV to process
pv, err := ctrl.pvLister.Get(pvName)
if err != nil {
if apierrs.IsNotFound(err) {
// PV was deleted in the meantime, ignore.
glog.V(3).Infof("PV %q deleted, ignoring", pvName)
klog.V(3).Infof("PV %q deleted, ignoring", pvName)
return
}
glog.Errorf("Error getting PersistentVolume %q: %v", pvName, err)
klog.Errorf("Error getting PersistentVolume %q: %v", pvName, err)
ctrl.pvQueue.AddRateLimited(pvName)
return
}
Expand Down
Loading

0 comments on commit aeae0f8

Please sign in to comment.