Skip to content

Commit

Permalink
fixing golint
Browse files Browse the repository at this point in the history
Signed-off-by: Pawan <pawan@mayadata.io>
  • Loading branch information
pawanpraka1 committed Jul 13, 2020
1 parent 1b4f429 commit cfde926
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 85 deletions.
26 changes: 12 additions & 14 deletions pkg/mgmt/backup/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ import (
)

// isDeletionCandidate checks if a zfs backup is a deletion candidate.
func (c *BackupController) isDeletionCandidate(bkp *apis.ZFSBackup) bool {
func (c *BkpController) isDeletionCandidate(bkp *apis.ZFSBackup) bool {
return bkp.ObjectMeta.DeletionTimestamp != nil
}

// syncHandler compares the actual state with the desired, and attempts to
// converge the two.
func (c *BackupController) syncHandler(key string) error {
func (c *BkpController) syncHandler(key string) error {
// Convert the namespace/name string into a distinct namespace and name
namespace, name, err := cache.SplitMetaNamespaceKey(key)
if err != nil {
Expand All @@ -61,7 +61,7 @@ func (c *BackupController) syncHandler(key string) error {
// enqueueBkp takes a ZFSBackup resource and converts it into a namespace/name
// string which is then put onto the work queue. This method should *not* be
// passed resources of any type other than ZFSBackup.
func (c *BackupController) enqueueBkp(obj interface{}) {
func (c *BkpController) enqueueBkp(obj interface{}) {
var key string
var err error
if key, err = cache.MetaNamespaceKeyFunc(obj); err != nil {
Expand All @@ -73,12 +73,10 @@ func (c *BackupController) enqueueBkp(obj interface{}) {

// synBkp is the function which tries to converge to a desired state for the
// ZFSBackup
func (c *BackupController) syncBkp(bkp *apis.ZFSBackup) error {
var err error
func (c *BkpController) syncBkp(bkp *apis.ZFSBackup) error {
var err error = nil
// ZFSBackup should be deleted. Check if deletion timestamp is set
if c.isDeletionCandidate(bkp) {
return nil
} else {
if !c.isDeletionCandidate(bkp) {
// if finalizer is not set then it means we are creating
// the zfs backup.
if bkp.Status == apis.BKPZFSStatusInit {
Expand All @@ -92,7 +90,7 @@ func (c *BackupController) syncBkp(bkp *apis.ZFSBackup) error {
}

// addBkp is the add event handler for ZFSBackup
func (c *BackupController) addBkp(obj interface{}) {
func (c *BkpController) addBkp(obj interface{}) {
bkp, ok := obj.(*apis.ZFSBackup)
if !ok {
runtime.HandleError(fmt.Errorf("Couldn't get bkp object %#v", obj))
Expand All @@ -107,7 +105,7 @@ func (c *BackupController) addBkp(obj interface{}) {
}

// updateBkp is the update event handler for ZFSBackup
func (c *BackupController) updateBkp(oldObj, newObj interface{}) {
func (c *BkpController) updateBkp(oldObj, newObj interface{}) {

newBkp, ok := newObj.(*apis.ZFSBackup)
if !ok {
Expand All @@ -126,7 +124,7 @@ func (c *BackupController) updateBkp(oldObj, newObj interface{}) {
}

// deleteBkp is the delete event handler for ZFSBackup
func (c *BackupController) deleteBkp(obj interface{}) {
func (c *BkpController) deleteBkp(obj interface{}) {
bkp, ok := obj.(*apis.ZFSBackup)
if !ok {
tombstone, ok := obj.(cache.DeletedFinalStateUnknown)
Expand All @@ -153,7 +151,7 @@ func (c *BackupController) deleteBkp(obj interface{}) {
// as syncing informer caches and starting workers. It will block until stopCh
// is closed, at which point it will shutdown the workqueue and wait for
// workers to finish processing their current work items.
func (c *BackupController) Run(threadiness int, stopCh <-chan struct{}) error {
func (c *BkpController) Run(threadiness int, stopCh <-chan struct{}) error {
defer runtime.HandleCrash()
defer c.workqueue.ShutDown()

Expand Down Expand Up @@ -182,14 +180,14 @@ func (c *BackupController) Run(threadiness int, stopCh <-chan struct{}) error {
// runWorker is a long-running function that will continually call the
// processNextWorkItem function in order to read and process a message on the
// workqueue.
func (c *BackupController) runWorker() {
func (c *BkpController) runWorker() {
for c.processNextWorkItem() {
}
}

// processNextWorkItem will read a single work item off the workqueue and
// attempt to process it, by calling the syncHandler.
func (c *BackupController) processNextWorkItem() bool {
func (c *BkpController) processNextWorkItem() bool {
obj, shutdown := c.workqueue.Get()

if shutdown {
Expand Down
54 changes: 27 additions & 27 deletions pkg/mgmt/backup/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ import (

const controllerAgentName = "zfsbackup-controller"

// BackupController is the controller implementation for Bkp resources
type BackupController struct {
// BkpController is the controller implementation for Bkp resources
type BkpController struct {
// kubeclientset is a standard kubernetes clientset
kubeclientset kubernetes.Interface

Expand All @@ -59,78 +59,78 @@ type BackupController struct {
recorder record.EventRecorder
}

// BackupControllerBuilder is the builder object for controller.
type BackupControllerBuilder struct {
BackupController *BackupController
// BkpControllerBuilder is the builder object for controller.
type BkpControllerBuilder struct {
BkpController *BkpController
}

// NewBackupControllerBuilder returns an empty instance of controller builder.
func NewBackupControllerBuilder() *BackupControllerBuilder {
return &BackupControllerBuilder{
BackupController: &BackupController{},
// NewBkpControllerBuilder returns an empty instance of controller builder.
func NewBkpControllerBuilder() *BkpControllerBuilder {
return &BkpControllerBuilder{
BkpController: &BkpController{},
}
}

// withKubeClient fills kube client to controller object.
func (cb *BackupControllerBuilder) withKubeClient(ks kubernetes.Interface) *BackupControllerBuilder {
cb.BackupController.kubeclientset = ks
func (cb *BkpControllerBuilder) withKubeClient(ks kubernetes.Interface) *BkpControllerBuilder {
cb.BkpController.kubeclientset = ks
return cb
}

// withOpenEBSClient fills openebs client to controller object.
func (cb *BackupControllerBuilder) withOpenEBSClient(cs clientset.Interface) *BackupControllerBuilder {
cb.BackupController.clientset = cs
func (cb *BkpControllerBuilder) withOpenEBSClient(cs clientset.Interface) *BkpControllerBuilder {
cb.BkpController.clientset = cs
return cb
}

// withBkpLister fills bkp lister to controller object.
func (cb *BackupControllerBuilder) withBkpLister(sl informers.SharedInformerFactory) *BackupControllerBuilder {
func (cb *BkpControllerBuilder) withBkpLister(sl informers.SharedInformerFactory) *BkpControllerBuilder {
bkpInformer := sl.Zfs().V1().ZFSBackups()
cb.BackupController.bkpLister = bkpInformer.Lister()
cb.BkpController.bkpLister = bkpInformer.Lister()
return cb
}

// withBkpSynced adds object sync information in cache to controller object.
func (cb *BackupControllerBuilder) withBkpSynced(sl informers.SharedInformerFactory) *BackupControllerBuilder {
func (cb *BkpControllerBuilder) withBkpSynced(sl informers.SharedInformerFactory) *BkpControllerBuilder {
bkpInformer := sl.Zfs().V1().ZFSBackups()
cb.BackupController.bkpSynced = bkpInformer.Informer().HasSynced
cb.BkpController.bkpSynced = bkpInformer.Informer().HasSynced
return cb
}

// withWorkqueue adds workqueue to controller object.
func (cb *BackupControllerBuilder) withWorkqueueRateLimiting() *BackupControllerBuilder {
cb.BackupController.workqueue = workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "Bkp")
func (cb *BkpControllerBuilder) withWorkqueueRateLimiting() *BkpControllerBuilder {
cb.BkpController.workqueue = workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "Bkp")
return cb
}

// withRecorder adds recorder to controller object.
func (cb *BackupControllerBuilder) withRecorder(ks kubernetes.Interface) *BackupControllerBuilder {
func (cb *BkpControllerBuilder) withRecorder(ks kubernetes.Interface) *BkpControllerBuilder {
klog.Infof("Creating event broadcaster")
eventBroadcaster := record.NewBroadcaster()
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
cb.BkpController.recorder = recorder
return cb
}

// withEventHandler adds event handlers controller object.
func (cb *BackupControllerBuilder) withEventHandler(cvcInformerFactory informers.SharedInformerFactory) *BackupControllerBuilder {
func (cb *BkpControllerBuilder) withEventHandler(cvcInformerFactory informers.SharedInformerFactory) *BkpControllerBuilder {
cvcInformer := cvcInformerFactory.Zfs().V1().ZFSBackups()
// Set up an event handler for when Bkp resources change
cvcInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: cb.BackupController.addBkp,
UpdateFunc: cb.BackupController.updateBkp,
DeleteFunc: cb.BackupController.deleteBkp,
AddFunc: cb.BkpController.addBkp,
UpdateFunc: cb.BkpController.updateBkp,
DeleteFunc: cb.BkpController.deleteBkp,
})
return cb
}

// Build returns a controller instance.
func (cb *BackupControllerBuilder) Build() (*BackupController, error) {
func (cb *BkpControllerBuilder) Build() (*BkpController, error) {
err := openebsScheme.AddToScheme(scheme.Scheme)
if err != nil {
return nil, err
}
return cb.BackupController, nil
return cb.BkpController, nil
}
2 changes: 1 addition & 1 deletion pkg/mgmt/backup/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func Start(controllerMtx *sync.RWMutex, stopCh <-chan struct{}) error {
// This lock is used to serialize the AddToScheme call of all controllers.
controllerMtx.Lock()

controller, err := NewBackupControllerBuilder().
controller, err := NewBkpControllerBuilder().
withKubeClient(kubeClient).
withOpenEBSClient(openebsClient).
withBkpSynced(bkpInformerFactory).
Expand Down
54 changes: 27 additions & 27 deletions pkg/mgmt/restore/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ import (

const controllerAgentName = "zfsrestore-controller"

// RestoreController is the controller implementation for Restore resources
type RestoreController struct {
// RstrController is the controller implementation for Restore resources
type RstrController struct {
// kubeclientset is a standard kubernetes clientset
kubeclientset kubernetes.Interface

Expand All @@ -59,78 +59,78 @@ type RestoreController struct {
recorder record.EventRecorder
}

// RestoreControllerBuilder is the builder object for controller.
type RestoreControllerBuilder struct {
RestoreController *RestoreController
// RstrControllerBuilder is the builder object for controller.
type RstrControllerBuilder struct {
RstrController *RstrController
}

// NewRestoreControllerBuilder returns an empty instance of controller builder.
func NewRestoreControllerBuilder() *RestoreControllerBuilder {
return &RestoreControllerBuilder{
RestoreController: &RestoreController{},
// NewRstrControllerBuilder returns an empty instance of controller builder.
func NewRstrControllerBuilder() *RstrControllerBuilder {
return &RstrControllerBuilder{
RstrController: &RstrController{},
}
}

// withKubeClient fills kube client to controller object.
func (cb *RestoreControllerBuilder) withKubeClient(ks kubernetes.Interface) *RestoreControllerBuilder {
cb.RestoreController.kubeclientset = ks
func (cb *RstrControllerBuilder) withKubeClient(ks kubernetes.Interface) *RstrControllerBuilder {
cb.RstrController.kubeclientset = ks
return cb
}

// withOpenEBSClient fills openebs client to controller object.
func (cb *RestoreControllerBuilder) withOpenEBSClient(cs clientset.Interface) *RestoreControllerBuilder {
cb.RestoreController.clientset = cs
func (cb *RstrControllerBuilder) withOpenEBSClient(cs clientset.Interface) *RstrControllerBuilder {
cb.RstrController.clientset = cs
return cb
}

// withRestoreLister fills rstr lister to controller object.
func (cb *RestoreControllerBuilder) withRestoreLister(sl informers.SharedInformerFactory) *RestoreControllerBuilder {
func (cb *RstrControllerBuilder) withRestoreLister(sl informers.SharedInformerFactory) *RstrControllerBuilder {
rstrInformer := sl.Zfs().V1().ZFSRestores()
cb.RestoreController.rstrLister = rstrInformer.Lister()
cb.RstrController.rstrLister = rstrInformer.Lister()
return cb
}

// withRestoreSynced adds object sync information in cache to controller object.
func (cb *RestoreControllerBuilder) withRestoreSynced(sl informers.SharedInformerFactory) *RestoreControllerBuilder {
func (cb *RstrControllerBuilder) withRestoreSynced(sl informers.SharedInformerFactory) *RstrControllerBuilder {
rstrInformer := sl.Zfs().V1().ZFSRestores()
cb.RestoreController.rstrSynced = rstrInformer.Informer().HasSynced
cb.RstrController.rstrSynced = rstrInformer.Informer().HasSynced
return cb
}

// withWorkqueue adds workqueue to controller object.
func (cb *RestoreControllerBuilder) withWorkqueueRateLimiting() *RestoreControllerBuilder {
cb.RestoreController.workqueue = workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "Restore")
func (cb *RstrControllerBuilder) withWorkqueueRateLimiting() *RstrControllerBuilder {
cb.RstrController.workqueue = workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "Restore")
return cb
}

// withRecorder adds recorder to controller object.
func (cb *RestoreControllerBuilder) withRecorder(ks kubernetes.Interface) *RestoreControllerBuilder {
func (cb *RstrControllerBuilder) withRecorder(ks kubernetes.Interface) *RstrControllerBuilder {
klog.Infof("Creating event broadcaster")
eventBroadcaster := record.NewBroadcaster()
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
cb.RstrController.recorder = recorder
return cb
}

// withEventHandler adds event handlers controller object.
func (cb *RestoreControllerBuilder) withEventHandler(cvcInformerFactory informers.SharedInformerFactory) *RestoreControllerBuilder {
func (cb *RstrControllerBuilder) withEventHandler(cvcInformerFactory informers.SharedInformerFactory) *RstrControllerBuilder {
cvcInformer := cvcInformerFactory.Zfs().V1().ZFSRestores()
// Set up an event handler for when Restore resources change
cvcInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: cb.RestoreController.addRestore,
UpdateFunc: cb.RestoreController.updateRestore,
DeleteFunc: cb.RestoreController.deleteRestore,
AddFunc: cb.RstrController.addRestore,
UpdateFunc: cb.RstrController.updateRestore,
DeleteFunc: cb.RstrController.deleteRestore,
})
return cb
}

// Build returns a controller instance.
func (cb *RestoreControllerBuilder) Build() (*RestoreController, error) {
func (cb *RstrControllerBuilder) Build() (*RstrController, error) {
err := openebsScheme.AddToScheme(scheme.Scheme)
if err != nil {
return nil, err
}
return cb.RestoreController, nil
return cb.RstrController, nil
}
Loading

0 comments on commit cfde926

Please sign in to comment.