Skip to content

Commit

Permalink
Merge pull request #278 from k82cn/273_3
Browse files Browse the repository at this point in the history
Updated EventHandler type.
  • Loading branch information
k82cn authored Jul 7, 2018
2 parents e7de4ea + 1a4c0f8 commit 720168c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 72 deletions.
2 changes: 1 addition & 1 deletion pkg/apis/v1alpha1/schedulingspec.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type SchedulingSpec struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata"`

Spec SchedulingSpecTemplate `json:"spec"`
Spec SchedulingSpecTemplate `json:"spec,omitempty" protobuf:"bytes,1,rep,name=spec"`
}

type SchedulingSpecTemplate struct {
Expand Down
10 changes: 2 additions & 8 deletions pkg/client/informers/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,9 @@ type SharedInformerFactory interface {
ForResource(resource schema.GroupVersionResource) (GenericInformer, error)
WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool

SchedulingSpec() arbclient.Interface

QueueJob() arbclient.Interface
}

func (f *sharedInformerFactory) SchedulingSpec() arbclient.Interface {
return arbclient.New(f)
Batch() arbclient.Interface
}

func (f *sharedInformerFactory) QueueJob() arbclient.Interface {
func (f *sharedInformerFactory) Batch() arbclient.Interface {
return arbclient.New(f)
}
5 changes: 2 additions & 3 deletions pkg/client/informers/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,15 @@ func (f *genericInformer) Lister() cache.GenericLister {
func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) {
switch resource {
// Group=, Version=V1

case arbv1.SchemeGroupVersion.WithResource("schedulingspecs"):
return &genericInformer{
resource: resource.GroupResource(),
informer: f.SchedulingSpec().SchedulingSpecs().Informer(),
informer: f.Batch().SchedulingSpecs().Informer(),
}, nil
case arbv1.SchemeGroupVersion.WithResource("queuejobs"):
return &genericInformer{
resource: resource.GroupResource(),
informer: f.QueueJob().QueueJobs().Informer(),
informer: f.Batch().QueueJobs().Informer(),
}, nil
}

Expand Down
44 changes: 11 additions & 33 deletions pkg/controller/queuejob/queuejob_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,44 +84,22 @@ func NewQueueJobController(config *rest.Config) *Controller {
panic(err)
}

cc.queueJobInformer = arbinformers.NewSharedInformerFactory(queueJobClient, 0).QueueJob().QueueJobs()
cc.queueJobInformer.Informer().AddEventHandler(
cache.FilteringResourceEventHandler{
FilterFunc: func(obj interface{}) bool {
switch t := obj.(type) {
case *arbv1.QueueJob:
glog.V(4).Infof("Filter QueueJob name(%s) namespace(%s)\n", t.Name, t.Namespace)
return true
default:
return false
}
},
Handler: cache.ResourceEventHandlerFuncs{
AddFunc: cc.addQueueJob,
UpdateFunc: cc.updateQueueJob,
DeleteFunc: cc.deleteQueueJob,
},
})
cc.queueJobInformer = arbinformers.NewSharedInformerFactory(queueJobClient, 0).Batch().QueueJobs()
cc.queueJobInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: cc.addQueueJob,
UpdateFunc: cc.updateQueueJob,
DeleteFunc: cc.deleteQueueJob,
})
cc.queueJobLister = cc.queueJobInformer.Lister()
cc.queueJobSynced = cc.queueJobInformer.Informer().HasSynced

cc.podInformer = informers.NewSharedInformerFactory(cc.clients, 0).Core().V1().Pods()
cc.podInformer.Informer().AddEventHandler(cache.FilteringResourceEventHandler{
FilterFunc: func(obj interface{}) bool {
switch t := obj.(type) {
case *v1.Pod:
glog.V(4).Infof("Filter Pod name(%s) namespace(%s)\n", t.Name, t.Namespace)
return true
default:
return false
}
},
Handler: cache.ResourceEventHandlerFuncs{
AddFunc: cc.addPod,
UpdateFunc: cc.updatePod,
DeleteFunc: cc.deletePod,
},
cc.podInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: cc.addPod,
UpdateFunc: cc.updatePod,
DeleteFunc: cc.deletePod,
})

cc.podListr = cc.podInformer.Lister()
cc.podSynced = cc.podInformer.Informer().HasSynced

Expand Down
38 changes: 11 additions & 27 deletions pkg/scheduler/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import (
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/cache"

arbv1 "github.com/kubernetes-incubator/kube-arbitrator/pkg/apis/v1alpha1"
"github.com/kubernetes-incubator/kube-arbitrator/pkg/client"
informerfactory "github.com/kubernetes-incubator/kube-arbitrator/pkg/client/informers"
arbclient "github.com/kubernetes-incubator/kube-arbitrator/pkg/client/informers/v1"
Expand Down Expand Up @@ -183,14 +182,11 @@ func newSchedulerCache(config *rest.Config, schedulerName string) *SchedulerCach
})

sc.pdbInformer = informerFactory.Policy().V1beta1().PodDisruptionBudgets()
sc.pdbInformer.Informer().AddEventHandler(
cache.FilteringResourceEventHandler{
Handler: cache.ResourceEventHandlerFuncs{
AddFunc: sc.AddPDB,
UpdateFunc: sc.UpdatePDB,
DeleteFunc: sc.DeletePDB,
},
})
sc.pdbInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: sc.AddPDB,
UpdateFunc: sc.UpdatePDB,
DeleteFunc: sc.DeletePDB,
})

// create queue informer
queueClient, _, err := client.NewClient(config)
Expand All @@ -200,24 +196,12 @@ func newSchedulerCache(config *rest.Config, schedulerName string) *SchedulerCach

schedulingSpecInformerFactory := informerfactory.NewSharedInformerFactory(queueClient, 0)
// create informer for Queue information
sc.schedulingSpecInformer = schedulingSpecInformerFactory.SchedulingSpec().SchedulingSpecs()
sc.schedulingSpecInformer.Informer().AddEventHandler(
cache.FilteringResourceEventHandler{
FilterFunc: func(obj interface{}) bool {
switch t := obj.(type) {
case *arbv1.SchedulingSpec:
glog.V(4).Infof("Filter Queue name(%s) namespace(%s)\n", t.Name, t.Namespace)
return true
default:
return false
}
},
Handler: cache.ResourceEventHandlerFuncs{
AddFunc: sc.AddSchedulingSpec,
UpdateFunc: sc.UpdateSchedulingSpec,
DeleteFunc: sc.DeleteSchedulingSpec,
},
})
sc.schedulingSpecInformer = schedulingSpecInformerFactory.Batch().SchedulingSpecs()
sc.schedulingSpecInformer.Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: sc.AddSchedulingSpec,
UpdateFunc: sc.UpdateSchedulingSpec,
DeleteFunc: sc.DeleteSchedulingSpec,
})

return sc
}
Expand Down

0 comments on commit 720168c

Please sign in to comment.