Skip to content

Commit

Permalink
Migrate to k8s.io/klog from glog.
Browse files Browse the repository at this point in the history
Signed-off-by: Humble Chirammal <[email protected]>
  • Loading branch information
humblec committed Mar 18, 2019
1 parent 311f929 commit 0a0d830
Show file tree
Hide file tree
Showing 6 changed files with 201 additions and 200 deletions.
39 changes: 20 additions & 19 deletions cmd/csi-snapshotter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ import (
"os/signal"
"time"

"github.com/golang/glog"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/klog"

"github.com/kubernetes-csi/external-snapshotter/pkg/connection"
"github.com/kubernetes-csi/external-snapshotter/pkg/controller"
Expand Down Expand Up @@ -67,38 +67,39 @@ var (
)

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

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

if *connectionTimeout != 0 {
glog.Warning("--connection-timeout is deprecated and will have no effect")
klog.Warning("--connection-timeout is deprecated and will have no effect")
}
if *snapshotter != "" {
glog.Warning("--snapshotter is deprecated and will have no effect")
klog.Warning("--snapshotter is deprecated and will have no effect")
}

// 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)
}

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

snapClient, err := clientset.NewForConfig(config)
if err != nil {
glog.Errorf("Error building snapshot clientset: %s", err.Error())
klog.Errorf("Error building snapshot clientset: %s", err.Error())
os.Exit(1)
}

