Skip to content
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

Merged
merged 2 commits into from
May 7, 2019

Conversation

cofyc
Copy link
Member

@cofyc cofyc commented May 4, 2019

What type of PR is this?

Uncomment only one /kind <> line, hit enter to put that in a new line, and remove leading whitespaces from that line:

/kind api-change
/kind bug
/kind cleanup
/kind design
/kind documentation
/kind failing-test
/kind feature
/kind flake

What this PR does / why we need it:

  • pkg/controller/volume/persistentvolume/testing
  • pkg/controller/volume/scheduling

Which issue(s) this PR fixes:

Fixes #77084

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

@k8s-ci-robot k8s-ci-robot added release-note-none Denotes a PR that doesn't merit a release note. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. sig/apps Categorizes an issue or PR as relevant to SIG Apps. and removed needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels May 4, 2019
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")
Copy link
Member Author

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 {
Copy link
Member Author

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 {
Copy link
Member Author

@cofyc cofyc May 4, 2019

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)}
Copy link
Member Author

@cofyc cofyc May 4, 2019

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

Copy link
Member

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

Copy link
Member Author

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)}
Copy link
Member Author

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)
Copy link
Member Author

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)
Copy link
Member Author

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 {
Copy link
Member Author

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 {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return exported interface

@cofyc cofyc changed the title Fix go lint failures in a few packages Fix go lint failures in volume scheduling packages May 4, 2019
@cofyc cofyc force-pushed the fix77084 branch 2 times, most recently from af7237b to 529ebc2 Compare May 4, 2019 15:39
@cofyc
Copy link
Member Author

cofyc commented May 4, 2019

/assign @dims @fejta
for hack/.golint_failures approval
/assign @msau42
for reviewing

- pkg/controller/volume/persistentvolume/testing
- pkg/controller/volume/scheduling
Copy link
Contributor

@fejta fejta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 7, 2019
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 7, 2019
@msau42
Copy link
Member

msau42 commented May 7, 2019

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 7, 2019
@msau42
Copy link
Member

msau42 commented May 7, 2019

/priority important-longterm

@k8s-ci-robot
Copy link
Contributor

[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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. approved Indicates a PR has been approved by an approver from all required OWNERS files. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels May 7, 2019
@k8s-ci-robot k8s-ci-robot merged commit 43284ec into kubernetes:master May 7, 2019
@cofyc cofyc deleted the fix77084 branch September 2, 2019 05:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-longterm Important over the long term, but may not be staffed and/or may need multiple releases to complete. release-note-none Denotes a PR that doesn't merit a release note. sig/apps Categorizes an issue or PR as relevant to SIG Apps. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Follow up of #75434: fix go lint failures
5 participants