k3s/vendor/k8s.io/kubernetes/pkg/scheduler/volumebinder/volume_binder.go

62 lines
2.0 KiB
Go
Raw Normal View History

2019-01-12 04:58:27 +00:00
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package volumebinder
import (
"time"
"k8s.io/api/core/v1"
coreinformers "k8s.io/client-go/informers/core/v1"
storageinformers "k8s.io/client-go/informers/storage/v1"
clientset "k8s.io/client-go/kubernetes"
2019-08-30 18:33:25 +00:00
volumescheduling "k8s.io/kubernetes/pkg/controller/volume/scheduling"
2019-01-12 04:58:27 +00:00
)
// VolumeBinder sets up the volume binding library
type VolumeBinder struct {
2019-08-30 18:33:25 +00:00
Binder volumescheduling.SchedulerVolumeBinder
2019-01-12 04:58:27 +00:00
}
// NewVolumeBinder sets up the volume binding library and binding queue
func NewVolumeBinder(
client clientset.Interface,
2019-04-07 17:07:55 +00:00
nodeInformer coreinformers.NodeInformer,
2019-01-12 04:58:27 +00:00
pvcInformer coreinformers.PersistentVolumeClaimInformer,
pvInformer coreinformers.PersistentVolumeInformer,
storageClassInformer storageinformers.StorageClassInformer,
bindTimeout time.Duration) *VolumeBinder {
return &VolumeBinder{
2019-08-30 18:33:25 +00:00
Binder: volumescheduling.NewVolumeBinder(client, nodeInformer, pvcInformer, pvInformer, storageClassInformer, bindTimeout),
2019-01-12 04:58:27 +00:00
}
}
// NewFakeVolumeBinder sets up a fake volume binder and binding queue
2019-08-30 18:33:25 +00:00
func NewFakeVolumeBinder(config *volumescheduling.FakeVolumeBinderConfig) *VolumeBinder {
2019-01-12 04:58:27 +00:00
return &VolumeBinder{
2019-08-30 18:33:25 +00:00
Binder: volumescheduling.NewFakeVolumeBinder(config),
2019-01-12 04:58:27 +00:00
}
}
// DeletePodBindings will delete the cached volume bindings for the given pod.
func (b *VolumeBinder) DeletePodBindings(pod *v1.Pod) {
cache := b.Binder.GetBindingsCache()
if cache != nil && pod != nil {
cache.DeleteBindings(pod)
}
}