volume_manager_fake.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. Copyright 2019 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 volumemanager
  14. import (
  15. "k8s.io/api/core/v1"
  16. "k8s.io/kubernetes/pkg/kubelet/config"
  17. "k8s.io/kubernetes/pkg/kubelet/container"
  18. "k8s.io/kubernetes/pkg/volume/util/types"
  19. )
  20. // FakeVolumeManager is a test implementation that just tracks calls
  21. type FakeVolumeManager struct {
  22. volumes map[v1.UniqueVolumeName]bool
  23. reportedInUse map[v1.UniqueVolumeName]bool
  24. }
  25. // NewFakeVolumeManager creates a new VolumeManager test instance
  26. func NewFakeVolumeManager(initialVolumes []v1.UniqueVolumeName) *FakeVolumeManager {
  27. volumes := map[v1.UniqueVolumeName]bool{}
  28. for _, v := range initialVolumes {
  29. volumes[v] = true
  30. }
  31. return &FakeVolumeManager{
  32. volumes: volumes,
  33. reportedInUse: map[v1.UniqueVolumeName]bool{},
  34. }
  35. }
  36. // Run is not implemented
  37. func (f *FakeVolumeManager) Run(sourcesReady config.SourcesReady, stopCh <-chan struct{}) {
  38. }
  39. // WaitForAttachAndMount is not implemented
  40. func (f *FakeVolumeManager) WaitForAttachAndMount(pod *v1.Pod) error {
  41. return nil
  42. }
  43. // GetMountedVolumesForPod is not implemented
  44. func (f *FakeVolumeManager) GetMountedVolumesForPod(podName types.UniquePodName) container.VolumeMap {
  45. return nil
  46. }
  47. // GetExtraSupplementalGroupsForPod is not implemented
  48. func (f *FakeVolumeManager) GetExtraSupplementalGroupsForPod(pod *v1.Pod) []int64 {
  49. return nil
  50. }
  51. // GetVolumesInUse returns a list of the initial volumes
  52. func (f *FakeVolumeManager) GetVolumesInUse() []v1.UniqueVolumeName {
  53. inuse := []v1.UniqueVolumeName{}
  54. for v := range f.volumes {
  55. inuse = append(inuse, v)
  56. }
  57. return inuse
  58. }
  59. // ReconcilerStatesHasBeenSynced is not implemented
  60. func (f *FakeVolumeManager) ReconcilerStatesHasBeenSynced() bool {
  61. return true
  62. }
  63. // VolumeIsAttached is not implemented
  64. func (f *FakeVolumeManager) VolumeIsAttached(volumeName v1.UniqueVolumeName) bool {
  65. return false
  66. }
  67. // MarkVolumesAsReportedInUse adds the given volumes to the reportedInUse map
  68. func (f *FakeVolumeManager) MarkVolumesAsReportedInUse(volumesReportedAsInUse []v1.UniqueVolumeName) {
  69. for _, reportedVolume := range volumesReportedAsInUse {
  70. if _, ok := f.volumes[reportedVolume]; ok {
  71. f.reportedInUse[reportedVolume] = true
  72. }
  73. }
  74. }
  75. // GetVolumesReportedInUse is a test function only that returns a list of volumes
  76. // from the reportedInUse map
  77. func (f *FakeVolumeManager) GetVolumesReportedInUse() []v1.UniqueVolumeName {
  78. inuse := []v1.UniqueVolumeName{}
  79. for reportedVolume := range f.reportedInUse {
  80. inuse = append(inuse, reportedVolume)
  81. }
  82. return inuse
  83. }