-
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
Conversation
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") |
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
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate function
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
exported func NewAssumeCache returns unexported type *scheduling.assumeCache, which can be annoying to use
I guess it's better to expose interface instead struct, so I changed the function to return interface
func NewPVAssumeCache(informer cache.SharedIndexInformer) PVAssumeCache { | ||
return &pvAssumeCache{assumeCache: NewAssumeCache(informer, "v1.PersistentVolume", "storageclass", pvStorageClassIndexFunc)} | ||
return &pvAssumeCache{NewAssumeCache(informer, "v1.PersistentVolume", "storageclass", pvStorageClassIndexFunc).(*assumeCache)} |
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.
because it returns an interface now, we need to cast it to *assumeCache
back here
It feels weird but we cannot use AssumeCache interface in pvAssumeCache
struct because private functions of assumeCache
are required in testing pvAssumeCache
and pvcAssumeCache
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.
Hm can the unit tests do one more level of casting to get the 'assumeCache'?
Looking at L348, I'm not sure we need to copy private 'assumeCache' into the struct. It looks like we only use interface functions in the PV and PVC implementations
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.
can the unit tests do one more level of casting to get the 'assumeCache'?
At before, I thought we need two variables to access pv/pvc)AssumeCache and assumeCache with which the code will be tedious, but I found in testing we didn't need to access private methods of (pv/pvc)AssumeCache.
It's a good idea. I pushed a new commit to address this: 4abd730
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).(*assumeCache)} |
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.
same as NewPVAssumeCache
@@ -109,13 +109,13 @@ func TestAssumePV(t *testing.T) { | |||
|
|||
for name, scenario := range scenarios { | |||
cache := NewPVAssumeCache(nil) | |||
internal_cache, ok := cache.(*pvAssumeCache) | |||
internalCache, ok := cache.(*pvAssumeCache) |
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.
don't use underscores in Go names; var internal_cache should be internalCache
} | ||
klog.V(4).Infof("GetVolume: volume %s not found", name) |
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.
if block ends with a return statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary)
it applies to all if else
cases
@@ -18,7 +18,7 @@ package scheduling | |||
|
|||
import "k8s.io/api/core/v1" | |||
|
|||
type FakeVolumeBinderConfig struct { | |||
type fakeVolumeBinderConfig struct { |
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.
unexported it then we don't need to comment it
// topology-aware volume binding decisions. | ||
func NewFakeVolumeBinder(config *FakeVolumeBinderConfig) *FakeVolumeBinder { | ||
return &FakeVolumeBinder{ | ||
func NewFakeVolumeBinder(config *fakeVolumeBinderConfig) SchedulerVolumeBinder { |
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.
return exported interface
af7237b
to
529ebc2
Compare
- pkg/controller/volume/persistentvolume/testing - pkg/controller/volume/scheduling
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.
/lgtm
/approve
/lgtm |
/priority important-longterm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cofyc, fejta, msau42 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
What this PR does / why we need it:
Which issue(s) this PR fixes:
Fixes #77084
Special notes for your reviewer:
Does this PR introduce a user-facing change?: