diff --git a/cmd/csi-snapshotter/create_crd.go b/cmd/csi-snapshotter/create_crd.go index 99f9cf57f..656e1bd2d 100644 --- a/cmd/csi-snapshotter/create_crd.go +++ b/cmd/csi-snapshotter/create_crd.go @@ -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 @@ -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) } @@ -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) } @@ -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) } diff --git a/cmd/csi-snapshotter/main.go b/cmd/csi-snapshotter/main.go index 13bb0253e..529e8f7c1 100644 --- a/cmd/csi-snapshotter/main.go +++ b/cmd/csi-snapshotter/main.go @@ -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" @@ -67,6 +67,7 @@ var ( ) func main() { + klog.InitFlags(nil) flag.Set("logtostderr", "true") flag.Parse() @@ -74,31 +75,31 @@ func main() { 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) } @@ -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) } @@ -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) } @@ -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, @@ -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) { diff --git a/pkg/connection/connection.go b/pkg/connection/connection.go index 22c8309ab..760ae2cdb 100644 --- a/pkg/connection/connection.go +++ b/pkg/connection/connection.go @@ -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 @@ -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") } @@ -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 @@ -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 } diff --git a/pkg/controller/framework_test.go b/pkg/controller/framework_test.go index 08292af5e..da617cca4 100644 --- a/pkg/controller/framework_test.go +++ b/pkg/controller/framework_test.go @@ -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" @@ -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) @@ -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"): @@ -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"): @@ -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) @@ -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) @@ -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) } @@ -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 } } @@ -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 } } @@ -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) } } @@ -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 @@ -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{} diff --git a/pkg/controller/snapshot_controller.go b/pkg/controller/snapshot_controller.go index 9c0530aba..bcb7bbbf7 100644 --- a/pkg/controller/snapshot_controller.go +++ b/pkg/controller/snapshot_controller.go @@ -21,7 +21,6 @@ import ( "strings" "time" - "github.com/golang/glog" crdv1 "github.com/kubernetes-csi/external-snapshotter/pkg/apis/volumesnapshot/v1alpha1" "k8s.io/api/core/v1" storagev1 "k8s.io/api/storage/v1" @@ -32,6 +31,7 @@ import ( "k8s.io/apimachinery/pkg/labels" "k8s.io/client-go/kubernetes/scheme" ref "k8s.io/client-go/tools/reference" + "k8s.io/klog" "k8s.io/kubernetes/pkg/util/goroutinemap" "k8s.io/kubernetes/pkg/util/goroutinemap/exponentialbackoff" "k8s.io/kubernetes/pkg/util/slice" @@ -87,7 +87,7 @@ const IsDefaultSnapshotClassAnnotation = "snapshot.storage.kubernetes.io/is-defa // syncContent deals with one key off the queue. It returns false when it's time to quit. func (ctrl *csiSnapshotController) syncContent(content *crdv1.VolumeSnapshotContent) error { - glog.V(5).Infof("synchronizing VolumeSnapshotContent[%s]", content.Name) + klog.V(5).Infof("synchronizing VolumeSnapshotContent[%s]", content.Name) if isContentDeletionCandidate(content) { // Volume snapshot content should be deleted. Check if it's used @@ -95,29 +95,29 @@ func (ctrl *csiSnapshotController) syncContent(content *crdv1.VolumeSnapshotCont // Check if snapshot content is still bound to a snapshot. isUsed := ctrl.isSnapshotContentBeingUsed(content) if !isUsed { - glog.V(5).Infof("syncContent: Remove Finalizer for VolumeSnapshotContent[%s]", content.Name) + klog.V(5).Infof("syncContent: Remove Finalizer for VolumeSnapshotContent[%s]", content.Name) return ctrl.removeContentFinalizer(content) } } if needToAddContentFinalizer(content) { // Content is not being deleted -> it should have the finalizer. - glog.V(5).Infof("syncContent: Add Finalizer for VolumeSnapshotContent[%s]", content.Name) + klog.V(5).Infof("syncContent: Add Finalizer for VolumeSnapshotContent[%s]", content.Name) return ctrl.addContentFinalizer(content) } // VolumeSnapshotContent is not bound to any VolumeSnapshot, in this case we just return err if content.Spec.VolumeSnapshotRef == nil { // content is not bound - glog.V(4).Infof("synchronizing VolumeSnapshotContent[%s]: VolumeSnapshotContent is not bound to any VolumeSnapshot", content.Name) + klog.V(4).Infof("synchronizing VolumeSnapshotContent[%s]: VolumeSnapshotContent is not bound to any VolumeSnapshot", content.Name) ctrl.eventRecorder.Event(content, v1.EventTypeWarning, "SnapshotContentNotBound", "VolumeSnapshotContent is not bound to any VolumeSnapshot") return fmt.Errorf("volumeSnapshotContent %s is not bound to any VolumeSnapshot", content.Name) } - glog.V(4).Infof("synchronizing VolumeSnapshotContent[%s]: content is bound to snapshot %s", content.Name, snapshotRefKey(content.Spec.VolumeSnapshotRef)) + klog.V(4).Infof("synchronizing VolumeSnapshotContent[%s]: content is bound to snapshot %s", content.Name, snapshotRefKey(content.Spec.VolumeSnapshotRef)) // The VolumeSnapshotContent is reserved for a VolumeSnapshot; // that VolumeSnapshot has not yet been bound to this VolumeSnapshotContent; the VolumeSnapshot sync will handle it. if content.Spec.VolumeSnapshotRef.UID == "" { - glog.V(4).Infof("synchronizing VolumeSnapshotContent[%s]: VolumeSnapshotContent is pre-bound to VolumeSnapshot %s", content.Name, snapshotRefKey(content.Spec.VolumeSnapshotRef)) + klog.V(4).Infof("synchronizing VolumeSnapshotContent[%s]: VolumeSnapshotContent is pre-bound to VolumeSnapshot %s", content.Name, snapshotRefKey(content.Spec.VolumeSnapshotRef)) return nil } // Get the VolumeSnapshot by _name_ @@ -128,7 +128,7 @@ func (ctrl *csiSnapshotController) syncContent(content *crdv1.VolumeSnapshotCont return err } if !found { - glog.V(4).Infof("synchronizing VolumeSnapshotContent[%s]: snapshot %s not found", content.Name, snapshotRefKey(content.Spec.VolumeSnapshotRef)) + klog.V(4).Infof("synchronizing VolumeSnapshotContent[%s]: snapshot %s not found", content.Name, snapshotRefKey(content.Spec.VolumeSnapshotRef)) // Fall through with snapshot = nil } else { var ok bool @@ -136,12 +136,12 @@ func (ctrl *csiSnapshotController) syncContent(content *crdv1.VolumeSnapshotCont if !ok { return fmt.Errorf("cannot convert object from snapshot cache to snapshot %q!?: %#v", content.Name, obj) } - glog.V(4).Infof("synchronizing VolumeSnapshotContent[%s]: snapshot %s found", content.Name, snapshotRefKey(content.Spec.VolumeSnapshotRef)) + klog.V(4).Infof("synchronizing VolumeSnapshotContent[%s]: snapshot %s found", content.Name, snapshotRefKey(content.Spec.VolumeSnapshotRef)) } if snapshot != nil && snapshot.UID != content.Spec.VolumeSnapshotRef.UID { // The snapshot that the content was pointing to was deleted, and another // with the same name created. - glog.V(4).Infof("synchronizing VolumeSnapshotContent[%s]: content %s has different UID, the old one must have been deleted", content.Name, snapshotRefKey(content.Spec.VolumeSnapshotRef)) + klog.V(4).Infof("synchronizing VolumeSnapshotContent[%s]: content %s has different UID, the old one must have been deleted", content.Name, snapshotRefKey(content.Spec.VolumeSnapshotRef)) // Treat the content as bound to a missing snapshot. snapshot = nil } @@ -149,10 +149,10 @@ func (ctrl *csiSnapshotController) syncContent(content *crdv1.VolumeSnapshotCont if content.Spec.DeletionPolicy != nil { switch *content.Spec.DeletionPolicy { case crdv1.VolumeSnapshotContentRetain: - glog.V(4).Infof("VolumeSnapshotContent[%s]: policy is Retain, nothing to do", content.Name) + klog.V(4).Infof("VolumeSnapshotContent[%s]: policy is Retain, nothing to do", content.Name) case crdv1.VolumeSnapshotContentDelete: - glog.V(4).Infof("VolumeSnapshotContent[%s]: policy is Delete", content.Name) + klog.V(4).Infof("VolumeSnapshotContent[%s]: policy is Delete", content.Name) ctrl.deleteSnapshotContent(content) default: // Unknown VolumeSnapshotDeletionolicy @@ -161,7 +161,7 @@ func (ctrl *csiSnapshotController) syncContent(content *crdv1.VolumeSnapshotCont return nil } // By default, we use Retain policy if it is not set by users - glog.V(4).Infof("VolumeSnapshotContent[%s]: by default the policy is Retain", content.Name) + klog.V(4).Infof("VolumeSnapshotContent[%s]: by default the policy is Retain", content.Name) } return nil @@ -173,7 +173,7 @@ func (ctrl *csiSnapshotController) syncContent(content *crdv1.VolumeSnapshotCont // these events. // For easier readability, it is split into syncUnreadySnapshot and syncReadySnapshot func (ctrl *csiSnapshotController) syncSnapshot(snapshot *crdv1.VolumeSnapshot) error { - glog.V(5).Infof("synchonizing VolumeSnapshot[%s]: %s", snapshotKey(snapshot), getSnapshotStatusForLogging(snapshot)) + klog.V(5).Infof("synchonizing VolumeSnapshot[%s]: %s", snapshotKey(snapshot), getSnapshotStatusForLogging(snapshot)) if isSnapshotDeletionCandidate(snapshot) { // Volume snapshot should be deleted. Check if it's used @@ -181,14 +181,14 @@ func (ctrl *csiSnapshotController) syncSnapshot(snapshot *crdv1.VolumeSnapshot) // Check if a volume is being created from snapshot. isUsed := ctrl.isVolumeBeingCreatedFromSnapshot(snapshot) if !isUsed { - glog.V(5).Infof("syncSnapshot: Remove Finalizer for VolumeSnapshot[%s]", snapshotKey(snapshot)) + klog.V(5).Infof("syncSnapshot: Remove Finalizer for VolumeSnapshot[%s]", snapshotKey(snapshot)) return ctrl.removeSnapshotFinalizer(snapshot) } } if needToAddSnapshotFinalizer(snapshot) { // Snapshot is not being deleted -> it should have the finalizer. - glog.V(5).Infof("syncSnapshot: Add Finalizer for VolumeSnapshot[%s]", snapshotKey(snapshot)) + klog.V(5).Infof("syncSnapshot: Add Finalizer for VolumeSnapshot[%s]", snapshotKey(snapshot)) return ctrl.addSnapshotFinalizer(snapshot) } @@ -223,7 +223,7 @@ func (ctrl *csiSnapshotController) syncReadySnapshot(snapshot *crdv1.VolumeSnaps return fmt.Errorf("Cannot convert object from snapshot content store to VolumeSnapshotContent %q!?: %#v", snapshot.Spec.SnapshotContentName, obj) } - glog.V(5).Infof("syncReadySnapshot[%s]: VolumeSnapshotContent %q found", snapshotKey(snapshot), content.Name) + klog.V(5).Infof("syncReadySnapshot[%s]: VolumeSnapshotContent %q found", snapshotKey(snapshot), content.Name) if !IsSnapshotBound(snapshot, content) { // snapshot is bound but content is not bound to snapshot correctly if err = ctrl.updateSnapshotErrorStatusWithEvent(snapshot, v1.EventTypeWarning, "SnapshotMisbound", "VolumeSnapshotContent is not bound to the VolumeSnapshot correctly"); err != nil { @@ -239,7 +239,7 @@ func (ctrl *csiSnapshotController) syncReadySnapshot(snapshot *crdv1.VolumeSnaps // syncUnreadySnapshot is the main controller method to decide what to do with a snapshot which is not set to ready. func (ctrl *csiSnapshotController) syncUnreadySnapshot(snapshot *crdv1.VolumeSnapshot) error { uniqueSnapshotName := snapshotKey(snapshot) - glog.V(5).Infof("syncUnreadySnapshot %s", uniqueSnapshotName) + klog.V(5).Infof("syncUnreadySnapshot %s", uniqueSnapshotName) if snapshot.Spec.SnapshotContentName != "" { contentObj, found, err := ctrl.contentStore.GetByKey(snapshot.Spec.SnapshotContentName) @@ -249,7 +249,7 @@ func (ctrl *csiSnapshotController) syncUnreadySnapshot(snapshot *crdv1.VolumeSna if !found { // snapshot is bound to a non-existing content. ctrl.updateSnapshotErrorStatusWithEvent(snapshot, v1.EventTypeWarning, "SnapshotContentMissing", "VolumeSnapshotContent is missing") - glog.V(4).Infof("synchronizing unready snapshot[%s]: snapshotcontent %q requested and not found, will try again next time", uniqueSnapshotName, snapshot.Spec.SnapshotContentName) + klog.V(4).Infof("synchronizing unready snapshot[%s]: snapshotcontent %q requested and not found, will try again next time", uniqueSnapshotName, snapshot.Spec.SnapshotContentName) return fmt.Errorf("snapshot %s is bound to a non-existing content %s", uniqueSnapshotName, snapshot.Spec.SnapshotContentName) } content, ok := contentObj.(*crdv1.VolumeSnapshotContent) @@ -264,19 +264,19 @@ func (ctrl *csiSnapshotController) syncUnreadySnapshot(snapshot *crdv1.VolumeSna } // snapshot is already bound correctly, check the status and update if it is ready. - glog.V(5).Infof("Check and update snapshot %s status", uniqueSnapshotName) + klog.V(5).Infof("Check and update snapshot %s status", uniqueSnapshotName) if err = ctrl.checkandUpdateBoundSnapshotStatus(snapshot, content); err != nil { return err } return nil } else { // snapshot.Spec.SnapshotContentName == nil if contentObj := ctrl.getMatchSnapshotContent(snapshot); contentObj != nil { - glog.V(5).Infof("Find VolumeSnapshotContent object %s for snapshot %s", contentObj.Name, uniqueSnapshotName) + klog.V(5).Infof("Find VolumeSnapshotContent object %s for snapshot %s", contentObj.Name, uniqueSnapshotName) newSnapshot, err := ctrl.bindandUpdateVolumeSnapshot(contentObj, snapshot) if err != nil { return err } - glog.V(5).Infof("bindandUpdateVolumeSnapshot %v", newSnapshot) + klog.V(5).Infof("bindandUpdateVolumeSnapshot %v", newSnapshot) return nil } else if snapshot.Status.Error == nil || isControllerUpdateFailError(snapshot.Status.Error) { // Try to create snapshot if no error status is set if err := ctrl.createSnapshot(snapshot); err != nil { @@ -310,7 +310,7 @@ func (ctrl *csiSnapshotController) getMatchSnapshotContent(snapshot *crdv1.Volum } if !found { - glog.V(4).Infof("No VolumeSnapshotContent for VolumeSnapshot %s found", snapshotKey(snapshot)) + klog.V(4).Infof("No VolumeSnapshotContent for VolumeSnapshot %s found", snapshotKey(snapshot)) return nil } @@ -320,7 +320,7 @@ func (ctrl *csiSnapshotController) getMatchSnapshotContent(snapshot *crdv1.Volum // deleteSnapshotContent starts delete action. func (ctrl *csiSnapshotController) deleteSnapshotContent(content *crdv1.VolumeSnapshotContent) { operationName := fmt.Sprintf("delete-%s[%s]", content.Name, string(content.UID)) - glog.V(5).Infof("Snapshotter is about to delete volume snapshot content and the operation named %s", operationName) + klog.V(5).Infof("Snapshotter is about to delete volume snapshot content and the operation named %s", operationName) ctrl.scheduleOperation(operationName, func() error { return ctrl.deleteSnapshotContentOperation(content) }) @@ -329,17 +329,17 @@ func (ctrl *csiSnapshotController) deleteSnapshotContent(content *crdv1.VolumeSn // scheduleOperation starts given asynchronous operation on given volume. It // makes sure the operation is already not running. func (ctrl *csiSnapshotController) scheduleOperation(operationName string, operation func() error) { - glog.V(5).Infof("scheduleOperation[%s]", operationName) + klog.V(5).Infof("scheduleOperation[%s]", operationName) err := ctrl.runningOperations.Run(operationName, operation) if err != nil { switch { case goroutinemap.IsAlreadyExists(err): - glog.V(4).Infof("operation %q is already running, skipping", operationName) + klog.V(4).Infof("operation %q is already running, skipping", operationName) case exponentialbackoff.IsExponentialBackoff(err): - glog.V(4).Infof("operation %q postponed due to exponential backoff", operationName) + klog.V(4).Infof("operation %q postponed due to exponential backoff", operationName) default: - glog.Errorf("error scheduling operation %q: %v", operationName, err) + klog.Errorf("error scheduling operation %q: %v", operationName, err) } } } @@ -354,19 +354,19 @@ func (ctrl *csiSnapshotController) storeContentUpdate(content interface{}) (bool // createSnapshot starts new asynchronous operation to create snapshot func (ctrl *csiSnapshotController) createSnapshot(snapshot *crdv1.VolumeSnapshot) error { - glog.V(5).Infof("createSnapshot[%s]: started", snapshotKey(snapshot)) + klog.V(5).Infof("createSnapshot[%s]: started", snapshotKey(snapshot)) opName := fmt.Sprintf("create-%s[%s]", snapshotKey(snapshot), string(snapshot.UID)) ctrl.scheduleOperation(opName, func() error { snapshotObj, err := ctrl.createSnapshotOperation(snapshot) if err != nil { ctrl.updateSnapshotErrorStatusWithEvent(snapshot, v1.EventTypeWarning, "SnapshotCreationFailed", fmt.Sprintf("Failed to create snapshot: %v", err)) - glog.Errorf("createSnapshot [%s]: error occurred in createSnapshotOperation: %v", opName, err) + klog.Errorf("createSnapshot [%s]: error occurred in createSnapshotOperation: %v", opName, err) return err } _, updateErr := ctrl.storeSnapshotUpdate(snapshotObj) if updateErr != nil { // We will get an "snapshot update" event soon, this is not a big error - glog.V(4).Infof("createSnapshot [%s]: cannot update internal cache: %v", snapshotKey(snapshotObj), updateErr) + klog.V(4).Infof("createSnapshot [%s]: cannot update internal cache: %v", snapshotKey(snapshotObj), updateErr) } return nil @@ -375,19 +375,19 @@ func (ctrl *csiSnapshotController) createSnapshot(snapshot *crdv1.VolumeSnapshot } func (ctrl *csiSnapshotController) checkandUpdateBoundSnapshotStatus(snapshot *crdv1.VolumeSnapshot, content *crdv1.VolumeSnapshotContent) error { - glog.V(5).Infof("checkandUpdateSnapshotStatus[%s] started", snapshotKey(snapshot)) + klog.V(5).Infof("checkandUpdateSnapshotStatus[%s] started", snapshotKey(snapshot)) opName := fmt.Sprintf("check-%s[%s]", snapshotKey(snapshot), string(snapshot.UID)) ctrl.scheduleOperation(opName, func() error { snapshotObj, err := ctrl.checkandUpdateBoundSnapshotStatusOperation(snapshot, content) if err != nil { ctrl.updateSnapshotErrorStatusWithEvent(snapshot, v1.EventTypeWarning, "SnapshotCheckandUpdateFailed", fmt.Sprintf("Failed to check and update snapshot: %v", err)) - glog.Errorf("checkandUpdateSnapshotStatus [%s]: error occured %v", snapshotKey(snapshot), err) + klog.Errorf("checkandUpdateSnapshotStatus [%s]: error occured %v", snapshotKey(snapshot), err) return err } _, updateErr := ctrl.storeSnapshotUpdate(snapshotObj) if updateErr != nil { // We will get an "snapshot update" event soon, this is not a big error - glog.V(4).Infof("checkandUpdateSnapshotStatus [%s]: cannot update internal cache: %v", snapshotKey(snapshotObj), updateErr) + klog.V(4).Infof("checkandUpdateSnapshotStatus [%s]: cannot update internal cache: %v", snapshotKey(snapshotObj), updateErr) } return nil @@ -402,10 +402,10 @@ func (ctrl *csiSnapshotController) checkandUpdateBoundSnapshotStatus(snapshot *c // snapshot - snapshot to update // eventtype, reason, message - event to send, see EventRecorder.Event() func (ctrl *csiSnapshotController) updateSnapshotErrorStatusWithEvent(snapshot *crdv1.VolumeSnapshot, eventtype, reason, message string) error { - glog.V(5).Infof("updateSnapshotStatusWithEvent[%s]", snapshotKey(snapshot)) + klog.V(5).Infof("updateSnapshotStatusWithEvent[%s]", snapshotKey(snapshot)) if snapshot.Status.Error != nil && snapshot.Status.Error.Message == message { - glog.V(4).Infof("updateSnapshotStatusWithEvent[%s]: the same error %v is already set", snapshot.Name, snapshot.Status.Error) + klog.V(4).Infof("updateSnapshotStatusWithEvent[%s]: the same error %v is already set", snapshot.Name, snapshot.Status.Error) return nil } snapshotClone := snapshot.DeepCopy() @@ -420,13 +420,13 @@ func (ctrl *csiSnapshotController) updateSnapshotErrorStatusWithEvent(snapshot * snapshotClone.Status.ReadyToUse = false newSnapshot, err := ctrl.clientset.VolumesnapshotV1alpha1().VolumeSnapshots(snapshotClone.Namespace).Update(snapshotClone) if err != nil { - glog.V(4).Infof("updating VolumeSnapshot[%s] error status failed %v", snapshotKey(snapshot), err) + klog.V(4).Infof("updating VolumeSnapshot[%s] error status failed %v", snapshotKey(snapshot), err) return err } _, err = ctrl.storeSnapshotUpdate(newSnapshot) if err != nil { - glog.V(4).Infof("updating VolumeSnapshot[%s] error status: cannot update internal cache %v", snapshotKey(snapshot), err) + klog.V(4).Infof("updating VolumeSnapshot[%s] error status: cannot update internal cache %v", snapshotKey(snapshot), err) return err } // Emit the event only when the status change happens @@ -454,18 +454,18 @@ func (ctrl *csiSnapshotController) isSnapshotContentBeingUsed(content *crdv1.Vol if content.Spec.VolumeSnapshotRef != nil { snapshotObj, err := ctrl.clientset.VolumesnapshotV1alpha1().VolumeSnapshots(content.Spec.VolumeSnapshotRef.Namespace).Get(content.Spec.VolumeSnapshotRef.Name, metav1.GetOptions{}) if err != nil { - glog.Infof("isSnapshotContentBeingUsed: Cannot get snapshot %s from api server: [%v]. VolumeSnapshot object may be deleted already.", content.Spec.VolumeSnapshotRef.Name, err) + klog.Infof("isSnapshotContentBeingUsed: Cannot get snapshot %s from api server: [%v]. VolumeSnapshot object may be deleted already.", content.Spec.VolumeSnapshotRef.Name, err) return false } // Check if the snapshot content is bound to the snapshot if IsSnapshotBound(snapshotObj, content) && snapshotObj.Spec.SnapshotContentName == content.Name { - glog.Infof("isSnapshotContentBeingUsed: VolumeSnapshot %s is bound to volumeSnapshotContent [%s]", snapshotObj.Name, content.Name) + klog.Infof("isSnapshotContentBeingUsed: VolumeSnapshot %s is bound to volumeSnapshotContent [%s]", snapshotObj.Name, content.Name) return true } } - glog.V(5).Infof("isSnapshotContentBeingUsed: Snapshot content %s is not being used", content.Name) + klog.V(5).Infof("isSnapshotContentBeingUsed: Snapshot content %s is not being used", content.Name) return false } @@ -473,7 +473,7 @@ func (ctrl *csiSnapshotController) isSnapshotContentBeingUsed(content *crdv1.Vol func (ctrl *csiSnapshotController) isVolumeBeingCreatedFromSnapshot(snapshot *crdv1.VolumeSnapshot) bool { pvcList, err := ctrl.pvcLister.PersistentVolumeClaims(snapshot.Namespace).List(labels.Everything()) if err != nil { - glog.Errorf("Failed to retrieve PVCs from the lister to check if volume snapshot %s is being used by a volume: %q", snapshotKey(snapshot), err) + klog.Errorf("Failed to retrieve PVCs from the lister to check if volume snapshot %s is being used by a volume: %q", snapshotKey(snapshot), err) return false } for _, pvc := range pvcList { @@ -481,13 +481,13 @@ func (ctrl *csiSnapshotController) isVolumeBeingCreatedFromSnapshot(snapshot *cr if pvc.Spec.DataSource.Kind == snapshotKind && *(pvc.Spec.DataSource.APIGroup) == snapshotAPIGroup { if pvc.Status.Phase == v1.ClaimPending { // A volume is being created from the snapshot - glog.Infof("isVolumeBeingCreatedFromSnapshot: volume %s is being created from snapshot %s", pvc.Name, pvc.Spec.DataSource.Name) + klog.Infof("isVolumeBeingCreatedFromSnapshot: volume %s is being created from snapshot %s", pvc.Name, pvc.Spec.DataSource.Name) return true } } } } - glog.V(5).Infof("isVolumeBeingCreatedFromSnapshot: no volume is being created from snapshot %s", snapshotKey(snapshot)) + klog.V(5).Infof("isVolumeBeingCreatedFromSnapshot: no volume is being created from snapshot %s", snapshotKey(snapshot)) return false } @@ -506,12 +506,12 @@ func (ctrl *csiSnapshotController) checkandBindSnapshotContent(snapshot *crdv1.V contentClone.Spec.VolumeSnapshotClassName = &className newContent, err := ctrl.clientset.VolumesnapshotV1alpha1().VolumeSnapshotContents().Update(contentClone) if err != nil { - glog.V(4).Infof("updating VolumeSnapshotContent[%s] error status failed %v", newContent.Name, err) + klog.V(4).Infof("updating VolumeSnapshotContent[%s] error status failed %v", newContent.Name, err) return err } _, err = ctrl.storeContentUpdate(newContent) if err != nil { - glog.V(4).Infof("updating VolumeSnapshotContent[%s] error status: cannot update internal cache %v", newContent.Name, err) + klog.V(4).Infof("updating VolumeSnapshotContent[%s] error status: cannot update internal cache %v", newContent.Name, err) return err } return nil @@ -519,23 +519,23 @@ func (ctrl *csiSnapshotController) checkandBindSnapshotContent(snapshot *crdv1.V func (ctrl *csiSnapshotController) getCreateSnapshotInput(snapshot *crdv1.VolumeSnapshot) (*crdv1.VolumeSnapshotClass, *v1.PersistentVolume, string, map[string]string, error) { className := snapshot.Spec.VolumeSnapshotClassName - glog.V(5).Infof("getCreateSnapshotInput [%s]: VolumeSnapshotClassName [%s]", snapshot.Name, *className) + klog.V(5).Infof("getCreateSnapshotInput [%s]: VolumeSnapshotClassName [%s]", snapshot.Name, *className) var class *crdv1.VolumeSnapshotClass var err error if className != nil { class, err = ctrl.GetSnapshotClass(*className) if err != nil { - glog.Errorf("getCreateSnapshotInput failed to getClassFromVolumeSnapshot %s", err) + klog.Errorf("getCreateSnapshotInput failed to getClassFromVolumeSnapshot %s", err) return nil, nil, "", nil, err } } else { - glog.Errorf("failed to getCreateSnapshotInput %s without a snapshot class", snapshot.Name) + klog.Errorf("failed to getCreateSnapshotInput %s without a snapshot class", snapshot.Name) return nil, nil, "", nil, fmt.Errorf("failed to take snapshot %s without a snapshot class", snapshot.Name) } volume, err := ctrl.getVolumeFromVolumeSnapshot(snapshot) if err != nil { - glog.Errorf("getCreateSnapshotInput failed to get PersistentVolume object [%s]: Error: [%#v]", snapshot.Name, err) + klog.Errorf("getCreateSnapshotInput failed to get PersistentVolume object [%s]: Error: [%#v]", snapshot.Name, err) return nil, nil, "", nil, err } @@ -566,10 +566,10 @@ func (ctrl *csiSnapshotController) checkandUpdateBoundSnapshotStatusOperation(sn } driverName, snapshotID, timestamp, size, readyToUse, err := ctrl.handler.CreateSnapshot(snapshot, volume, class.Parameters, snapshotterCredentials) if err != nil { - glog.Errorf("checkandUpdateBoundSnapshotStatusOperation: failed to call create snapshot to check whether the snapshot is ready to use %q", err) + klog.Errorf("checkandUpdateBoundSnapshotStatusOperation: failed to call create snapshot to check whether the snapshot is ready to use %q", err) return nil, err } - glog.V(5).Infof("checkandUpdateBoundSnapshotStatusOperation: driver %s, snapshotId %s, timestamp %d, size %d, readyToUse %t", driverName, snapshotID, timestamp, size, readyToUse) + klog.V(5).Infof("checkandUpdateBoundSnapshotStatusOperation: driver %s, snapshotId %s, timestamp %d, size %d, readyToUse %t", driverName, snapshotID, timestamp, size, readyToUse) if timestamp == 0 { timestamp = time.Now().UnixNano() @@ -591,10 +591,10 @@ func (ctrl *csiSnapshotController) checkandUpdateBoundSnapshotStatusOperation(sn // 3. Create the VolumeSnapshotContent object with the snapshot id information. // 4. Bind the VolumeSnapshot and VolumeSnapshotContent object func (ctrl *csiSnapshotController) createSnapshotOperation(snapshot *crdv1.VolumeSnapshot) (*crdv1.VolumeSnapshot, error) { - glog.Infof("createSnapshot: Creating snapshot %s through the plugin ...", snapshotKey(snapshot)) + klog.Infof("createSnapshot: Creating snapshot %s through the plugin ...", snapshotKey(snapshot)) if snapshot.Status.Error != nil && !isControllerUpdateFailError(snapshot.Status.Error) { - glog.V(4).Infof("error is already set in snapshot, do not retry to create: %s", snapshot.Status.Error.Message) + klog.V(4).Infof("error is already set in snapshot, do not retry to create: %s", snapshot.Status.Error.Message) return snapshot, nil } @@ -607,17 +607,17 @@ func (ctrl *csiSnapshotController) createSnapshotOperation(snapshot *crdv1.Volum if err != nil { return nil, fmt.Errorf("failed to take snapshot of the volume, %s: %q", volume.Name, err) } - glog.V(5).Infof("Created snapshot: driver %s, snapshotId %s, timestamp %d, size %d, readyToUse %t", driverName, snapshotID, timestamp, size, readyToUse) + klog.V(5).Infof("Created snapshot: driver %s, snapshotId %s, timestamp %d, size %d, readyToUse %t", driverName, snapshotID, timestamp, size, readyToUse) var newSnapshot *crdv1.VolumeSnapshot // Update snapshot status with timestamp for i := 0; i < ctrl.createSnapshotContentRetryCount; i++ { - glog.V(5).Infof("createSnapshot [%s]: trying to update snapshot creation timestamp", snapshotKey(snapshot)) + klog.V(5).Infof("createSnapshot [%s]: trying to update snapshot creation timestamp", snapshotKey(snapshot)) newSnapshot, err = ctrl.updateSnapshotStatus(snapshot, readyToUse, timestamp, size, false) if err == nil { break } - glog.V(4).Infof("failed to update snapshot %s creation timestamp: %v", snapshotKey(snapshot), err) + klog.V(4).Infof("failed to update snapshot %s creation timestamp: %v", snapshotKey(snapshot), err) } if err != nil { @@ -656,22 +656,22 @@ func (ctrl *csiSnapshotController) createSnapshotOperation(snapshot *crdv1.Volum DeletionPolicy: class.DeletionPolicy, }, } - glog.V(3).Infof("volume snapshot content %v", snapshotContent) + klog.V(3).Infof("volume snapshot content %v", snapshotContent) // Try to create the VolumeSnapshotContent object several times for i := 0; i < ctrl.createSnapshotContentRetryCount; i++ { - glog.V(5).Infof("createSnapshot [%s]: trying to save volume snapshot content %s", snapshotKey(snapshot), snapshotContent.Name) + klog.V(5).Infof("createSnapshot [%s]: trying to save volume snapshot content %s", snapshotKey(snapshot), snapshotContent.Name) if _, err = ctrl.clientset.VolumesnapshotV1alpha1().VolumeSnapshotContents().Create(snapshotContent); err == nil || apierrs.IsAlreadyExists(err) { // Save succeeded. if err != nil { - glog.V(3).Infof("volume snapshot content %q for snapshot %q already exists, reusing", snapshotContent.Name, snapshotKey(snapshot)) + klog.V(3).Infof("volume snapshot content %q for snapshot %q already exists, reusing", snapshotContent.Name, snapshotKey(snapshot)) err = nil } else { - glog.V(3).Infof("volume snapshot content %q for snapshot %q saved, %v", snapshotContent.Name, snapshotKey(snapshot), snapshotContent) + klog.V(3).Infof("volume snapshot content %q for snapshot %q saved, %v", snapshotContent.Name, snapshotKey(snapshot), snapshotContent) } break } // Save failed, try again after a while. - glog.V(3).Infof("failed to save volume snapshot content %q for snapshot %q: %v", snapshotContent.Name, snapshotKey(snapshot), err) + klog.V(3).Infof("failed to save volume snapshot content %q for snapshot %q: %v", snapshotContent.Name, snapshotKey(snapshot), err) time.Sleep(ctrl.createSnapshotContentInterval) } @@ -680,7 +680,7 @@ func (ctrl *csiSnapshotController) createSnapshotOperation(snapshot *crdv1.Volum // but we don't have appropriate volumesnapshot content object for it. // Emit some event here and controller should try to create the content in next sync period. strerr := fmt.Sprintf("Error creating volume snapshot content object for snapshot %s: %v.", snapshotKey(snapshot), err) - glog.Error(strerr) + klog.Error(strerr) ctrl.eventRecorder.Event(newSnapshot, v1.EventTypeWarning, "CreateSnapshotContentFailed", strerr) return nil, newControllerUpdateError(snapshotKey(snapshot), err.Error()) } @@ -701,7 +701,7 @@ func (ctrl *csiSnapshotController) createSnapshotOperation(snapshot *crdv1.Volum // 4. Remove the Snapshot from store // 5. Finish func (ctrl *csiSnapshotController) deleteSnapshotContentOperation(content *crdv1.VolumeSnapshotContent) error { - glog.V(5).Infof("deleteSnapshotOperation [%s] started", content.Name) + klog.V(5).Infof("deleteSnapshotOperation [%s] started", content.Name) // get secrets if VolumeSnapshotClass specifies it var snapshotterCredentials map[string]string @@ -737,7 +737,7 @@ func (ctrl *csiSnapshotController) deleteSnapshotContentOperation(content *crdv1 } func (ctrl *csiSnapshotController) bindandUpdateVolumeSnapshot(snapshotContent *crdv1.VolumeSnapshotContent, snapshot *crdv1.VolumeSnapshot) (*crdv1.VolumeSnapshot, error) { - glog.V(5).Infof("bindandUpdateVolumeSnapshot for snapshot [%s]: snapshotContent [%s]", snapshot.Name, snapshotContent.Name) + klog.V(5).Infof("bindandUpdateVolumeSnapshot for snapshot [%s]: snapshotContent [%s]", snapshot.Name, snapshotContent.Name) snapshotObj, err := ctrl.clientset.VolumesnapshotV1alpha1().VolumeSnapshots(snapshot.Namespace).Get(snapshot.Name, metav1.GetOptions{}) if err != nil { return nil, fmt.Errorf("error get snapshot %s from api server: %v", snapshotKey(snapshot), err) @@ -747,23 +747,23 @@ func (ctrl *csiSnapshotController) bindandUpdateVolumeSnapshot(snapshotContent * snapshotCopy := snapshotObj.DeepCopy() if snapshotObj.Spec.SnapshotContentName == snapshotContent.Name { - glog.Infof("bindVolumeSnapshotContentToVolumeSnapshot: VolumeSnapshot %s already bind to volumeSnapshotContent [%s]", snapshot.Name, snapshotContent.Name) + klog.Infof("bindVolumeSnapshotContentToVolumeSnapshot: VolumeSnapshot %s already bind to volumeSnapshotContent [%s]", snapshot.Name, snapshotContent.Name) } else { - glog.Infof("bindVolumeSnapshotContentToVolumeSnapshot: before bind VolumeSnapshot %s to volumeSnapshotContent [%s]", snapshot.Name, snapshotContent.Name) + klog.Infof("bindVolumeSnapshotContentToVolumeSnapshot: before bind VolumeSnapshot %s to volumeSnapshotContent [%s]", snapshot.Name, snapshotContent.Name) snapshotCopy.Spec.SnapshotContentName = snapshotContent.Name updateSnapshot, err := ctrl.clientset.VolumesnapshotV1alpha1().VolumeSnapshots(snapshot.Namespace).Update(snapshotCopy) if err != nil { - glog.Infof("bindVolumeSnapshotContentToVolumeSnapshot: Error binding VolumeSnapshot %s to volumeSnapshotContent [%s]. Error [%#v]", snapshot.Name, snapshotContent.Name, err) + klog.Infof("bindVolumeSnapshotContentToVolumeSnapshot: Error binding VolumeSnapshot %s to volumeSnapshotContent [%s]. Error [%#v]", snapshot.Name, snapshotContent.Name, err) return nil, newControllerUpdateError(snapshotKey(snapshot), err.Error()) } snapshotCopy = updateSnapshot _, err = ctrl.storeSnapshotUpdate(snapshotCopy) if err != nil { - glog.Errorf("%v", err) + klog.Errorf("%v", err) } } - glog.V(5).Infof("bindandUpdateVolumeSnapshot for snapshot completed [%#v]", snapshotCopy) + klog.V(5).Infof("bindandUpdateVolumeSnapshot for snapshot completed [%#v]", snapshotCopy) return snapshotCopy, nil } @@ -784,14 +784,14 @@ func (ctrl *csiSnapshotController) updateSnapshotContentSize(content *crdv1.Volu _, err = ctrl.storeContentUpdate(contentClone) if err != nil { - glog.Errorf("failed to update content store %v", err) + klog.Errorf("failed to update content store %v", err) } return nil } // UpdateSnapshotStatus converts snapshot status to crdv1.VolumeSnapshotCondition func (ctrl *csiSnapshotController) updateSnapshotStatus(snapshot *crdv1.VolumeSnapshot, readyToUse bool, createdAt, size int64, bound bool) (*crdv1.VolumeSnapshot, error) { - glog.V(5).Infof("updating VolumeSnapshot[]%s, readyToUse %v, timestamp %v", snapshotKey(snapshot), readyToUse, createdAt) + klog.V(5).Infof("updating VolumeSnapshot[]%s, readyToUse %v, timestamp %v", snapshotKey(snapshot), readyToUse, createdAt) status := snapshot.Status change := false timeAt := &metav1.Time{ @@ -844,7 +844,7 @@ func (ctrl *csiSnapshotController) getVolumeFromVolumeSnapshot(snapshot *crdv1.V return nil, fmt.Errorf("failed to retrieve PV %s from the API server: %q", pvName, err) } - glog.V(5).Infof("getVolumeFromVolumeSnapshot: snapshot [%s] PV name [%s]", snapshot.Name, pvName) + klog.V(5).Infof("getVolumeFromVolumeSnapshot: snapshot [%s] PV name [%s]", snapshot.Name, pvName) return pv, nil } @@ -875,11 +875,11 @@ func (ctrl *csiSnapshotController) getStorageClassFromVolumeSnapshot(snapshot *c // GetSnapshotClass is a helper function to get snapshot class from the class name. func (ctrl *csiSnapshotController) GetSnapshotClass(className string) (*crdv1.VolumeSnapshotClass, error) { - glog.V(5).Infof("getSnapshotClass: VolumeSnapshotClassName [%s]", className) + klog.V(5).Infof("getSnapshotClass: VolumeSnapshotClassName [%s]", className) class, err := ctrl.classLister.Get(className) if err != nil { - glog.Errorf("failed to retrieve snapshot class %s from the informer: %q", className, err) + klog.Errorf("failed to retrieve snapshot class %s from the informer: %q", className, err) return nil, fmt.Errorf("failed to retrieve snapshot class %s from the informer: %q", className, err) } @@ -889,7 +889,7 @@ func (ctrl *csiSnapshotController) GetSnapshotClass(className string) (*crdv1.Vo // SetDefaultSnapshotClass is a helper function to figure out the default snapshot class from // PVC/PV StorageClass and update VolumeSnapshot with this snapshot class name. func (ctrl *csiSnapshotController) SetDefaultSnapshotClass(snapshot *crdv1.VolumeSnapshot) (*crdv1.VolumeSnapshotClass, *crdv1.VolumeSnapshot, error) { - glog.V(5).Infof("SetDefaultSnapshotClass for snapshot [%s]", snapshot.Name) + klog.V(5).Infof("SetDefaultSnapshotClass for snapshot [%s]", snapshot.Name) storageclass, err := ctrl.getStorageClassFromVolumeSnapshot(snapshot) if err != nil { @@ -905,27 +905,27 @@ func (ctrl *csiSnapshotController) SetDefaultSnapshotClass(snapshot *crdv1.Volum for _, class := range list { if IsDefaultAnnotation(class.ObjectMeta) && storageclass.Provisioner == class.Snapshotter && ctrl.snapshotterName == class.Snapshotter { defaultClasses = append(defaultClasses, class) - glog.V(5).Infof("get defaultClass added: %s", class.Name) + klog.V(5).Infof("get defaultClass added: %s", class.Name) } } if len(defaultClasses) == 0 { return nil, nil, fmt.Errorf("cannot find default snapshot class") } if len(defaultClasses) > 1 { - glog.V(4).Infof("get DefaultClass %d defaults found", len(defaultClasses)) + klog.V(4).Infof("get DefaultClass %d defaults found", len(defaultClasses)) return nil, nil, fmt.Errorf("%d default snapshot classes were found", len(defaultClasses)) } - glog.V(5).Infof("setDefaultSnapshotClass [%s]: default VolumeSnapshotClassName [%s]", snapshot.Name, defaultClasses[0].Name) + klog.V(5).Infof("setDefaultSnapshotClass [%s]: default VolumeSnapshotClassName [%s]", snapshot.Name, defaultClasses[0].Name) snapshotClone := snapshot.DeepCopy() snapshotClone.Spec.VolumeSnapshotClassName = &(defaultClasses[0].Name) newSnapshot, err := ctrl.clientset.VolumesnapshotV1alpha1().VolumeSnapshots(snapshotClone.Namespace).Update(snapshotClone) if err != nil { - glog.V(4).Infof("updating VolumeSnapshot[%s] default class failed %v", snapshotKey(snapshot), err) + klog.V(4).Infof("updating VolumeSnapshot[%s] default class failed %v", snapshotKey(snapshot), err) } _, updateErr := ctrl.storeSnapshotUpdate(newSnapshot) if updateErr != nil { // We will get an "snapshot update" event soon, this is not a big error - glog.V(4).Infof("setDefaultSnapshotClass [%s]: cannot update internal cache: %v", snapshotKey(snapshot), updateErr) + klog.V(4).Infof("setDefaultSnapshotClass [%s]: cannot update internal cache: %v", snapshotKey(snapshot), updateErr) } return defaultClasses[0], newSnapshot, nil @@ -992,10 +992,10 @@ func (ctrl *csiSnapshotController) addContentFinalizer(content *crdv1.VolumeSnap _, err = ctrl.storeContentUpdate(contentClone) if err != nil { - glog.Errorf("failed to update content store %v", err) + klog.Errorf("failed to update content store %v", err) } - glog.V(5).Infof("Added protection finalizer to volume snapshot content %s", content.Name) + klog.V(5).Infof("Added protection finalizer to volume snapshot content %s", content.Name) return nil } @@ -1011,10 +1011,10 @@ func (ctrl *csiSnapshotController) removeContentFinalizer(content *crdv1.VolumeS _, err = ctrl.storeContentUpdate(contentClone) if err != nil { - glog.Errorf("failed to update content store %v", err) + klog.Errorf("failed to update content store %v", err) } - glog.V(5).Infof("Removed protection finalizer from volume snapshot content %s", content.Name) + klog.V(5).Infof("Removed protection finalizer from volume snapshot content %s", content.Name) return nil } @@ -1029,10 +1029,10 @@ func (ctrl *csiSnapshotController) addSnapshotFinalizer(snapshot *crdv1.VolumeSn _, err = ctrl.storeSnapshotUpdate(snapshotClone) if err != nil { - glog.Errorf("failed to update snapshot store %v", err) + klog.Errorf("failed to update snapshot store %v", err) } - glog.V(5).Infof("Added protection finalizer to volume snapshot %s", snapshotKey(snapshot)) + klog.V(5).Infof("Added protection finalizer to volume snapshot %s", snapshotKey(snapshot)) return nil } @@ -1048,9 +1048,9 @@ func (ctrl *csiSnapshotController) removeSnapshotFinalizer(snapshot *crdv1.Volum _, err = ctrl.storeSnapshotUpdate(snapshotClone) if err != nil { - glog.Errorf("failed to update snapshot store %v", err) + klog.Errorf("failed to update snapshot store %v", err) } - glog.V(5).Infof("Removed protection finalizer from volume snapshot %s", snapshotKey(snapshot)) + klog.V(5).Infof("Removed protection finalizer from volume snapshot %s", snapshotKey(snapshot)) return nil } diff --git a/pkg/controller/snapshot_controller_base.go b/pkg/controller/snapshot_controller_base.go index 0fc387c94..8c3f9a4e3 100644 --- a/pkg/controller/snapshot_controller_base.go +++ b/pkg/controller/snapshot_controller_base.go @@ -20,7 +20,6 @@ import ( "fmt" "time" - "github.com/golang/glog" crdv1 "github.com/kubernetes-csi/external-snapshotter/pkg/apis/volumesnapshot/v1alpha1" clientset "github.com/kubernetes-csi/external-snapshotter/pkg/client/clientset/versioned" storageinformers "github.com/kubernetes-csi/external-snapshotter/pkg/client/informers/externalversions/volumesnapshot/v1alpha1" @@ -38,6 +37,7 @@ import ( "k8s.io/client-go/tools/cache" "k8s.io/client-go/tools/record" "k8s.io/client-go/util/workqueue" + "k8s.io/klog" "k8s.io/kubernetes/pkg/util/goroutinemap" ) @@ -88,7 +88,7 @@ func NewCSISnapshotController( snapshotNameUUIDLength int, ) *csiSnapshotController { broadcaster := record.NewBroadcaster() - broadcaster.StartLogging(glog.Infof) + broadcaster.StartLogging(klog.Infof) broadcaster.StartRecordingToSink(&corev1.EventSinkImpl{Interface: client.CoreV1().Events(v1.NamespaceAll)}) var eventRecorder record.EventRecorder eventRecorder = broadcaster.NewRecorder(scheme.Scheme, v1.EventSource{Component: fmt.Sprintf("csi-snapshotter %s", snapshotterName)}) @@ -144,11 +144,11 @@ func (ctrl *csiSnapshotController) Run(workers int, stopCh <-chan struct{}) { defer ctrl.snapshotQueue.ShutDown() defer ctrl.contentQueue.ShutDown() - glog.Infof("Starting CSI snapshotter") - defer glog.Infof("Shutting CSI snapshotter") + klog.Infof("Starting CSI snapshotter") + defer klog.Infof("Shutting CSI snapshotter") if !cache.WaitForCacheSync(stopCh, ctrl.snapshotListerSynced, ctrl.contentListerSynced, ctrl.classListerSynced, ctrl.pvcListerSynced) { - glog.Errorf("Cannot sync caches") + klog.Errorf("Cannot sync caches") return } @@ -171,10 +171,10 @@ func (ctrl *csiSnapshotController) enqueueSnapshotWork(obj interface{}) { if snapshot, ok := obj.(*crdv1.VolumeSnapshot); ok { objName, err := cache.DeletionHandlingMetaNamespaceKeyFunc(snapshot) if err != nil { - glog.Errorf("failed to get key from object: %v, %v", err, snapshot) + klog.Errorf("failed to get key from object: %v, %v", err, snapshot) return } - glog.V(5).Infof("enqueued %q for sync", objName) + klog.V(5).Infof("enqueued %q for sync", objName) ctrl.snapshotQueue.Add(objName) } } @@ -188,10 +188,10 @@ func (ctrl *csiSnapshotController) enqueueContentWork(obj interface{}) { if content, ok := obj.(*crdv1.VolumeSnapshotContent); ok { objName, err := cache.DeletionHandlingMetaNamespaceKeyFunc(content) if err != nil { - glog.Errorf("failed to get key from object: %v, %v", err, content) + klog.Errorf("failed to get key from object: %v, %v", err, content) return } - glog.V(5).Infof("enqueued %q for sync", objName) + klog.V(5).Infof("enqueued %q for sync", objName) ctrl.contentQueue.Add(objName) } } @@ -206,12 +206,12 @@ func (ctrl *csiSnapshotController) snapshotWorker() { } defer ctrl.snapshotQueue.Done(keyObj) key := keyObj.(string) - glog.V(5).Infof("snapshotWorker[%s]", key) + klog.V(5).Infof("snapshotWorker[%s]", key) namespace, name, err := cache.SplitMetaNamespaceKey(key) - glog.V(5).Infof("snapshotWorker: snapshot namespace [%s] name [%s]", namespace, name) + klog.V(5).Infof("snapshotWorker: snapshot namespace [%s] name [%s]", namespace, name) if err != nil { - glog.Errorf("error getting namespace & name of snapshot %q to get snapshot from informer: %v", key, err) + klog.Errorf("error getting namespace & name of snapshot %q to get snapshot from informer: %v", key, err) return false } snapshot, err := ctrl.snapshotLister.VolumeSnapshots(namespace).Get(name) @@ -220,30 +220,30 @@ func (ctrl *csiSnapshotController) snapshotWorker() { // been add/update/sync newSnapshot, err := ctrl.checkAndUpdateSnapshotClass(snapshot) if err == nil { - glog.V(5).Infof("passed checkAndUpdateSnapshotClass for snapshot %q", key) + klog.V(5).Infof("passed checkAndUpdateSnapshotClass for snapshot %q", key) ctrl.updateSnapshot(newSnapshot) } return false } if err != nil && !errors.IsNotFound(err) { - glog.V(2).Infof("error getting snapshot %q from informer: %v", key, err) + klog.V(2).Infof("error getting snapshot %q from informer: %v", key, err) return false } // The snapshot is not in informer cache, the event must have been "delete" vsObj, found, err := ctrl.snapshotStore.GetByKey(key) if err != nil { - glog.V(2).Infof("error getting snapshot %q from cache: %v", key, err) + klog.V(2).Infof("error getting snapshot %q from cache: %v", key, err) return false } if !found { // The controller has already processed the delete event and // deleted the snapshot from its cache - glog.V(2).Infof("deletion of snapshot %q was already processed", key) + klog.V(2).Infof("deletion of snapshot %q was already processed", key) return false } snapshot, ok := vsObj.(*crdv1.VolumeSnapshot) if !ok { - glog.Errorf("expected vs, got %+v", vsObj) + klog.Errorf("expected vs, got %+v", vsObj) return false } newSnapshot, err := ctrl.checkAndUpdateSnapshotClass(snapshot) @@ -255,7 +255,7 @@ func (ctrl *csiSnapshotController) snapshotWorker() { for { if quit := workFunc(); quit { - glog.Infof("snapshot worker queue shutting down") + klog.Infof("snapshot worker queue shutting down") return } } @@ -271,11 +271,11 @@ func (ctrl *csiSnapshotController) contentWorker() { } defer ctrl.contentQueue.Done(keyObj) key := keyObj.(string) - glog.V(5).Infof("contentWorker[%s]", key) + klog.V(5).Infof("contentWorker[%s]", key) _, name, err := cache.SplitMetaNamespaceKey(key) if err != nil { - glog.V(4).Infof("error getting name of snapshotContent %q to get snapshotContent from informer: %v", key, err) + klog.V(4).Infof("error getting name of snapshotContent %q to get snapshotContent from informer: %v", key, err) return false } content, err := ctrl.contentLister.Get(name) @@ -288,7 +288,7 @@ func (ctrl *csiSnapshotController) contentWorker() { return false } if !errors.IsNotFound(err) { - glog.V(2).Infof("error getting content %q from informer: %v", key, err) + klog.V(2).Infof("error getting content %q from informer: %v", key, err) return false } @@ -296,18 +296,18 @@ func (ctrl *csiSnapshotController) contentWorker() { // "delete" contentObj, found, err := ctrl.contentStore.GetByKey(key) if err != nil { - glog.V(2).Infof("error getting content %q from cache: %v", key, err) + klog.V(2).Infof("error getting content %q from cache: %v", key, err) return false } if !found { // The controller has already processed the delete event and // deleted the content from its cache - glog.V(2).Infof("deletion of content %q was already processed", key) + klog.V(2).Infof("deletion of content %q was already processed", key) return false } content, ok := contentObj.(*crdv1.VolumeSnapshotContent) if !ok { - glog.Errorf("expected content, got %+v", content) + klog.Errorf("expected content, got %+v", content) return false } ctrl.deleteContent(content) @@ -316,7 +316,7 @@ func (ctrl *csiSnapshotController) contentWorker() { for { if quit := workFunc(); quit { - glog.Infof("content worker queue shutting down") + klog.Infof("content worker queue shutting down") return } } @@ -352,26 +352,26 @@ func (ctrl *csiSnapshotController) checkAndUpdateSnapshotClass(snapshot *crdv1.V var err error newSnapshot := snapshot if className != nil { - glog.V(5).Infof("checkAndUpdateSnapshotClass [%s]: VolumeSnapshotClassName [%s]", snapshot.Name, *className) + klog.V(5).Infof("checkAndUpdateSnapshotClass [%s]: VolumeSnapshotClassName [%s]", snapshot.Name, *className) class, err = ctrl.GetSnapshotClass(*className) if err != nil { - glog.Errorf("checkAndUpdateSnapshotClass failed to getSnapshotClass %v", err) + klog.Errorf("checkAndUpdateSnapshotClass failed to getSnapshotClass %v", err) ctrl.updateSnapshotErrorStatusWithEvent(snapshot, v1.EventTypeWarning, "GetSnapshotClassFailed", fmt.Sprintf("Failed to get snapshot class with error %v", err)) return nil, err } } else { - glog.V(5).Infof("checkAndUpdateSnapshotClass [%s]: SetDefaultSnapshotClass", snapshot.Name) + klog.V(5).Infof("checkAndUpdateSnapshotClass [%s]: SetDefaultSnapshotClass", snapshot.Name) class, newSnapshot, err = ctrl.SetDefaultSnapshotClass(snapshot) if err != nil { - glog.Errorf("checkAndUpdateSnapshotClass failed to setDefaultClass %v", err) + klog.Errorf("checkAndUpdateSnapshotClass failed to setDefaultClass %v", err) ctrl.updateSnapshotErrorStatusWithEvent(snapshot, v1.EventTypeWarning, "SetDefaultSnapshotClassFailed", fmt.Sprintf("Failed to set default snapshot class with error %v", err)) return nil, err } } - glog.V(5).Infof("VolumeSnapshotClass Snapshotter [%s] Snapshot Controller snapshotterName [%s]", class.Snapshotter, ctrl.snapshotterName) + klog.V(5).Infof("VolumeSnapshotClass Snapshotter [%s] Snapshot Controller snapshotterName [%s]", class.Snapshotter, ctrl.snapshotterName) if class.Snapshotter != ctrl.snapshotterName { - glog.V(4).Infof("Skipping VolumeSnapshot %s for snapshotter [%s] in VolumeSnapshotClass because it does not match with the snapshotter for controller [%s]", snapshotKey(snapshot), class.Snapshotter, ctrl.snapshotterName) + klog.V(4).Infof("Skipping VolumeSnapshot %s for snapshotter [%s] in VolumeSnapshotClass because it does not match with the snapshotter for controller [%s]", snapshotKey(snapshot), class.Snapshotter, ctrl.snapshotterName) return nil, fmt.Errorf("volumeSnapshotClass does not match with the snapshotter for controller") } return newSnapshot, nil @@ -382,10 +382,10 @@ func (ctrl *csiSnapshotController) checkAndUpdateSnapshotClass(snapshot *crdv1.V func (ctrl *csiSnapshotController) updateSnapshot(snapshot *crdv1.VolumeSnapshot) { // Store the new snapshot version in the cache and do not process it if this is // an old version. - glog.V(5).Infof("updateSnapshot %q", snapshotKey(snapshot)) + klog.V(5).Infof("updateSnapshot %q", snapshotKey(snapshot)) newSnapshot, err := ctrl.storeSnapshotUpdate(snapshot) if err != nil { - glog.Errorf("%v", err) + klog.Errorf("%v", err) } if !newSnapshot { return @@ -395,9 +395,9 @@ func (ctrl *csiSnapshotController) updateSnapshot(snapshot *crdv1.VolumeSnapshot if errors.IsConflict(err) { // Version conflict error happens quite often and the controller // recovers from it easily. - glog.V(3).Infof("could not sync claim %q: %+v", snapshotKey(snapshot), err) + klog.V(3).Infof("could not sync claim %q: %+v", snapshotKey(snapshot), err) } else { - glog.Errorf("could not sync volume %q: %+v", snapshotKey(snapshot), err) + klog.Errorf("could not sync volume %q: %+v", snapshotKey(snapshot), err) } } } @@ -409,7 +409,7 @@ func (ctrl *csiSnapshotController) updateContent(content *crdv1.VolumeSnapshotCo // an old version. new, err := ctrl.storeContentUpdate(content) if err != nil { - glog.Errorf("%v", err) + klog.Errorf("%v", err) } if !new { return @@ -419,9 +419,9 @@ func (ctrl *csiSnapshotController) updateContent(content *crdv1.VolumeSnapshotCo if errors.IsConflict(err) { // Version conflict error happens quite often and the controller // recovers from it easily. - glog.V(3).Infof("could not sync content %q: %+v", content.Name, err) + klog.V(3).Infof("could not sync content %q: %+v", content.Name, err) } else { - glog.Errorf("could not sync content %q: %+v", content.Name, err) + klog.Errorf("could not sync content %q: %+v", content.Name, err) } } } @@ -429,34 +429,34 @@ func (ctrl *csiSnapshotController) updateContent(content *crdv1.VolumeSnapshotCo // deleteSnapshot runs in worker thread and handles "snapshot deleted" event. func (ctrl *csiSnapshotController) deleteSnapshot(snapshot *crdv1.VolumeSnapshot) { _ = ctrl.snapshotStore.Delete(snapshot) - glog.V(4).Infof("snapshot %q deleted", snapshotKey(snapshot)) + klog.V(4).Infof("snapshot %q deleted", snapshotKey(snapshot)) snapshotContentName := snapshot.Spec.SnapshotContentName if snapshotContentName == "" { - glog.V(5).Infof("deleteSnapshot[%q]: content not bound", snapshotKey(snapshot)) + klog.V(5).Infof("deleteSnapshot[%q]: content not bound", snapshotKey(snapshot)) return } // sync the content when its snapshot is deleted. Explicitly sync'ing the // content here in response to snapshot deletion prevents the content from // waiting until the next sync period for its Release. - glog.V(5).Infof("deleteSnapshot[%q]: scheduling sync of content %s", snapshotKey(snapshot), snapshotContentName) + klog.V(5).Infof("deleteSnapshot[%q]: scheduling sync of content %s", snapshotKey(snapshot), snapshotContentName) ctrl.contentQueue.Add(snapshotContentName) } // deleteContent runs in worker thread and handles "content deleted" event. func (ctrl *csiSnapshotController) deleteContent(content *crdv1.VolumeSnapshotContent) { _ = ctrl.contentStore.Delete(content) - glog.V(4).Infof("content %q deleted", content.Name) + klog.V(4).Infof("content %q deleted", content.Name) snapshotName := snapshotRefKey(content.Spec.VolumeSnapshotRef) if snapshotName == "" { - glog.V(5).Infof("deleteContent[%q]: content not bound", content.Name) + klog.V(5).Infof("deleteContent[%q]: content not bound", content.Name) return } // sync the snapshot when its content is deleted. Explicitly sync'ing the // snapshot here in response to content deletion prevents the snapshot from // waiting until the next sync period for its Release. - glog.V(5).Infof("deleteContent[%q]: scheduling sync of snapshot %s", content.Name, snapshotName) + klog.V(5).Infof("deleteContent[%q]: scheduling sync of snapshot %s", content.Name, snapshotName) ctrl.snapshotQueue.Add(snapshotName) } @@ -466,27 +466,27 @@ func (ctrl *csiSnapshotController) deleteContent(content *crdv1.VolumeSnapshotCo func (ctrl *csiSnapshotController) initializeCaches(snapshotLister storagelisters.VolumeSnapshotLister, contentLister storagelisters.VolumeSnapshotContentLister) { snapshotList, err := snapshotLister.List(labels.Everything()) if err != nil { - glog.Errorf("CSISnapshotController can't initialize caches: %v", err) + klog.Errorf("CSISnapshotController can't initialize caches: %v", err) return } for _, snapshot := range snapshotList { snapshotClone := snapshot.DeepCopy() if _, err = ctrl.storeSnapshotUpdate(snapshotClone); err != nil { - glog.Errorf("error updating volume snapshot cache: %v", err) + klog.Errorf("error updating volume snapshot cache: %v", err) } } contentList, err := contentLister.List(labels.Everything()) if err != nil { - glog.Errorf("CSISnapshotController can't initialize caches: %v", err) + klog.Errorf("CSISnapshotController can't initialize caches: %v", err) return } for _, content := range contentList { contentClone := content.DeepCopy() if _, err = ctrl.storeContentUpdate(contentClone); err != nil { - glog.Errorf("error updating volume snapshot content cache: %v", err) + klog.Errorf("error updating volume snapshot content cache: %v", err) } } - glog.V(4).Infof("controller initialized") + klog.V(4).Infof("controller initialized") } diff --git a/pkg/controller/util.go b/pkg/controller/util.go index b6d2ca3e9..75593d499 100644 --- a/pkg/controller/util.go +++ b/pkg/controller/util.go @@ -20,7 +20,6 @@ import ( "fmt" "strings" - "github.com/golang/glog" crdv1 "github.com/kubernetes-csi/external-snapshotter/pkg/apis/volumesnapshot/v1alpha1" "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/meta" @@ -29,6 +28,7 @@ import ( "k8s.io/apimachinery/pkg/util/validation" "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/cache" + "k8s.io/klog" "k8s.io/kubernetes/pkg/util/slice" "os" "strconv" @@ -104,7 +104,7 @@ func storeObjectUpdate(store cache.Store, obj interface{}, className string) (bo if !found { // This is a new object - glog.V(4).Infof("storeObjectUpdate: adding %s %q, version %s", className, objName, objAccessor.GetResourceVersion()) + klog.V(4).Infof("storeObjectUpdate: adding %s %q, version %s", className, objName, objAccessor.GetResourceVersion()) if err = store.Add(obj); err != nil { return false, fmt.Errorf("error adding %s %q to controller cache: %v", className, objName, err) } @@ -128,11 +128,11 @@ func storeObjectUpdate(store cache.Store, obj interface{}, className string) (bo // Throw away only older version, let the same version pass - we do want to // get periodic sync events. if oldObjResourceVersion > objResourceVersion { - glog.V(4).Infof("storeObjectUpdate: ignoring %s %q version %s", className, objName, objAccessor.GetResourceVersion()) + klog.V(4).Infof("storeObjectUpdate: ignoring %s %q version %s", className, objName, objAccessor.GetResourceVersion()) return false, nil } - glog.V(4).Infof("storeObjectUpdate updating %s %q with version %s", className, objName, objAccessor.GetResourceVersion()) + klog.V(4).Infof("storeObjectUpdate updating %s %q with version %s", className, objName, objAccessor.GetResourceVersion()) if err = store.Update(obj); err != nil { return false, fmt.Errorf("error updating %s %q in controller cache: %v", className, objName, err) } @@ -169,12 +169,12 @@ func verifyAndGetSecretNameAndNamespaceTemplate(secret deprecatedSecretParamsMap if t, ok := snapshotClassParams[secret.deprecatedSecretNameKey]; ok { nameTemplate = t numName++ - glog.Warning(deprecationWarning(secret.deprecatedSecretNameKey, secret.secretNameKey, "")) + klog.Warning(deprecationWarning(secret.deprecatedSecretNameKey, secret.secretNameKey, "")) } if t, ok := snapshotClassParams[secret.deprecatedSecretNamespaceKey]; ok { namespaceTemplate = t numNamespace++ - glog.Warning(deprecationWarning(secret.deprecatedSecretNamespaceKey, secret.secretNamespaceKey, "")) + klog.Warning(deprecationWarning(secret.deprecatedSecretNamespaceKey, secret.secretNamespaceKey, "")) } if t, ok := snapshotClassParams[secret.secretNameKey]; ok { nameTemplate = t @@ -249,7 +249,7 @@ func getSecretReference(snapshotClassParams map[string]string, snapContentName s if err != nil { return nil, fmt.Errorf("error resolving value %q: %v", namespaceTemplate, err) } - glog.V(4).Infof("GetSecretReference namespaceTemplate %s, namespaceParams: %+v, resolved %s", namespaceTemplate, namespaceParams, resolvedNamespace) + klog.V(4).Infof("GetSecretReference namespaceTemplate %s, namespaceParams: %+v, resolved %s", namespaceTemplate, namespaceParams, resolvedNamespace) if len(validation.IsDNS1123Label(resolvedNamespace)) > 0 { if namespaceTemplate != resolvedNamespace { @@ -282,7 +282,7 @@ func getSecretReference(snapshotClassParams map[string]string, snapContentName s } ref.Name = resolvedName - glog.V(4).Infof("GetSecretReference validated Secret: %+v", ref) + klog.V(4).Infof("GetSecretReference validated Secret: %+v", ref) return ref, nil }