Expand All @@ -108,14 +109,14 @@ func main() {
// Create CRD resource
aeclientset, err := apiextensionsclient.NewForConfig(config)
if err != nil {
glog.Error(err.Error())
klog.Error(err.Error())
os.Exit(1)
}

// initialize CRD resource if it does not exist
err = CreateCRD(aeclientset)
if err != nil {
glog.Error(err.Error())
klog.Error(err.Error())
os.Exit(1)
}

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

Expand All @@ -136,34 +137,34 @@ func main() {
// Find driver name
*snapshotter, 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", *snapshotter)
klog.V(2).Infof("CSI driver name: %q", *snapshotter)

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

// Find out if the driver supports create/delete snapshot.
supportsCreateSnapshot, err := csiConn.SupportsControllerCreateSnapshot(ctx)
if err != nil {
glog.Error(err.Error())
klog.Error(err.Error())
os.Exit(1)
}
if !supportsCreateSnapshot {
glog.Errorf("CSI driver %s does not support ControllerCreateSnapshot", *snapshotter)
klog.Errorf("CSI driver %s does not support ControllerCreateSnapshot", *snapshotter)
os.Exit(1)
}

if len(*snapshotNamePrefix) == 0 {
glog.Error("Snapshot name prefix cannot be of length 0")
klog.Error("Snapshot name prefix cannot be of length 0")
os.Exit(1)
}

glog.V(2).Infof("Start NewCSISnapshotController with snapshotter [%s] kubeconfig [%s] connectionTimeout [%+v] csiAddress [%s] createSnapshotContentRetryCount [%d] createSnapshotContentInterval [%+v] resyncPeriod [%+v] snapshotNamePrefix [%s] snapshotNameUUIDLength [%d]", *snapshotter, *kubeconfig, *connectionTimeout, *csiAddress, createSnapshotContentRetryCount, *createSnapshotContentInterval, *resyncPeriod, *snapshotNamePrefix, snapshotNameUUIDLength)
klog.V(2).Infof("Start NewCSISnapshotController with snapshotter [%s] kubeconfig [%s] connectionTimeout [%+v] csiAddress [%s] createSnapshotContentRetryCount [%d] createSnapshotContentInterval [%+v] resyncPeriod [%+v] snapshotNamePrefix [%s] snapshotNameUUIDLength [%d]", *snapshotter, *kubeconfig, *connectionTimeout, *csiAddress, createSnapshotContentRetryCount, *createSnapshotContentInterval, *resyncPeriod, *snapshotNamePrefix, snapshotNameUUIDLength)

ctrl := controller.NewCSISnapshotController(
snapClient,
Expand Down Expand Up @@ -211,10 +212,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
14 changes: 7 additions & 7 deletions pkg/connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ import (
"fmt"

"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/golang/glog"
"github.com/golang/protobuf/ptypes"
"github.com/golang/protobuf/ptypes/timestamp"
"github.com/kubernetes-csi/csi-lib-utils/connection"
"github.com/kubernetes-csi/csi-lib-utils/protosanitizer"
"google.golang.org/grpc"
"k8s.io/api/core/v1"
"k8s.io/klog"
)

// CSIConnection is gRPC connection to a remote CSI driver and abstracts all
Expand Down Expand Up @@ -157,7 +157,7 @@ func (c *csiConnection) SupportsControllerListSnapshots(ctx context.Context) (bo
}

func (c *csiConnection) CreateSnapshot(ctx context.Context, snapshotName string, volume *v1.PersistentVolume, parameters map[string]string, snapshotterCredentials map[string]string) (string, string, int64, int64, bool, error) {
glog.V(5).Infof("CSI CreateSnapshot: %s", snapshotName)
klog.V(5).Infof("CSI CreateSnapshot: %s", snapshotName)
if volume.Spec.CSI == nil {
return "", "", 0, 0, false, fmt.Errorf("CSIPersistentVolumeSource not defined in spec")
}
Expand All @@ -181,7 +181,7 @@ func (c *csiConnection) CreateSnapshot(ctx context.Context, snapshotName string,
return "", "", 0, 0, false, err
}

glog.V(5).Infof("CSI CreateSnapshot: %s driver name [%s] snapshot ID [%s] time stamp [%d] size [%d] readyToUse [%v]", snapshotName, driverName, rsp.Snapshot.SnapshotId, rsp.Snapshot.CreationTime, rsp.Snapshot.SizeBytes, rsp.Snapshot.ReadyToUse)
klog.V(5).Infof("CSI CreateSnapshot: %s driver name [%s] snapshot ID [%s] time stamp [%d] size [%d] readyToUse [%v]", snapshotName, driverName, rsp.Snapshot.SnapshotId, rsp.Snapshot.CreationTime, rsp.Snapshot.SizeBytes, rsp.Snapshot.ReadyToUse)
creationTime, err := timestampToUnixTime(rsp.Snapshot.CreationTime)
if err != nil {
return "", "", 0, 0, false, err
Expand Down Expand Up @@ -232,11 +232,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
56 changes: 28 additions & 28 deletions pkg/controller/framework_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"testing"
"time"

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

crdv1 "github.com/kubernetes-csi/external-snapshotter/pkg/apis/volumesnapshot/v1alpha1"
clientset "github.com/kubernetes-csi/external-snapshotter/pkg/client/clientset/versioned"
Expand Down Expand Up @@ -191,7 +191,7 @@ func (r *snapshotReactor) React(action core.Action) (handled bool, ret runtime.O
r.lock.Lock()
defer r.lock.Unlock()

glog.V(4).Infof("reactor got operation %q on %q", action.GetVerb(), action.GetResource())
klog.V(4).Infof("reactor got operation %q on %q", action.GetVerb(), action.GetResource())

// Inject error when requested
err = r.injectReactError(action)
Expand All @@ -215,7 +215,7 @@ func (r *snapshotReactor) React(action core.Action) (handled bool, ret runtime.O
r.contents[content.Name] = content
r.changedObjects = append(r.changedObjects, content)
r.changedSinceLastSync++
glog.V(5).Infof("created content %s", content.Name)
klog.V(5).Infof("created content %s", content.Name)
return true, content, nil

case action.Matches("update", "volumesnapshotcontents"):
Expand All @@ -241,7 +241,7 @@ func (r *snapshotReactor) React(action core.Action) (handled bool, ret runtime.O
r.contents[content.Name] = content
r.changedObjects = append(r.changedObjects, content)
r.changedSinceLastSync++
glog.V(4).Infof("saved updated content %s", content.Name)
klog.V(4).Infof("saved updated content %s", content.Name)
return true, content, nil

case action.Matches("update", "volumesnapshots"):
Expand All @@ -267,32 +267,32 @@ func (r *snapshotReactor) React(action core.Action) (handled bool, ret runtime.O
r.snapshots[snapshot.Name] = snapshot
r.changedObjects = append(r.changedObjects, snapshot)
r.changedSinceLastSync++
glog.V(4).Infof("saved updated snapshot %s", snapshot.Name)
klog.V(4).Infof("saved updated snapshot %s", snapshot.Name)
return true, snapshot, nil

case action.Matches("get", "volumesnapshotcontents"):
name := action.(core.GetAction).GetName()
content, found := r.contents[name]
if found {
glog.V(4).Infof("GetVolume: found %s", content.Name)
klog.V(4).Infof("GetVolume: found %s", content.Name)
return true, content, nil
}
glog.V(4).Infof("GetVolume: content %s not found", name)
klog.V(4).Infof("GetVolume: content %s not found", name)
return true, nil, fmt.Errorf("cannot find content %s", name)

case action.Matches("get", "volumesnapshots"):
name := action.(core.GetAction).GetName()
snapshot, found := r.snapshots[name]
if found {
glog.V(4).Infof("GetSnapshot: found %s", snapshot.Name)
klog.V(4).Infof("GetSnapshot: found %s", snapshot.Name)
return true, snapshot, nil
}
glog.V(4).Infof("GetSnapshot: content %s not found", name)
klog.V(4).Infof("GetSnapshot: content %s not found", name)
return true, nil, fmt.Errorf("cannot find snapshot %s", name)

case action.Matches("delete", "volumesnapshotcontents"):
name := action.(core.DeleteAction).GetName()
glog.V(4).Infof("deleted content %s", name)
klog.V(4).Infof("deleted content %s", name)
_, found := r.contents[name]
if found {
delete(r.contents, name)
Expand All @@ -303,7 +303,7 @@ func (r *snapshotReactor) React(action core.Action) (handled bool, ret runtime.O

case action.Matches("delete", "volumesnapshots"):
name := action.(core.DeleteAction).GetName()
glog.V(4).Infof("deleted snapshot %s", name)
klog.V(4).Infof("deleted snapshot %s", name)
_, found := r.contents[name]
if found {
delete(r.snapshots, name)
Expand All @@ -316,40 +316,40 @@ func (r *snapshotReactor) React(action core.Action) (handled bool, ret runtime.O
name := action.(core.GetAction).GetName()
volume, found := r.volumes[name]
if found {
glog.V(4).Infof("GetVolume: found %s", volume.Name)
klog.V(4).Infof("GetVolume: found %s", volume.Name)
return true, volume, nil
}
glog.V(4).Infof("GetVolume: volume %s not found", name)
klog.V(4).Infof("GetVolume: volume %s not found", name)
return true, nil, fmt.Errorf("cannot find volume %s", name)

case action.Matches("get", "persistentvolumeclaims"):
name := action.(core.GetAction).GetName()
claim, found := r.claims[name]
if found {
glog.V(4).Infof("GetClaim: found %s", claim.Name)
klog.V(4).Infof("GetClaim: found %s", claim.Name)
return true, claim, nil
}
glog.V(4).Infof("GetClaim: claim %s not found", name)
klog.V(4).Infof("GetClaim: claim %s not found", name)
return true, nil, fmt.Errorf("cannot find claim %s", name)

case action.Matches("get", "storageclasses"):
name := action.(core.GetAction).GetName()
storageClass, found := r.storageClasses[name]
if found {
glog.V(4).Infof("GetStorageClass: found %s", storageClass.Name)
klog.V(4).Infof("GetStorageClass: found %s", storageClass.Name)
return true, storageClass, nil
}
glog.V(4).Infof("GetStorageClass: storageClass %s not found", name)
klog.V(4).Infof("GetStorageClass: storageClass %s not found", name)
return true, nil, fmt.Errorf("cannot find storageClass %s", name)

case action.Matches("get", "secrets"):
name := action.(core.GetAction).GetName()
secret, found := r.secrets[name]
if found {
glog.V(4).Infof("GetSecret: found %s", secret.Name)
klog.V(4).Infof("GetSecret: found %s", secret.Name)
return true, secret, nil
}
glog.V(4).Infof("GetSecret: secret %s not found", name)
klog.V(4).Infof("GetSecret: secret %s not found", name)
return true, nil, fmt.Errorf("cannot find secret %s", name)

}
Expand All @@ -366,11 +366,11 @@ func (r *snapshotReactor) injectReactError(action core.Action) error {
}

for i, expected := range r.errors {
glog.V(4).Infof("trying to match %q %q with %q %q", expected.verb, expected.resource, action.GetVerb(), action.GetResource())
klog.V(4).Infof("trying to match %q %q with %q %q", expected.verb, expected.resource, action.GetVerb(), action.GetResource())
if action.Matches(expected.verb, expected.resource) {
// That's the action we're waiting for, remove it from injectedErrors
r.errors = append(r.errors[:i], r.errors[i+1:]...)
glog.V(4).Infof("reactor found matching error at index %d: %q %q, returning %v", i, expected.verb, expected.resource, expected.error)
klog.V(4).Infof("reactor found matching error at index %d: %q %q, returning %v", i, expected.verb, expected.resource, expected.error)
return expected.error
}
}
Expand Down Expand Up @@ -477,14 +477,14 @@ func checkEvents(t *testing.T, expectedEvents []string, ctrl *csiSnapshotControl
select {
case event, ok := <-fakeRecorder.Events:
if ok {
glog.V(5).Infof("event recorder got event %s", event)
klog.V(5).Infof("event recorder got event %s", event)
gotEvents = append(gotEvents, event)
} else {
glog.V(5).Infof("event recorder finished")
klog.V(5).Infof("event recorder finished")
finished = true
}
case _, _ = <-timer.C:
glog.V(5).Infof("event recorder timeout")
klog.V(5).Infof("event recorder timeout")
finished = true
}
}
Expand Down Expand Up @@ -524,10 +524,10 @@ func (r *snapshotReactor) popChange() interface{} {
switch obj.(type) {
case *crdv1.VolumeSnapshotContent:
vol, _ := obj.(*crdv1.VolumeSnapshotContent)
glog.V(4).Infof("reactor queue: %s", vol.Name)
klog.V(4).Infof("reactor queue: %s", vol.Name)
case *crdv1.VolumeSnapshot:
snapshot, _ := obj.(*crdv1.VolumeSnapshot)
glog.V(4).Infof("reactor queue: %s", snapshot.Name)
klog.V(4).Infof("reactor queue: %s", snapshot.Name)
}
}

Expand Down Expand Up @@ -981,7 +981,7 @@ func wrapTestWithInjectedOperation(toWrap testCall, injectBeforeOperation func(c

return func(ctrl *csiSnapshotController, reactor *snapshotReactor, test controllerTest) error {
// Inject a hook before async operation starts
glog.V(4).Infof("reactor:injecting call")
klog.V(4).Infof("reactor:injecting call")
injectBeforeOperation(ctrl, reactor)

// Run the tested function (typically syncSnapshot/syncContent) in a
Expand Down Expand Up @@ -1028,7 +1028,7 @@ func evaluateTestResults(ctrl *csiSnapshotController, reactor *snapshotReactor,
func runSyncTests(t *testing.T, tests []controllerTest, snapshotClasses []*crdv1.VolumeSnapshotClass) {
snapshotscheme.AddToScheme(scheme.Scheme)
for _, test := range tests {
glog.V(4).Infof("starting test %q", test.name)
klog.V(4).Infof("starting test %q", test.name)

// Initialize the controller
kubeClient := &kubefake.Clientset{}
Expand Down
Loading

0 comments on commit 0a0d830

Please sign in to comment.