@@ -108,17 +108,17 @@ func RunController(masterURL, kubeconfig, imageName, namespace, prefix string,
108
108
}()
109
109
110
110
cfg , err := clientcmd .BuildConfigFromFlags (masterURL , kubeconfig )
111
- if nil != err {
111
+ if err != nil {
112
112
klog .Fatalf ("Failed to create config: %v" , err )
113
113
}
114
114
115
115
kubeClient , err := kubernetes .NewForConfig (cfg )
116
- if nil != err {
116
+ if err != nil {
117
117
klog .Fatalf ("Failed to create client: %v" , err )
118
118
}
119
119
120
120
dynClient , err := dynamic .NewForConfig (cfg )
121
- if nil != err {
121
+ if err != nil {
122
122
klog .Fatalf ("Failed to create dynamic client: %v" , err )
123
123
}
124
124
@@ -224,7 +224,7 @@ func RunController(masterURL, kubeconfig, imageName, namespace, prefix string,
224
224
kubeInformerFactory .Start (stopCh )
225
225
dynInformerFactory .Start (stopCh )
226
226
227
- if err = c .run (stopCh ); nil != err {
227
+ if err = c .run (stopCh ); err != nil {
228
228
klog .Fatalf ("Failed to run controller: %v" , err )
229
229
}
230
230
}
@@ -239,29 +239,29 @@ func (c *controller) addNotification(keyToCall, objType, namespace, name string)
239
239
c .mu .Lock ()
240
240
defer c .mu .Unlock ()
241
241
s := c .notifyMap [key ]
242
- if nil == s {
242
+ if s == nil {
243
243
s = & stringSet {make (map [string ]empty )}
244
244
c .notifyMap [key ] = s
245
245
}
246
246
s .set [keyToCall ] = empty {}
247
247
s = c .cleanupMap [keyToCall ]
248
- if nil == s {
248
+ if s == nil {
249
249
s = & stringSet {make (map [string ]empty )}
250
250
c .cleanupMap [keyToCall ] = s
251
251
}
252
252
s .set [key ] = empty {}
253
253
}
254
254
255
- func (c * controller ) cleanupNofications (keyToCall string ) {
255
+ func (c * controller ) cleanupNotifications (keyToCall string ) {
256
256
c .mu .Lock ()
257
257
defer c .mu .Unlock ()
258
258
s := c .cleanupMap [keyToCall ]
259
- if nil == s {
259
+ if s == nil {
260
260
return
261
261
}
262
262
for key := range s .set {
263
263
t := c .notifyMap [key ]
264
- if nil == t {
264
+ if t == nil {
265
265
continue
266
266
}
267
267
delete (t .set , keyToCall )
@@ -291,11 +291,11 @@ func translateObject(obj interface{}) metav1.Object {
291
291
292
292
func (c * controller ) handleMapped (obj interface {}, objType string ) {
293
293
object := translateObject (obj )
294
- if nil == object {
294
+ if object == nil {
295
295
return
296
296
}
297
297
var key string
298
- if 0 == len (object .GetNamespace ()) {
298
+ if len (object .GetNamespace ()) == 0 {
299
299
key = objType + "/" + object .GetName ()
300
300
} else {
301
301
key = objType + "/" + object .GetNamespace () + "/" + object .GetName ()
@@ -312,7 +312,7 @@ func (c *controller) handleMapped(obj interface{}, objType string) {
312
312
func (c * controller ) handlePVC (obj interface {}) {
313
313
c .handleMapped (obj , "pvc" )
314
314
object := translateObject (obj )
315
- if nil == object {
315
+ if object == nil {
316
316
return
317
317
}
318
318
if c .populatorNamespace != object .GetNamespace () {
@@ -366,7 +366,7 @@ func (c *controller) runWorker() {
366
366
parts := strings .Split (key , "/" )
367
367
switch parts [0 ] {
368
368
case "pvc" :
369
- if 3 != len (parts ) {
369
+ if len (parts ) != 3 {
370
370
utilruntime .HandleError (fmt .Errorf ("invalid resource key: %s" , key ))
371
371
return nil
372
372
}
@@ -375,7 +375,7 @@ func (c *controller) runWorker() {
375
375
utilruntime .HandleError (fmt .Errorf ("invalid resource key: %s" , key ))
376
376
return nil
377
377
}
378
- if nil != err {
378
+ if err != nil {
379
379
c .workqueue .AddRateLimited (key )
380
380
return fmt .Errorf ("error syncing '%s': %s, requeuing" , key , err .Error ())
381
381
}
@@ -389,7 +389,7 @@ func (c *controller) runWorker() {
389
389
return
390
390
}
391
391
err := processNextWorkItem (obj )
392
- if nil != err {
392
+ if err != nil {
393
393
utilruntime .HandleError (err )
394
394
}
395
395
}
@@ -405,7 +405,7 @@ func (c *controller) syncPvc(ctx context.Context, key, pvcNamespace, pvcName str
405
405
406
406
var pvc * corev1.PersistentVolumeClaim
407
407
pvc , err = c .pvcLister .PersistentVolumeClaims (pvcNamespace ).Get (pvcName )
408
- if nil != err {
408
+ if err != nil {
409
409
if errors .IsNotFound (err ) {
410
410
utilruntime .HandleError (fmt .Errorf ("pvc '%s' in work queue no longer exists" , key ))
411
411
return nil
@@ -414,7 +414,7 @@ func (c *controller) syncPvc(ctx context.Context, key, pvcNamespace, pvcName str
414
414
}
415
415
416
416
dataSourceRef := pvc .Spec .DataSourceRef
417
- if nil == dataSourceRef {
417
+ if dataSourceRef == nil {
418
418
// Ignore PVCs without a datasource
419
419
return nil
420
420
}
@@ -426,7 +426,7 @@ func (c *controller) syncPvc(ctx context.Context, key, pvcNamespace, pvcName str
426
426
427
427
var unstructured * unstructured.Unstructured
428
428
unstructured , err = c .unstLister .Namespace (pvc .Namespace ).Get (dataSourceRef .Name )
429
- if nil != err {
429
+ if err != nil {
430
430
if ! errors .IsNotFound (err ) {
431
431
return err
432
432
}
@@ -437,12 +437,12 @@ func (c *controller) syncPvc(ctx context.Context, key, pvcNamespace, pvcName str
437
437
438
438
var waitForFirstConsumer bool
439
439
var nodeName string
440
- if nil != pvc .Spec .StorageClassName {
440
+ if pvc .Spec .StorageClassName != nil {
441
441
storageClassName := * pvc .Spec .StorageClassName
442
442
443
443
var storageClass * storagev1.StorageClass
444
444
storageClass , err = c .scLister .Get (storageClassName )
445
- if nil != err {
445
+ if err != nil {
446
446
if ! errors .IsNotFound (err ) {
447
447
return err
448
448
}
@@ -451,10 +451,10 @@ func (c *controller) syncPvc(ctx context.Context, key, pvcNamespace, pvcName str
451
451
return nil
452
452
}
453
453
454
- if nil != storageClass . VolumeBindingMode && storagev1 .VolumeBindingWaitForFirstConsumer == * storageClass .VolumeBindingMode {
454
+ if storageClass . VolumeBindingMode != nil && storagev1 .VolumeBindingWaitForFirstConsumer == * storageClass .VolumeBindingMode {
455
455
waitForFirstConsumer = true
456
456
nodeName = pvc .Annotations [annSelectedNode ]
457
- if "" == nodeName {
457
+ if nodeName == "" {
458
458
// Wait for the PVC to get a node name before continuing
459
459
return nil
460
460
}
@@ -466,7 +466,7 @@ func (c *controller) syncPvc(ctx context.Context, key, pvcNamespace, pvcName str
466
466
c .addNotification (key , "pod" , c .populatorNamespace , podName )
467
467
var pod * corev1.Pod
468
468
pod , err = c .podLister .Pods (c .populatorNamespace ).Get (podName )
469
- if nil != err {
469
+ if err != nil {
470
470
if ! errors .IsNotFound (err ) {
471
471
return err
472
472
}
@@ -477,7 +477,7 @@ func (c *controller) syncPvc(ctx context.Context, key, pvcNamespace, pvcName str
477
477
c .addNotification (key , "pvc" , c .populatorNamespace , pvcPrimeName )
478
478
var pvcPrime * corev1.PersistentVolumeClaim
479
479
pvcPrime , err = c .pvcLister .PersistentVolumeClaims (c .populatorNamespace ).Get (pvcPrimeName )
480
- if nil != err {
480
+ if err != nil {
481
481
if ! errors .IsNotFound (err ) {
482
482
return err
483
483
}
@@ -490,12 +490,12 @@ func (c *controller) syncPvc(ctx context.Context, key, pvcNamespace, pvcName str
490
490
491
491
// Ensure the PVC has a finalizer on it so we can clean up the stuff we create
492
492
err = c .ensureFinalizer (ctx , pvc , c .pvcFinalizer , true )
493
- if nil != err {
493
+ if err != nil {
494
494
return err
495
495
}
496
496
497
497
// If the pod doesn't exist yet, create it
498
- if nil == pod {
498
+ if pod == nil {
499
499
var rawBlock bool
500
500
if nil != pvc .Spec .VolumeMode && corev1 .PersistentVolumeBlock == * pvc .Spec .VolumeMode {
501
501
rawBlock = true
@@ -504,7 +504,7 @@ func (c *controller) syncPvc(ctx context.Context, key, pvcNamespace, pvcName str
504
504
// Calculate the args for the populator pod
505
505
var args []string
506
506
args , err = c .populatorArgs (rawBlock , unstructured )
507
- if nil != err {
507
+ if err != nil {
508
508
return err
509
509
}
510
510
@@ -539,12 +539,12 @@ func (c *controller) syncPvc(ctx context.Context, key, pvcNamespace, pvcName str
539
539
pod .Spec .NodeName = nodeName
540
540
}
541
541
_ , err = c .kubeClient .CoreV1 ().Pods (c .populatorNamespace ).Create (ctx , pod , metav1.CreateOptions {})
542
- if nil != err {
542
+ if err != nil {
543
543
return err
544
544
}
545
545
546
546
// If PVC' doesn't exist yet, create it
547
- if nil == pvcPrime {
547
+ if pvcPrime == nil {
548
548
pvcPrime = & corev1.PersistentVolumeClaim {
549
549
ObjectMeta : metav1.ObjectMeta {
550
550
Name : pvcPrimeName ,
@@ -563,7 +563,7 @@ func (c *controller) syncPvc(ctx context.Context, key, pvcNamespace, pvcName str
563
563
}
564
564
}
565
565
_ , err = c .kubeClient .CoreV1 ().PersistentVolumeClaims (c .populatorNamespace ).Create (ctx , pvcPrime , metav1.CreateOptions {})
566
- if nil != err {
566
+ if err != nil {
567
567
return err
568
568
}
569
569
}
@@ -576,7 +576,7 @@ func (c *controller) syncPvc(ctx context.Context, key, pvcNamespace, pvcName str
576
576
if corev1 .PodFailed == pod .Status .Phase {
577
577
// Delete failed pods so we can try again
578
578
err = c .kubeClient .CoreV1 ().Pods (c .populatorNamespace ).Delete (ctx , pod .Name , metav1.DeleteOptions {})
579
- if nil != err {
579
+ if err != nil {
580
580
return err
581
581
}
582
582
}
@@ -585,15 +585,15 @@ func (c *controller) syncPvc(ctx context.Context, key, pvcNamespace, pvcName str
585
585
}
586
586
587
587
// This would be bad
588
- if nil == pvcPrime {
588
+ if pvcPrime == nil {
589
589
return fmt .Errorf ("Failed to find PVC for populator pod" )
590
590
}
591
591
592
592
// Get PV
593
593
var pv * corev1.PersistentVolume
594
594
c .addNotification (key , "pv" , "" , pvcPrime .Spec .VolumeName )
595
595
pv , err = c .kubeClient .CoreV1 ().PersistentVolumes ().Get (ctx , pvcPrime .Spec .VolumeName , metav1.GetOptions {})
596
- if nil != err {
596
+ if err != nil {
597
597
if ! errors .IsNotFound (err ) {
598
598
return err
599
599
}
@@ -622,12 +622,12 @@ func (c *controller) syncPvc(ctx context.Context, key, pvcNamespace, pvcName str
622
622
patchPv .Annotations [c .populatedFromAnno ] = pvc .Namespace + "/" + dataSourceRef .Name
623
623
var patchData []byte
624
624
patchData , err = json .Marshal (patchPv )
625
- if nil != err {
625
+ if err != nil {
626
626
return err
627
627
}
628
628
_ , err = c .kubeClient .CoreV1 ().PersistentVolumes ().Patch (ctx , pv .Name , types .StrategicMergePatchType ,
629
629
patchData , metav1.PatchOptions {})
630
- if nil != err {
630
+ if err != nil {
631
631
return err
632
632
}
633
633
@@ -638,7 +638,7 @@ func (c *controller) syncPvc(ctx context.Context, key, pvcNamespace, pvcName str
638
638
}
639
639
640
640
// Wait for the bind controller to rebind the PV
641
- if nil != pvcPrime {
641
+ if pvcPrime != nil {
642
642
if corev1 .ClaimLost != pvcPrime .Status .Phase {
643
643
return nil
644
644
}
@@ -647,29 +647,29 @@ func (c *controller) syncPvc(ctx context.Context, key, pvcNamespace, pvcName str
647
647
// *** At this point the volume population is done and we're just cleaning up ***
648
648
649
649
// If the pod still exists, delete it
650
- if nil != pod {
650
+ if pod != nil {
651
651
err = c .kubeClient .CoreV1 ().Pods (c .populatorNamespace ).Delete (ctx , pod .Name , metav1.DeleteOptions {})
652
- if nil != err {
652
+ if err != nil {
653
653
return err
654
654
}
655
655
}
656
656
657
657
// If PVC' still exists, delete it
658
- if nil != pvcPrime {
658
+ if pvcPrime != nil {
659
659
err = c .kubeClient .CoreV1 ().PersistentVolumeClaims (c .populatorNamespace ).Delete (ctx , pvcPrime .Name , metav1.DeleteOptions {})
660
- if nil != err {
660
+ if err != nil {
661
661
return err
662
662
}
663
663
}
664
664
665
665
// Make sure the PVC finalizer is gone
666
666
err = c .ensureFinalizer (ctx , pvc , c .pvcFinalizer , false )
667
- if nil != err {
667
+ if err != nil {
668
668
return err
669
669
}
670
670
671
671
// Clean up our internal callback maps
672
- c .cleanupNofications (key )
672
+ c .cleanupNotifications (key )
673
673
674
674
return nil
675
675
}
@@ -751,12 +751,12 @@ func (c *controller) ensureFinalizer(ctx context.Context, pvc *corev1.Persistent
751
751
}
752
752
753
753
data , err := json .Marshal (patch )
754
- if nil != err {
754
+ if err != nil {
755
755
return err
756
756
}
757
757
_ , err = c .kubeClient .CoreV1 ().PersistentVolumeClaims (pvc .Namespace ).Patch (ctx , pvc .Name , types .JSONPatchType ,
758
758
data , metav1.PatchOptions {})
759
- if nil != err {
759
+ if err != nil {
760
760
return err
761
761
}
762
762
0 commit comments