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 <hchiramm@redhat.com>
  • Loading branch information
humblec committed Mar 26, 2019
1 parent 311f929 commit eb2dd43
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 204 deletions.
8 changes: 4 additions & 4 deletions cmd/csi-snapshotter/create_crd.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ package main
import (
"reflect"

"github.com/golang/glog"
crdv1 "github.com/kubernetes-csi/external-snapshotter/pkg/apis/volumesnapshot/v1alpha1"
apiextensionsv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/klog"
)

// CreateCRD creates CustomResourceDefinition
Expand All @@ -43,7 +43,7 @@ func CreateCRD(clientset apiextensionsclient.Interface) error {
res, err := clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd)

if err != nil && !apierrors.IsAlreadyExists(err) {
glog.Fatalf("failed to create VolumeSnapshotResource: %#v, err: %#v",
klog.Fatalf("failed to create VolumeSnapshotResource: %#v, err: %#v",
res, err)
}

Expand All @@ -64,7 +64,7 @@ func CreateCRD(clientset apiextensionsclient.Interface) error {
res, err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd)

if err != nil && !apierrors.IsAlreadyExists(err) {
glog.Fatalf("failed to create VolumeSnapshotContentResource: %#v, err: %#v",
klog.Fatalf("failed to create VolumeSnapshotContentResource: %#v, err: %#v",
res, err)
}

Expand All @@ -85,7 +85,7 @@ func CreateCRD(clientset apiextensionsclient.Interface) error {
res, err = clientset.ApiextensionsV1beta1().CustomResourceDefinitions().Create(crd)

if err != nil && !apierrors.IsAlreadyExists(err) {
glog.Fatalf("failed to create VolumeSnapshotResource: %#v, err: %#v",
klog.Fatalf("failed to create VolumeSnapshotResource: %#v, err: %#v",
res, err)
}

Expand Down
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
Loading

0 comments on commit eb2dd43

Please sign in to comment.