Skip to content

Commit 43284ec

Browse files
authored
Merge pull request kubernetes#77442 from cofyc/fix77084
Fix go lint failures in volume scheduling packages
2 parents 5b34d95 + 4abd730 commit 43284ec

File tree

10 files changed

+80
-69
lines changed

10 files changed

+80
-69
lines changed

hack/.golint_failures

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,6 @@ pkg/controller/volume/expand
103103
pkg/controller/volume/persistentvolume
104104
pkg/controller/volume/persistentvolume/config/v1alpha1
105105
pkg/controller/volume/persistentvolume/options
106-
pkg/controller/volume/persistentvolume/testing
107-
pkg/controller/volume/scheduling
108106
pkg/credentialprovider
109107
pkg/credentialprovider/gcp
110108
pkg/features

pkg/controller/volume/persistentvolume/framework_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ func runMultisyncTests(t *testing.T, tests []controllerTest, storageClasses []*s
688688
obj := reactor.PopChange()
689689
if obj == nil {
690690
// Nothing was changed, should we exit?
691-
if firstSync || reactor.ChangedSinceLastSync() > 0 {
691+
if firstSync || reactor.GetChangeCount() > 0 {
692692
// There were some changes after the last "periodic sync".
693693
// Simulate "periodic sync" of everything (until it produces
694694
// no changes).
@@ -712,7 +712,7 @@ func runMultisyncTests(t *testing.T, tests []controllerTest, storageClasses []*s
712712
ctrl.claims.Update(claim)
713713
err = ctrl.syncClaim(claim)
714714
if err != nil {
715-
if err == pvtesting.VersionConflictError {
715+
if err == pvtesting.ErrVersionConflict {
716716
// Ignore version errors
717717
klog.V(4).Infof("test intentionaly ignores version error.")
718718
} else {
@@ -729,7 +729,7 @@ func runMultisyncTests(t *testing.T, tests []controllerTest, storageClasses []*s
729729
ctrl.volumes.store.Update(volume)
730730
err = ctrl.syncVolume(volume)
731731
if err != nil {
732-
if err == pvtesting.VersionConflictError {
732+
if err == pvtesting.ErrVersionConflict {
733733
// Ignore version errors
734734
klog.V(4).Infof("test intentionaly ignores version error.")
735735
} else {

pkg/controller/volume/persistentvolume/testing/testing.go

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ import (
3737
"k8s.io/kubernetes/pkg/features"
3838
)
3939

40-
var VersionConflictError = errors.New("VersionError")
40+
// ErrVersionConflict is the error returned when resource version of requested
41+
// object conflicts with the object in storage.
42+
var ErrVersionConflict = errors.New("VersionError")
4143

4244
// VolumeReactor is a core.Reactor that simulates etcd and API server. It
4345
// stores:
@@ -157,7 +159,7 @@ func (r *VolumeReactor) React(action core.Action) (handled bool, ret runtime.Obj
157159
storedVer, _ := strconv.Atoi(storedVolume.ResourceVersion)
158160
requestedVer, _ := strconv.Atoi(volume.ResourceVersion)
159161
if storedVer != requestedVer {
160-
return true, obj, VersionConflictError
162+
return true, obj, ErrVersionConflict
161163
}
162164
if reflect.DeepEqual(storedVolume, volume) {
163165
klog.V(4).Infof("nothing updated volume %s", volume.Name)
@@ -190,7 +192,7 @@ func (r *VolumeReactor) React(action core.Action) (handled bool, ret runtime.Obj
190192
storedVer, _ := strconv.Atoi(storedClaim.ResourceVersion)
191193
requestedVer, _ := strconv.Atoi(claim.ResourceVersion)
192194
if storedVer != requestedVer {
193-
return true, obj, VersionConflictError
195+
return true, obj, ErrVersionConflict
194196
}
195197
if reflect.DeepEqual(storedClaim, claim) {
196198
klog.V(4).Infof("nothing updated claim %s", claim.Name)
@@ -219,21 +221,19 @@ func (r *VolumeReactor) React(action core.Action) (handled bool, ret runtime.Obj
219221
if found {
220222
klog.V(4).Infof("GetVolume: found %s", volume.Name)
221223
return true, volume.DeepCopy(), nil
222-
} else {
223-
klog.V(4).Infof("GetVolume: volume %s not found", name)
224-
return true, nil, fmt.Errorf("Cannot find volume %s", name)
225224
}
225+
klog.V(4).Infof("GetVolume: volume %s not found", name)
226+
return true, nil, fmt.Errorf("Cannot find volume %s", name)
226227

227228
case action.Matches("get", "persistentvolumeclaims"):
228229
name := action.(core.GetAction).GetName()
229230
claim, found := r.claims[name]
230231
if found {
231232
klog.V(4).Infof("GetClaim: found %s", claim.Name)
232233
return true, claim.DeepCopy(), nil
233-
} else {
234-
klog.V(4).Infof("GetClaim: claim %s not found", name)
235-
return true, nil, apierrs.NewNotFound(action.GetResource().GroupResource(), name)
236234
}
235+
klog.V(4).Infof("GetClaim: claim %s not found", name)
236+
return true, nil, apierrs.NewNotFound(action.GetResource().GroupResource(), name)
237237

238238
case action.Matches("delete", "persistentvolumes"):
239239
name := action.(core.DeleteAction).GetName()
@@ -246,9 +246,8 @@ func (r *VolumeReactor) React(action core.Action) (handled bool, ret runtime.Obj
246246
}
247247
r.changedSinceLastSync++
248248
return true, nil, nil
249-
} else {
250-
return true, nil, fmt.Errorf("Cannot delete volume %s: not found", name)
251249
}
250+
return true, nil, fmt.Errorf("Cannot delete volume %s: not found", name)
252251

253252
case action.Matches("delete", "persistentvolumeclaims"):
254253
name := action.(core.DeleteAction).GetName()
@@ -261,9 +260,8 @@ func (r *VolumeReactor) React(action core.Action) (handled bool, ret runtime.Obj
261260
}
262261
r.changedSinceLastSync++
263262
return true, nil, nil
264-
} else {
265-
return true, nil, fmt.Errorf("Cannot delete claim %s: not found", name)
266263
}
264+
return true, nil, fmt.Errorf("Cannot delete claim %s: not found", name)
267265
}
268266

269267
return false, nil, nil
@@ -299,12 +297,6 @@ func (r *VolumeReactor) getWatches(gvr schema.GroupVersionResource, ns string) [
299297
return watches
300298
}
301299

302-
func (r *VolumeReactor) ChangedSinceLastSync() int {
303-
r.lock.RLock()
304-
defer r.lock.RUnlock()
305-
return r.changedSinceLastSync
306-
}
307-
308300
// injectReactError returns an error when the test requested given action to
309301
// fail. nil is returned otherwise.
310302
func (r *VolumeReactor) injectReactError(action core.Action) error {
@@ -435,6 +427,7 @@ func (r *VolumeReactor) SyncAll() {
435427
r.changedSinceLastSync = 0
436428
}
437429

430+
// GetChangeCount returns changes since last sync.
438431
func (r *VolumeReactor) GetChangeCount() int {
439432
r.lock.Lock()
440433
defer r.lock.Unlock()
@@ -515,6 +508,7 @@ func (r *VolumeReactor) AddClaimEvent(claim *v1.PersistentVolumeClaim) {
515508
}
516509
}
517510

511+
// AddClaims adds PVCs into VolumeReactor.
518512
func (r *VolumeReactor) AddClaims(claims []*v1.PersistentVolumeClaim) {
519513
r.lock.Lock()
520514
defer r.lock.Unlock()
@@ -523,6 +517,7 @@ func (r *VolumeReactor) AddClaims(claims []*v1.PersistentVolumeClaim) {
523517
}
524518
}
525519

520+
// AddVolumes adds PVs into VolumeReactor.
526521
func (r *VolumeReactor) AddVolumes(volumes []*v1.PersistentVolume) {
527522
r.lock.Lock()
528523
defer r.lock.Unlock()
@@ -531,24 +526,28 @@ func (r *VolumeReactor) AddVolumes(volumes []*v1.PersistentVolume) {
531526
}
532527
}
533528

529+
// AddClaim adds a PVC into VolumeReactor.
534530
func (r *VolumeReactor) AddClaim(claim *v1.PersistentVolumeClaim) {
535531
r.lock.Lock()
536532
defer r.lock.Unlock()
537533
r.claims[claim.Name] = claim
538534
}
539535

536+
// AddVolume adds a PV into VolumeReactor.
540537
func (r *VolumeReactor) AddVolume(volume *v1.PersistentVolume) {
541538
r.lock.Lock()
542539
defer r.lock.Unlock()
543540
r.volumes[volume.Name] = volume
544541
}
545542

543+
// DeleteVolume deletes a PV by name.
546544
func (r *VolumeReactor) DeleteVolume(name string) {
547545
r.lock.Lock()
548546
defer r.lock.Unlock()
549547
delete(r.volumes, name)
550548
}
551549

550+
// AddClaimBoundToVolume adds a PVC and binds it to corresponding PV.
552551
func (r *VolumeReactor) AddClaimBoundToVolume(claim *v1.PersistentVolumeClaim) {
553552
r.lock.Lock()
554553
defer r.lock.Unlock()
@@ -558,6 +557,7 @@ func (r *VolumeReactor) AddClaimBoundToVolume(claim *v1.PersistentVolumeClaim) {
558557
}
559558
}
560559

560+
// MarkVolumeAvaiable marks a PV available by name.
561561
func (r *VolumeReactor) MarkVolumeAvaiable(name string) {
562562
r.lock.Lock()
563563
defer r.lock.Unlock()
@@ -568,6 +568,7 @@ func (r *VolumeReactor) MarkVolumeAvaiable(name string) {
568568
}
569569
}
570570

571+
// NewVolumeReactor creates a volume reactor.
571572
func NewVolumeReactor(client *fake.Clientset, fakeVolumeWatch, fakeClaimWatch *watch.FakeWatcher, errors []ReactorError) *VolumeReactor {
572573
reactor := &VolumeReactor{
573574
volumes: make(map[string]*v1.PersistentVolume),

pkg/controller/volume/scheduling/scheduler_assume_cache.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ func (c *assumeCache) objInfoIndexFunc(obj interface{}) ([]string, error) {
127127
return c.indexFunc(objInfo.latestObj)
128128
}
129129

130-
func NewAssumeCache(informer cache.SharedIndexInformer, description, indexName string, indexFunc cache.IndexFunc) *assumeCache {
130+
// NewAssumeCache creates an assume cache for genernal objects.
131+
func NewAssumeCache(informer cache.SharedIndexInformer, description, indexName string, indexFunc cache.IndexFunc) AssumeCache {
131132
c := &assumeCache{
132133
description: description,
133134
indexFunc: indexFunc,
@@ -344,7 +345,7 @@ type PVAssumeCache interface {
344345
}
345346

346347
type pvAssumeCache struct {
347-
*assumeCache
348+
AssumeCache
348349
}
349350

350351
func pvStorageClassIndexFunc(obj interface{}) ([]string, error) {
@@ -354,8 +355,9 @@ func pvStorageClassIndexFunc(obj interface{}) ([]string, error) {
354355
return []string{""}, fmt.Errorf("object is not a v1.PersistentVolume: %v", obj)
355356
}
356357

358+
// NewPVAssumeCache creates a PV assume cache.
357359
func NewPVAssumeCache(informer cache.SharedIndexInformer) PVAssumeCache {
358-
return &pvAssumeCache{assumeCache: NewAssumeCache(informer, "v1.PersistentVolume", "storageclass", pvStorageClassIndexFunc)}
360+
return &pvAssumeCache{NewAssumeCache(informer, "v1.PersistentVolume", "storageclass", pvStorageClassIndexFunc)}
359361
}
360362

361363
func (c *pvAssumeCache) GetPV(pvName string) (*v1.PersistentVolume, error) {
@@ -411,11 +413,12 @@ type PVCAssumeCache interface {
411413
}
412414

413415
type pvcAssumeCache struct {
414-
*assumeCache
416+
AssumeCache
415417
}
416418

419+
// NewPVCAssumeCache creates a PVC assume cache.
417420
func NewPVCAssumeCache(informer cache.SharedIndexInformer) PVCAssumeCache {
418-
return &pvcAssumeCache{assumeCache: NewAssumeCache(informer, "v1.PersistentVolumeClaim", "namespace", cache.MetaNamespaceIndexFunc)}
421+
return &pvcAssumeCache{NewAssumeCache(informer, "v1.PersistentVolumeClaim", "namespace", cache.MetaNamespaceIndexFunc)}
419422
}
420423

421424
func (c *pvcAssumeCache) GetPVC(pvcKey string) (*v1.PersistentVolumeClaim, error) {

0 commit comments

Comments
 (0)