-
Notifications
You must be signed in to change notification settings - Fork 38.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix go lint failures in volume scheduling packages #77442
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,7 +37,9 @@ import ( | |
"k8s.io/kubernetes/pkg/features" | ||
) | ||
|
||
var VersionConflictError = errors.New("VersionError") | ||
// ErrVersionConflict is the error returned when resource version of requested | ||
// object conflicts with the object in storage. | ||
var ErrVersionConflict = errors.New("VersionError") | ||
|
||
// VolumeReactor is a core.Reactor that simulates etcd and API server. It | ||
// stores: | ||
|
@@ -157,7 +159,7 @@ func (r *VolumeReactor) React(action core.Action) (handled bool, ret runtime.Obj | |
storedVer, _ := strconv.Atoi(storedVolume.ResourceVersion) | ||
requestedVer, _ := strconv.Atoi(volume.ResourceVersion) | ||
if storedVer != requestedVer { | ||
return true, obj, VersionConflictError | ||
return true, obj, ErrVersionConflict | ||
} | ||
if reflect.DeepEqual(storedVolume, volume) { | ||
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 | |
storedVer, _ := strconv.Atoi(storedClaim.ResourceVersion) | ||
requestedVer, _ := strconv.Atoi(claim.ResourceVersion) | ||
if storedVer != requestedVer { | ||
return true, obj, VersionConflictError | ||
return true, obj, ErrVersionConflict | ||
} | ||
if reflect.DeepEqual(storedClaim, claim) { | ||
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 | |
if found { | ||
klog.V(4).Infof("GetVolume: found %s", volume.Name) | ||
return true, volume.DeepCopy(), nil | ||
} else { | ||
klog.V(4).Infof("GetVolume: volume %s not found", name) | ||
return true, nil, fmt.Errorf("Cannot find volume %s", name) | ||
} | ||
klog.V(4).Infof("GetVolume: volume %s not found", name) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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 { | ||
klog.V(4).Infof("GetClaim: found %s", claim.Name) | ||
return true, claim.DeepCopy(), nil | ||
} else { | ||
klog.V(4).Infof("GetClaim: claim %s not found", name) | ||
return true, nil, apierrs.NewNotFound(action.GetResource().GroupResource(), name) | ||
} | ||
klog.V(4).Infof("GetClaim: claim %s not found", name) | ||
return true, nil, apierrs.NewNotFound(action.GetResource().GroupResource(), name) | ||
|
||
case action.Matches("delete", "persistentvolumes"): | ||
name := action.(core.DeleteAction).GetName() | ||
|
@@ -246,9 +246,8 @@ func (r *VolumeReactor) React(action core.Action) (handled bool, ret runtime.Obj | |
} | ||
r.changedSinceLastSync++ | ||
return true, nil, nil | ||
} else { | ||
return true, nil, fmt.Errorf("Cannot delete volume %s: not found", name) | ||
} | ||
return true, nil, fmt.Errorf("Cannot delete volume %s: not found", name) | ||
|
||
case action.Matches("delete", "persistentvolumeclaims"): | ||
name := action.(core.DeleteAction).GetName() | ||
|
@@ -261,9 +260,8 @@ func (r *VolumeReactor) React(action core.Action) (handled bool, ret runtime.Obj | |
} | ||
r.changedSinceLastSync++ | ||
return true, nil, nil | ||
} else { | ||
return true, nil, fmt.Errorf("Cannot delete claim %s: not found", name) | ||
} | ||
return true, nil, fmt.Errorf("Cannot delete claim %s: not found", name) | ||
} | ||
|
||
return false, nil, nil | ||
|
@@ -299,12 +297,6 @@ func (r *VolumeReactor) getWatches(gvr schema.GroupVersionResource, ns string) [ | |
return watches | ||
} | ||
|
||
func (r *VolumeReactor) ChangedSinceLastSync() int { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Duplicate function |
||
r.lock.RLock() | ||
defer r.lock.RUnlock() | ||
return r.changedSinceLastSync | ||
} | ||
|
||
// injectReactError returns an error when the test requested given action to | ||
// fail. nil is returned otherwise. | ||
func (r *VolumeReactor) injectReactError(action core.Action) error { | ||
|
@@ -435,6 +427,7 @@ func (r *VolumeReactor) SyncAll() { | |
r.changedSinceLastSync = 0 | ||
} | ||
|
||
// GetChangeCount returns changes since last sync. | ||
func (r *VolumeReactor) GetChangeCount() int { | ||
r.lock.Lock() | ||
defer r.lock.Unlock() | ||
|
@@ -515,6 +508,7 @@ func (r *VolumeReactor) AddClaimEvent(claim *v1.PersistentVolumeClaim) { | |
} | ||
} | ||
|
||
// AddClaims adds PVCs into VolumeReactor. | ||
func (r *VolumeReactor) AddClaims(claims []*v1.PersistentVolumeClaim) { | ||
r.lock.Lock() | ||
defer r.lock.Unlock() | ||
|
@@ -523,6 +517,7 @@ func (r *VolumeReactor) AddClaims(claims []*v1.PersistentVolumeClaim) { | |
} | ||
} | ||
|
||
// AddVolumes adds PVs into VolumeReactor. | ||
func (r *VolumeReactor) AddVolumes(volumes []*v1.PersistentVolume) { | ||
r.lock.Lock() | ||
defer r.lock.Unlock() | ||
|
@@ -531,24 +526,28 @@ func (r *VolumeReactor) AddVolumes(volumes []*v1.PersistentVolume) { | |
} | ||
} | ||
|
||
// AddClaim adds a PVC into VolumeReactor. | ||
func (r *VolumeReactor) AddClaim(claim *v1.PersistentVolumeClaim) { | ||
r.lock.Lock() | ||
defer r.lock.Unlock() | ||
r.claims[claim.Name] = claim | ||
} | ||
|
||
// AddVolume adds a PV into VolumeReactor. | ||
func (r *VolumeReactor) AddVolume(volume *v1.PersistentVolume) { | ||
r.lock.Lock() | ||
defer r.lock.Unlock() | ||
r.volumes[volume.Name] = volume | ||
} | ||
|
||
// DeleteVolume deletes a PV by name. | ||
func (r *VolumeReactor) DeleteVolume(name string) { | ||
r.lock.Lock() | ||
defer r.lock.Unlock() | ||
delete(r.volumes, name) | ||
} | ||
|
||
// AddClaimBoundToVolume adds a PVC and binds it to corresponding PV. | ||
func (r *VolumeReactor) AddClaimBoundToVolume(claim *v1.PersistentVolumeClaim) { | ||
r.lock.Lock() | ||
defer r.lock.Unlock() | ||
|
@@ -558,6 +557,7 @@ func (r *VolumeReactor) AddClaimBoundToVolume(claim *v1.PersistentVolumeClaim) { | |
} | ||
} | ||
|
||
// MarkVolumeAvaiable marks a PV available by name. | ||
func (r *VolumeReactor) MarkVolumeAvaiable(name string) { | ||
r.lock.Lock() | ||
defer r.lock.Unlock() | ||
|
@@ -568,6 +568,7 @@ func (r *VolumeReactor) MarkVolumeAvaiable(name string) { | |
} | ||
} | ||
|
||
// NewVolumeReactor creates a volume reactor. | ||
func NewVolumeReactor(client *fake.Clientset, fakeVolumeWatch, fakeClaimWatch *watch.FakeWatcher, errors []ReactorError) *VolumeReactor { | ||
reactor := &VolumeReactor{ | ||
volumes: make(map[string]*v1.PersistentVolume), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,7 +127,8 @@ func (c *assumeCache) objInfoIndexFunc(obj interface{}) ([]string, error) { | |
return c.indexFunc(objInfo.latestObj) | ||
} | ||
|
||
func NewAssumeCache(informer cache.SharedIndexInformer, description, indexName string, indexFunc cache.IndexFunc) *assumeCache { | ||
// NewAssumeCache creates an assume cache for genernal objects. | ||
func NewAssumeCache(informer cache.SharedIndexInformer, description, indexName string, indexFunc cache.IndexFunc) AssumeCache { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
c := &assumeCache{ | ||
description: description, | ||
indexFunc: indexFunc, | ||
|
@@ -344,7 +345,7 @@ type PVAssumeCache interface { | |
} | ||
|
||
type pvAssumeCache struct { | ||
*assumeCache | ||
AssumeCache | ||
} | ||
|
||
func pvStorageClassIndexFunc(obj interface{}) ([]string, error) { | ||
|
@@ -354,8 +355,9 @@ func pvStorageClassIndexFunc(obj interface{}) ([]string, error) { | |
return []string{""}, fmt.Errorf("object is not a v1.PersistentVolume: %v", obj) | ||
} | ||
|
||
// NewPVAssumeCache creates a PV assume cache. | ||
func NewPVAssumeCache(informer cache.SharedIndexInformer) PVAssumeCache { | ||
return &pvAssumeCache{assumeCache: NewAssumeCache(informer, "v1.PersistentVolume", "storageclass", pvStorageClassIndexFunc)} | ||
return &pvAssumeCache{NewAssumeCache(informer, "v1.PersistentVolume", "storageclass", pvStorageClassIndexFunc)} | ||
} | ||
|
||
func (c *pvAssumeCache) GetPV(pvName string) (*v1.PersistentVolume, error) { | ||
|
@@ -411,11 +413,12 @@ type PVCAssumeCache interface { | |
} | ||
|
||
type pvcAssumeCache struct { | ||
*assumeCache | ||
AssumeCache | ||
} | ||
|
||
// NewPVCAssumeCache creates a PVC assume cache. | ||
func NewPVCAssumeCache(informer cache.SharedIndexInformer) PVCAssumeCache { | ||
return &pvcAssumeCache{assumeCache: NewAssumeCache(informer, "v1.PersistentVolumeClaim", "namespace", cache.MetaNamespaceIndexFunc)} | ||
return &pvcAssumeCache{NewAssumeCache(informer, "v1.PersistentVolumeClaim", "namespace", cache.MetaNamespaceIndexFunc)} | ||
} | ||
|
||
func (c *pvcAssumeCache) GetPVC(pvcKey string) (*v1.PersistentVolumeClaim, error) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
golint: error var VersionConflictError should have name of the form ErrFoo