Skip to content

Commit

Permalink
klog rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
pawanpraka1 committed Jun 29, 2020
1 parent 6a472d9 commit b9e893f
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 37 deletions.
4 changes: 2 additions & 2 deletions pkg/driver/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ func NewNode(d *CSIDriver) csi.NodeServer {
go func() {
err := backup.Start(&ControllerMutex, stopCh)
if err != nil {
logrus.Fatalf("Failed to start ZFS volume snapshot management controller: %s", err.Error())
klog.Fatalf("Failed to start ZFS volume snapshot management controller: %s", err.Error())
}
}()

// start the restore controller
go func() {
err := restore.Start(&ControllerMutex, stopCh)
if err != nil {
logrus.Fatalf("Failed to start ZFS volume snapshot management controller: %s", err.Error())
klog.Fatalf("Failed to start ZFS volume snapshot management controller: %s", err.Error())
}
}()

Expand Down
21 changes: 10 additions & 11 deletions pkg/mgmt/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ package backup

import (
"fmt"
"k8s.io/klog"
"time"

"github.com/Sirupsen/logrus"

apis "github.com/openebs/zfs-localpv/pkg/apis/openebs.io/zfs/v1"
zfs "github.com/openebs/zfs-localpv/pkg/zfs"
k8serror "k8s.io/apimachinery/pkg/api/errors"
Expand Down Expand Up @@ -103,7 +102,7 @@ func (c *BackupController) addBkp(obj interface{}) {
if zfs.NodeID != bkp.Spec.OwnerNodeID {
return
}
logrus.Infof("Got add event for Bkp %s@%s", bkp.Spec.VolumeName, bkp.Spec.SnapName)
klog.Infof("Got add event for Bkp %s@%s", bkp.Spec.VolumeName, bkp.Spec.SnapName)
c.enqueueBkp(bkp)
}

Expand All @@ -121,7 +120,7 @@ func (c *BackupController) updateBkp(oldObj, newObj interface{}) {
}

if c.isDeletionCandidate(newBkp) {
logrus.Infof("Got update event for Bkp %s@%s", newBkp.Spec.VolumeName, newBkp.Spec.SnapName)
klog.Infof("Got update event for Bkp %s@%s", newBkp.Spec.VolumeName, newBkp.Spec.SnapName)
c.enqueueBkp(newBkp)
}
}
Expand All @@ -146,7 +145,7 @@ func (c *BackupController) deleteBkp(obj interface{}) {
return
}

logrus.Infof("Got delete event for Bkp %s@%s", bkp.Spec.VolumeName, bkp.Spec.SnapName)
klog.Infof("Got delete event for Bkp %s@%s", bkp.Spec.VolumeName, bkp.Spec.SnapName)
c.enqueueBkp(bkp)
}

Expand All @@ -159,23 +158,23 @@ func (c *BackupController) Run(threadiness int, stopCh <-chan struct{}) error {
defer c.workqueue.ShutDown()

// Start the informer factories to begin populating the informer caches
logrus.Info("Starting Bkp controller")
klog.Info("Starting Bkp controller")

// Wait for the k8s caches to be synced before starting workers
logrus.Info("Waiting for informer caches to sync")
klog.Info("Waiting for informer caches to sync")
if ok := cache.WaitForCacheSync(stopCh, c.bkpSynced); !ok {
return fmt.Errorf("failed to wait for caches to sync")
}
logrus.Info("Starting Bkp workers")
klog.Info("Starting Bkp workers")
// Launch worker to process Bkp resources
// Threadiness will decide the number of workers you want to launch to process work items from queue
for i := 0; i < threadiness; i++ {
go wait.Until(c.runWorker, time.Second, stopCh)
}

logrus.Info("Started Bkp workers")
klog.Info("Started Bkp workers")
<-stopCh
logrus.Info("Shutting down Bkp workers")
klog.Info("Shutting down Bkp workers")

return nil
}
Expand Down Expand Up @@ -231,7 +230,7 @@ func (c *BackupController) processNextWorkItem() bool {
// Finally, if no error occurs we Forget this item so it does not
// get queued again until another change happens.
c.workqueue.Forget(obj)
logrus.Infof("Successfully synced '%s'", key)
klog.Infof("Successfully synced '%s'", key)
return nil
}(obj)

Expand Down
6 changes: 3 additions & 3 deletions pkg/mgmt/backup/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package backup

import (
"github.com/Sirupsen/logrus"
"k8s.io/klog"

clientset "github.com/openebs/zfs-localpv/pkg/generated/clientset/internalclientset"
openebsScheme "github.com/openebs/zfs-localpv/pkg/generated/clientset/internalclientset/scheme"
Expand Down Expand Up @@ -105,9 +105,9 @@ func (cb *BackupControllerBuilder) withWorkqueueRateLimiting() *BackupController

// withRecorder adds recorder to controller object.
func (cb *BackupControllerBuilder) withRecorder(ks kubernetes.Interface) *BackupControllerBuilder {
logrus.Infof("Creating event broadcaster")
klog.Infof("Creating event broadcaster")
eventBroadcaster := record.NewBroadcaster()
eventBroadcaster.StartLogging(logrus.Infof)
eventBroadcaster.StartLogging(klog.Infof)
eventBroadcaster.StartRecordingToSink(&typedcorev1.EventSinkImpl{Interface: ks.CoreV1().Events("")})
recorder := eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: controllerAgentName})
cb.BackupController.recorder = recorder
Expand Down
4 changes: 2 additions & 2 deletions pkg/mgmt/backup/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package backup
import (
"sync"

"github.com/Sirupsen/logrus"
"github.com/pkg/errors"
"k8s.io/klog"

"time"

Expand Down Expand Up @@ -94,7 +94,7 @@ func Start(controllerMtx *sync.RWMutex, stopCh <-chan struct{}) error {
func getClusterConfig(kubeconfig string) (*rest.Config, error) {
cfg, err := rest.InClusterConfig()
if err != nil {
logrus.Errorf("Failed to get k8s Incluster config. %+v", err)
klog.Errorf("Failed to get k8s Incluster config. %+v", err)
if kubeconfig == "" {
return nil, errors.Wrap(err, "kubeconfig is empty")
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/mgmt/restore/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ limitations under the License.
package restore

import (
"github.com/Sirupsen/logrus"
"k8s.io/klog"

clientset "github.com/openebs/zfs-localpv/pkg/generated/clientset/internalclientset"
openebsScheme "github.com/openebs/zfs-localpv/pkg/generated/clientset/internalclientset/scheme"
Expand Down Expand Up @@ -105,9 +105,9 @@ func (cb *RestoreControllerBuilder) withWorkqueueRateLimiting() *RestoreControll

// withRecorder adds recorder to controller object.
func (cb *RestoreControllerBuilder) withRecorder(ks kubernetes.Interface) *RestoreControllerBuilder {
logrus.Infof("Creating event broadcaster")
klog.Infof("Creating event broadcaster")
eventBroadcaster := record.NewBroadcaster()
eventBroadcaster.StartLogging(logrus.Infof)
eventBroadcaster.StartLogging(klog.Infof)
eventBroadcaster.StartRecordingToSink(&typedcorev1.EventSinkImpl{Interface: ks.CoreV1().Events("")})
recorder := eventBroadcaster.NewRecorder(scheme.Scheme, corev1.EventSource{Component: controllerAgentName})
cb.RestoreController.recorder = recorder
Expand Down
20 changes: 10 additions & 10 deletions pkg/mgmt/restore/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"fmt"
"time"

"github.com/Sirupsen/logrus"
"k8s.io/klog"

apis "github.com/openebs/zfs-localpv/pkg/apis/openebs.io/zfs/v1"
zfs "github.com/openebs/zfs-localpv/pkg/zfs"
Expand Down Expand Up @@ -103,7 +103,7 @@ func (c *RestoreController) addRestore(obj interface{}) {
if zfs.NodeID != rstr.Spec.OwnerNodeID {
return
}
logrus.Infof("Got add event for Restore %s", rstr.Spec.VolumeName)
klog.Infof("Got add event for Restore %s", rstr.Spec.VolumeName)
c.enqueueRestore(rstr)
}

Expand All @@ -121,7 +121,7 @@ func (c *RestoreController) updateRestore(oldObj, newObj interface{}) {
}

if c.isDeletionCandidate(newRestore) {
logrus.Infof("Got update event for Restore %s", newRestore.Spec.VolumeName)
klog.Infof("Got update event for Restore %s", newRestore.Spec.VolumeName)
c.enqueueRestore(newRestore)
}
}
Expand All @@ -146,7 +146,7 @@ func (c *RestoreController) deleteRestore(obj interface{}) {
return
}

logrus.Infof("Got delete event for Restore %s", rstr.Spec.VolumeName)
klog.Infof("Got delete event for Restore %s", rstr.Spec.VolumeName)
c.enqueueRestore(rstr)
}

Expand All @@ -159,23 +159,23 @@ func (c *RestoreController) Run(threadiness int, stopCh <-chan struct{}) error {
defer c.workqueue.ShutDown()

// Start the informer factories to begin populating the informer caches
logrus.Info("Starting Restore controller")
klog.Info("Starting Restore controller")

// Wait for the k8s caches to be synced before starting workers
logrus.Info("Waiting for informer caches to sync")
klog.Info("Waiting for informer caches to sync")
if ok := cache.WaitForCacheSync(stopCh, c.rstrSynced); !ok {
return fmt.Errorf("failed to wait for caches to sync")
}
logrus.Info("Starting Restore workers")
klog.Info("Starting Restore workers")
// Launch worker to process Restore resources
// Threadiness will decide the number of workers you want to launch to process work items from queue
for i := 0; i < threadiness; i++ {
go wait.Until(c.runWorker, time.Second, stopCh)
}

logrus.Info("Started Restore workers")
klog.Info("Started Restore workers")
<-stopCh
logrus.Info("Shutting down Restore workers")
klog.Info("Shutting down Restore workers")

return nil
}
Expand Down Expand Up @@ -231,7 +231,7 @@ func (c *RestoreController) processNextWorkItem() bool {
// Finally, if no error occurs we Forget this item so it does not
// get queued again until another change happens.
c.workqueue.Forget(obj)
logrus.Infof("Successfully synced '%s'", key)
klog.Infof("Successfully synced '%s'", key)
return nil
}(obj)

Expand Down
4 changes: 2 additions & 2 deletions pkg/mgmt/restore/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package restore
import (
"sync"

"github.com/Sirupsen/logrus"
"github.com/pkg/errors"
"k8s.io/klog"

"time"

Expand Down Expand Up @@ -94,7 +94,7 @@ func Start(controllerMtx *sync.RWMutex, stopCh <-chan struct{}) error {
func getClusterConfig(kubeconfig string) (*rest.Config, error) {
cfg, err := rest.InClusterConfig()
if err != nil {
logrus.Errorf("Failed to get k8s Incluster config. %+v", err)
klog.Errorf("Failed to get k8s Incluster config. %+v", err)
if kubeconfig == "" {
return nil, errors.Wrap(err, "kubeconfig is empty")
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/zfs/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func UpdateBkpInfo(bkp *apis.ZFSBackup, status apis.ZFSBackupStatus) error {
newBkp.Status = status

if err != nil {
logrus.Errorf("Update snapshot failed %s err: %s", bkp.Spec.VolumeName, err.Error())
klog.Errorf("Update snapshot failed %s err: %s", bkp.Spec.VolumeName, err.Error())
return err
}

Expand All @@ -283,7 +283,7 @@ func UpdateRestoreInfo(rstr *apis.ZFSRestore, status apis.ZFSRestoreStatus) erro
newRstr.Status = status

if err != nil {
logrus.Errorf("Update snapshot failed %s err: %s", rstr.Spec.VolumeName, err.Error())
klog.Errorf("Update snapshot failed %s err: %s", rstr.Spec.VolumeName, err.Error())
return err
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/zfs/zfs_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ func CreateBackup(bkp *apis.ZFSBackup) error {
out, err := cmd.CombinedOutput()

if err != nil {
logrus.Errorf(
klog.Errorf(
"zfs: could not backup the volume %v cmd %v error: %s", volume, args, string(out),
)
}
Expand All @@ -696,7 +696,7 @@ func CreateRestore(rstr *apis.ZFSRestore) error {
out, err := cmd.CombinedOutput()

if err != nil {
logrus.Errorf(
klog.Errorf(
"zfs: could not restore the volume %v cmd %v error: %s", volume, args, string(out),
)
}
Expand Down

0 comments on commit b9e893f

Please sign in to comment.