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

[scheduler cleanup phase 1]: Move FakeCache to pkg/scheduler/internal… #69318

Merged
merged 1 commit into from
Oct 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/scheduler/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ go_test(
"//pkg/scheduler/api:go_default_library",
"//pkg/scheduler/core:go_default_library",
"//pkg/scheduler/internal/cache:go_default_library",
"//pkg/scheduler/internal/cache/fake:go_default_library",
"//pkg/scheduler/testing:go_default_library",
"//pkg/scheduler/volumebinder:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
Expand Down
1 change: 1 addition & 0 deletions pkg/scheduler/factory/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ go_test(
"//pkg/scheduler/api:go_default_library",
"//pkg/scheduler/api/latest:go_default_library",
"//pkg/scheduler/cache:go_default_library",
"//pkg/scheduler/internal/cache/fake:go_default_library",
"//pkg/scheduler/internal/queue:go_default_library",
"//pkg/scheduler/testing:go_default_library",
"//pkg/scheduler/util:go_default_library",
Expand Down
3 changes: 2 additions & 1 deletion pkg/scheduler/factory/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
schedulerapi "k8s.io/kubernetes/pkg/scheduler/api"
latestschedulerapi "k8s.io/kubernetes/pkg/scheduler/api/latest"
schedulercache "k8s.io/kubernetes/pkg/scheduler/cache"
fakecache "k8s.io/kubernetes/pkg/scheduler/internal/cache/fake"
internalqueue "k8s.io/kubernetes/pkg/scheduler/internal/queue"
schedulertesting "k8s.io/kubernetes/pkg/scheduler/testing"
"k8s.io/kubernetes/pkg/scheduler/util"
Expand Down Expand Up @@ -526,7 +527,7 @@ func TestSkipPodUpdate(t *testing.T) {
for _, test := range table {
t.Run(test.name, func(t *testing.T) {
c := &configFactory{
schedulerCache: &schedulertesting.FakeCache{
schedulerCache: &fakecache.Cache{
IsAssumedPodFunc: test.isAssumedPodFunc,
GetPodFunc: test.getPodFunc,
},
Expand Down
5 changes: 4 additions & 1 deletion pkg/scheduler/internal/cache/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ filegroup(

filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
srcs = [
":package-srcs",
"//pkg/scheduler/internal/cache/fake:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
28 changes: 28 additions & 0 deletions pkg/scheduler/internal/cache/fake/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = ["fake_cache.go"],
importpath = "k8s.io/kubernetes/pkg/scheduler/internal/cache/fake",
visibility = ["//pkg/scheduler:__subpackages__"],
deps = [
"//pkg/scheduler/cache:go_default_library",
"//pkg/scheduler/internal/cache:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/labels:go_default_library",
],
)

filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)

filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package testing
package fake
Copy link
Member

Choose a reason for hiding this comment

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

Why not putting the file in scheduler/internal/cache instead of scheduler/internal/cache/fake?

Choose a reason for hiding this comment

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

Since the fake is meant for unit testing, we want a way to avoid importing it into production binaries. One way would be to call the file fake_test.go or we could just put it in a sub-package. Incidentally, this copies the convention from k8s.io/client-go/kubernetes/fake.


import (
"k8s.io/api/core/v1"
Expand All @@ -23,74 +23,74 @@ import (
schedulerinternalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache"
)

// FakeCache is used for testing
type FakeCache struct {
// Cache is used for testing
type Cache struct {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rewrite FakeCache to Cache for

Errors from golint:
pkg/scheduler/internal/cache/fake/fake_cache.go:26:6: type name will be used as fake.FakeCache by other packages, and that stutters; consider calling this Cache

AssumeFunc func(*v1.Pod)
ForgetFunc func(*v1.Pod)
IsAssumedPodFunc func(*v1.Pod) bool
GetPodFunc func(*v1.Pod) *v1.Pod
}

// AssumePod is a fake method for testing.
func (f *FakeCache) AssumePod(pod *v1.Pod) error {
f.AssumeFunc(pod)
func (c *Cache) AssumePod(pod *v1.Pod) error {
c.AssumeFunc(pod)
return nil
}

// FinishBinding is a fake method for testing.
func (f *FakeCache) FinishBinding(pod *v1.Pod) error { return nil }
func (c *Cache) FinishBinding(pod *v1.Pod) error { return nil }

// ForgetPod is a fake method for testing.
func (f *FakeCache) ForgetPod(pod *v1.Pod) error {
f.ForgetFunc(pod)
func (c *Cache) ForgetPod(pod *v1.Pod) error {
c.ForgetFunc(pod)
return nil
}

// AddPod is a fake method for testing.
func (f *FakeCache) AddPod(pod *v1.Pod) error { return nil }
func (c *Cache) AddPod(pod *v1.Pod) error { return nil }

// UpdatePod is a fake method for testing.
func (f *FakeCache) UpdatePod(oldPod, newPod *v1.Pod) error { return nil }
func (c *Cache) UpdatePod(oldPod, newPod *v1.Pod) error { return nil }

// RemovePod is a fake method for testing.
func (f *FakeCache) RemovePod(pod *v1.Pod) error { return nil }
func (c *Cache) RemovePod(pod *v1.Pod) error { return nil }

// IsAssumedPod is a fake method for testing.
func (f *FakeCache) IsAssumedPod(pod *v1.Pod) (bool, error) {
return f.IsAssumedPodFunc(pod), nil
func (c *Cache) IsAssumedPod(pod *v1.Pod) (bool, error) {
return c.IsAssumedPodFunc(pod), nil
}

// GetPod is a fake method for testing.
func (f *FakeCache) GetPod(pod *v1.Pod) (*v1.Pod, error) {
return f.GetPodFunc(pod), nil
func (c *Cache) GetPod(pod *v1.Pod) (*v1.Pod, error) {
return c.GetPodFunc(pod), nil
}

// AddNode is a fake method for testing.
func (f *FakeCache) AddNode(node *v1.Node) error { return nil }
func (c *Cache) AddNode(node *v1.Node) error { return nil }

// UpdateNode is a fake method for testing.
func (f *FakeCache) UpdateNode(oldNode, newNode *v1.Node) error { return nil }
func (c *Cache) UpdateNode(oldNode, newNode *v1.Node) error { return nil }

// RemoveNode is a fake method for testing.
func (f *FakeCache) RemoveNode(node *v1.Node) error { return nil }
func (c *Cache) RemoveNode(node *v1.Node) error { return nil }

// UpdateNodeNameToInfoMap is a fake method for testing.
func (f *FakeCache) UpdateNodeNameToInfoMap(infoMap map[string]*schedulercache.NodeInfo) error {
func (c *Cache) UpdateNodeNameToInfoMap(infoMap map[string]*schedulercache.NodeInfo) error {
return nil
}

// List is a fake method for testing.
func (f *FakeCache) List(s labels.Selector) ([]*v1.Pod, error) { return nil, nil }
func (c *Cache) List(s labels.Selector) ([]*v1.Pod, error) { return nil, nil }

// FilteredList is a fake method for testing.
func (f *FakeCache) FilteredList(filter schedulerinternalcache.PodFilter, selector labels.Selector) ([]*v1.Pod, error) {
func (c *Cache) FilteredList(filter schedulerinternalcache.PodFilter, selector labels.Selector) ([]*v1.Pod, error) {
return nil, nil
}

// Snapshot is a fake method for testing
func (f *FakeCache) Snapshot() *schedulerinternalcache.Snapshot {
func (c *Cache) Snapshot() *schedulerinternalcache.Snapshot {
return &schedulerinternalcache.Snapshot{}
}

// NodeTree is a fake method for testing.
func (f *FakeCache) NodeTree() *schedulerinternalcache.NodeTree { return nil }
func (c *Cache) NodeTree() *schedulerinternalcache.NodeTree { return nil }
3 changes: 2 additions & 1 deletion pkg/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"k8s.io/kubernetes/pkg/scheduler/api"
"k8s.io/kubernetes/pkg/scheduler/core"
schedulerinternalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache"
fakecache "k8s.io/kubernetes/pkg/scheduler/internal/cache/fake"
schedulertesting "k8s.io/kubernetes/pkg/scheduler/testing"
"k8s.io/kubernetes/pkg/scheduler/volumebinder"
)
Expand Down Expand Up @@ -200,7 +201,7 @@ func TestScheduler(t *testing.T) {
var gotBinding *v1.Binding
configurator := &FakeConfigurator{
Config: &Config{
SchedulerCache: &schedulertesting.FakeCache{
SchedulerCache: &fakecache.Cache{
ForgetFunc: func(pod *v1.Pod) {
gotForgetPod = pod
},
Expand Down
2 changes: 0 additions & 2 deletions pkg/scheduler/testing/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ load(
go_library(
name = "go_default_library",
srcs = [
"fake_cache.go",
"fake_lister.go",
"util.go",
],
Expand All @@ -19,7 +18,6 @@ go_library(
"//pkg/apis/core:go_default_library",
"//pkg/apis/core/install:go_default_library",
"//pkg/scheduler/algorithm:go_default_library",
"//pkg/scheduler/cache:go_default_library",
"//pkg/scheduler/internal/cache:go_default_library",
"//staging/src/k8s.io/api/apps/v1:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
Expand Down