fake_cache.go 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. Copyright 2015 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package fake
  14. import (
  15. "k8s.io/api/core/v1"
  16. "k8s.io/apimachinery/pkg/labels"
  17. "k8s.io/kubernetes/pkg/scheduler/algorithm"
  18. internalcache "k8s.io/kubernetes/pkg/scheduler/internal/cache"
  19. )
  20. // Cache is used for testing
  21. type Cache struct {
  22. AssumeFunc func(*v1.Pod)
  23. ForgetFunc func(*v1.Pod)
  24. IsAssumedPodFunc func(*v1.Pod) bool
  25. GetPodFunc func(*v1.Pod) *v1.Pod
  26. }
  27. // AssumePod is a fake method for testing.
  28. func (c *Cache) AssumePod(pod *v1.Pod) error {
  29. c.AssumeFunc(pod)
  30. return nil
  31. }
  32. // FinishBinding is a fake method for testing.
  33. func (c *Cache) FinishBinding(pod *v1.Pod) error { return nil }
  34. // ForgetPod is a fake method for testing.
  35. func (c *Cache) ForgetPod(pod *v1.Pod) error {
  36. c.ForgetFunc(pod)
  37. return nil
  38. }
  39. // AddPod is a fake method for testing.
  40. func (c *Cache) AddPod(pod *v1.Pod) error { return nil }
  41. // UpdatePod is a fake method for testing.
  42. func (c *Cache) UpdatePod(oldPod, newPod *v1.Pod) error { return nil }
  43. // RemovePod is a fake method for testing.
  44. func (c *Cache) RemovePod(pod *v1.Pod) error { return nil }
  45. // IsAssumedPod is a fake method for testing.
  46. func (c *Cache) IsAssumedPod(pod *v1.Pod) (bool, error) {
  47. return c.IsAssumedPodFunc(pod), nil
  48. }
  49. // GetPod is a fake method for testing.
  50. func (c *Cache) GetPod(pod *v1.Pod) (*v1.Pod, error) {
  51. return c.GetPodFunc(pod), nil
  52. }
  53. // AddNode is a fake method for testing.
  54. func (c *Cache) AddNode(node *v1.Node) error { return nil }
  55. // UpdateNode is a fake method for testing.
  56. func (c *Cache) UpdateNode(oldNode, newNode *v1.Node) error { return nil }
  57. // RemoveNode is a fake method for testing.
  58. func (c *Cache) RemoveNode(node *v1.Node) error { return nil }
  59. // UpdateNodeInfoSnapshot is a fake method for testing.
  60. func (c *Cache) UpdateNodeInfoSnapshot(nodeSnapshot *internalcache.NodeInfoSnapshot) error {
  61. return nil
  62. }
  63. // List is a fake method for testing.
  64. func (c *Cache) List(s labels.Selector) ([]*v1.Pod, error) { return nil, nil }
  65. // FilteredList is a fake method for testing.
  66. func (c *Cache) FilteredList(filter algorithm.PodFilter, selector labels.Selector) ([]*v1.Pod, error) {
  67. return nil, nil
  68. }
  69. // Snapshot is a fake method for testing
  70. func (c *Cache) Snapshot() *internalcache.Snapshot {
  71. return &internalcache.Snapshot{}
  72. }
  73. // NodeTree is a fake method for testing.
  74. func (c *Cache) NodeTree() *internalcache.NodeTree { return nil }