in pkg/capacityscheduling/capacity_scheduling.go [105:185]
func New(obj runtime.Object, handle framework.Handle) (framework.Plugin, error) {
args, ok := obj.(*config.CapacitySchedulingArgs)
if !ok {
return nil, fmt.Errorf("want args to be of type CapacitySchedulingArgs, got %T", obj)
}
kubeConfigPath := args.KubeConfigPath
c := &CapacityScheduling{
fh: handle,
elasticQuotaInfos: NewElasticQuotaInfos(),
podLister: handle.SharedInformerFactory().Core().V1().Pods().Lister(),
pdbLister: getPDBLister(handle.SharedInformerFactory()),
}
restConfig, err := clientcmd.BuildConfigFromFlags("", kubeConfigPath)
if err != nil {
return nil, err
}
client, err := versioned.NewForConfig(restConfig)
if err != nil {
return nil, err
}
schedSharedInformerFactory := schedinformer.NewSharedInformerFactory(client, 0)
c.elasticQuotaLister = schedSharedInformerFactory.Scheduling().V1alpha1().ElasticQuotas().Lister()
elasticQuotaInformer := schedSharedInformerFactory.Scheduling().V1alpha1().ElasticQuotas().Informer()
elasticQuotaInformer.AddEventHandler(
cache.FilteringResourceEventHandler{
FilterFunc: func(obj interface{}) bool {
switch t := obj.(type) {
case *v1alpha1.ElasticQuota:
return true
case cache.DeletedFinalStateUnknown:
if _, ok := t.Obj.(*v1alpha1.ElasticQuota); ok {
return true
}
utilruntime.HandleError(fmt.Errorf("cannot convert to *v1alpha1.ElasticQuota: %v", obj))
return false
default:
utilruntime.HandleError(fmt.Errorf("unable to handle object in %T", obj))
return false
}
},
Handler: cache.ResourceEventHandlerFuncs{
AddFunc: c.addElasticQuota,
UpdateFunc: c.updateElasticQuota,
DeleteFunc: c.deleteElasticQuota,
},
})
schedSharedInformerFactory.Start(nil)
if !cache.WaitForCacheSync(nil, elasticQuotaInformer.HasSynced) {
return nil, fmt.Errorf("timed out waiting for caches to sync %v", Name)
}
podInformer := handle.SharedInformerFactory().Core().V1().Pods().Informer()
podInformer.AddEventHandler(
cache.FilteringResourceEventHandler{
FilterFunc: func(obj interface{}) bool {
switch t := obj.(type) {
case *v1.Pod:
return assignedPod(t)
case cache.DeletedFinalStateUnknown:
if pod, ok := t.Obj.(*v1.Pod); ok {
return assignedPod(pod)
}
return false
default:
return false
}
},
Handler: cache.ResourceEventHandlerFuncs{
AddFunc: c.addPod,
UpdateFunc: c.updatePod,
DeleteFunc: c.deletePod,
},
},
)
klog.Infof("CapacityScheduling start")
return c, nil
}