scheduler_binder_fake.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. Copyright 2017 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 scheduling
  14. import "k8s.io/api/core/v1"
  15. // FakeVolumeBinderConfig holds configurations for fake volume binder.
  16. type FakeVolumeBinderConfig struct {
  17. AllBound bool
  18. FindUnboundSatsified bool
  19. FindBoundSatsified bool
  20. FindErr error
  21. AssumeErr error
  22. BindErr error
  23. }
  24. // NewFakeVolumeBinder sets up all the caches needed for the scheduler to make
  25. // topology-aware volume binding decisions.
  26. func NewFakeVolumeBinder(config *FakeVolumeBinderConfig) *FakeVolumeBinder {
  27. return &FakeVolumeBinder{
  28. config: config,
  29. }
  30. }
  31. // FakeVolumeBinder represents a fake volume binder for testing.
  32. type FakeVolumeBinder struct {
  33. config *FakeVolumeBinderConfig
  34. AssumeCalled bool
  35. BindCalled bool
  36. }
  37. // FindPodVolumes implements SchedulerVolumeBinder.FindPodVolumes.
  38. func (b *FakeVolumeBinder) FindPodVolumes(pod *v1.Pod, node *v1.Node) (unboundVolumesSatisfied, boundVolumesSatsified bool, err error) {
  39. return b.config.FindUnboundSatsified, b.config.FindBoundSatsified, b.config.FindErr
  40. }
  41. // AssumePodVolumes implements SchedulerVolumeBinder.AssumePodVolumes.
  42. func (b *FakeVolumeBinder) AssumePodVolumes(assumedPod *v1.Pod, nodeName string) (bool, error) {
  43. b.AssumeCalled = true
  44. return b.config.AllBound, b.config.AssumeErr
  45. }
  46. // BindPodVolumes implements SchedulerVolumeBinder.BindPodVolumes.
  47. func (b *FakeVolumeBinder) BindPodVolumes(assumedPod *v1.Pod) error {
  48. b.BindCalled = true
  49. return b.config.BindErr
  50. }
  51. // GetBindingsCache implements SchedulerVolumeBinder.GetBindingsCache.
  52. func (b *FakeVolumeBinder) GetBindingsCache() PodBindingCache {
  53. return nil
  54. }