volume_binder.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 volumebinder
  14. import (
  15. "time"
  16. "k8s.io/api/core/v1"
  17. coreinformers "k8s.io/client-go/informers/core/v1"
  18. storageinformers "k8s.io/client-go/informers/storage/v1"
  19. clientset "k8s.io/client-go/kubernetes"
  20. volumescheduling "k8s.io/kubernetes/pkg/controller/volume/scheduling"
  21. )
  22. // VolumeBinder sets up the volume binding library
  23. type VolumeBinder struct {
  24. Binder volumescheduling.SchedulerVolumeBinder
  25. }
  26. // NewVolumeBinder sets up the volume binding library and binding queue
  27. func NewVolumeBinder(
  28. client clientset.Interface,
  29. nodeInformer coreinformers.NodeInformer,
  30. pvcInformer coreinformers.PersistentVolumeClaimInformer,
  31. pvInformer coreinformers.PersistentVolumeInformer,
  32. storageClassInformer storageinformers.StorageClassInformer,
  33. bindTimeout time.Duration) *VolumeBinder {
  34. return &VolumeBinder{
  35. Binder: volumescheduling.NewVolumeBinder(client, nodeInformer, pvcInformer, pvInformer, storageClassInformer, bindTimeout),
  36. }
  37. }
  38. // NewFakeVolumeBinder sets up a fake volume binder and binding queue
  39. func NewFakeVolumeBinder(config *volumescheduling.FakeVolumeBinderConfig) *VolumeBinder {
  40. return &VolumeBinder{
  41. Binder: volumescheduling.NewFakeVolumeBinder(config),
  42. }
  43. }
  44. // DeletePodBindings will delete the cached volume bindings for the given pod.
  45. func (b *VolumeBinder) DeletePodBindings(pod *v1.Pod) {
  46. cache := b.Binder.GetBindingsCache()
  47. if cache != nil && pod != nil {
  48. cache.DeleteBindings(pod)
  49. }
  50. }