Skip to content

Commit

Permalink
register custom resource events for efficient pod enqueuing
Browse files Browse the repository at this point in the history
  • Loading branch information
Huang-Wei committed Jan 16, 2022
1 parent 7b3182b commit 9a9b458
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
6 changes: 5 additions & 1 deletion pkg/capacityscheduling/capacity_scheduling.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"k8s.io/kubernetes/pkg/scheduler/framework/plugins/defaultpreemption"
schedutil "k8s.io/kubernetes/pkg/scheduler/util"

"sigs.k8s.io/scheduler-plugins/pkg/apis/scheduling"
"sigs.k8s.io/scheduler-plugins/pkg/apis/scheduling/v1alpha1"
"sigs.k8s.io/scheduler-plugins/pkg/generated/clientset/versioned"
schedinformer "sigs.k8s.io/scheduler-plugins/pkg/generated/informers/externalversions"
Expand Down Expand Up @@ -184,9 +185,12 @@ func New(obj runtime.Object, handle framework.Handle) (framework.Plugin, error)
}

func (c *CapacityScheduling) EventsToRegister() []framework.ClusterEvent {
// To register a custom event, follow the naming convention at:
// https://git.k8s.io/kubernetes/pkg/scheduler/eventhandlers.go#L403-L410
eqGVK := fmt.Sprintf("elasticquotas.v1alpha1.%v", scheduling.GroupName)
return []framework.ClusterEvent{
{Resource: framework.Pod, ActionType: framework.Delete},
// TODO: once bump the dependency to k8s 1.22, addd custom object events.
{Resource: framework.GVK(eqGVK), ActionType: framework.Add | framework.Update},
}
}

Expand Down
6 changes: 5 additions & 1 deletion pkg/coscheduling/coscheduling.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"k8s.io/kubernetes/pkg/scheduler/framework"

"sigs.k8s.io/scheduler-plugins/pkg/apis/config"
"sigs.k8s.io/scheduler-plugins/pkg/apis/scheduling"
"sigs.k8s.io/scheduler-plugins/pkg/coscheduling/core"
pgclientset "sigs.k8s.io/scheduler-plugins/pkg/generated/clientset/versioned"
pgformers "sigs.k8s.io/scheduler-plugins/pkg/generated/informers/externalversions"
Expand Down Expand Up @@ -89,9 +90,12 @@ func New(obj runtime.Object, handle framework.Handle) (framework.Plugin, error)
}

func (cs *Coscheduling) EventsToRegister() []framework.ClusterEvent {
// To register a custom event, follow the naming convention at:
// https://git.k8s.io/kubernetes/pkg/scheduler/eventhandlers.go#L403-L410
pgGVK := fmt.Sprintf("podgroups.v1alpha1.%v", scheduling.GroupName)
return []framework.ClusterEvent{
{Resource: framework.Pod, ActionType: framework.Add},
// TODO: once bump the dependency to k8s 1.22, addd custom object events.
{Resource: framework.GVK(pgGVK), ActionType: framework.Add | framework.Update},
}
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/noderesourcetopology/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"k8s.io/kubernetes/pkg/scheduler/framework"
apiconfig "sigs.k8s.io/scheduler-plugins/pkg/apis/config"

"github.com/k8stopologyawareschedwg/noderesourcetopology-api/pkg/apis/topology"
topologyv1alpha1 "github.com/k8stopologyawareschedwg/noderesourcetopology-api/pkg/apis/topology/v1alpha1"
listerv1alpha1 "github.com/k8stopologyawareschedwg/noderesourcetopology-api/pkg/generated/listers/topology/v1alpha1"
)
Expand Down Expand Up @@ -117,8 +118,12 @@ func New(args runtime.Object, handle framework.Handle) (framework.Plugin, error)
// should be registered for this plugin since a Pod update may free up resources
// that make other Pods schedulable.
func (tm *TopologyMatch) EventsToRegister() []framework.ClusterEvent {
// To register a custom event, follow the naming convention at:
// https://git.k8s.io/kubernetes/pkg/scheduler/eventhandlers.go#L403-L410
nrtGVK := fmt.Sprintf("noderesourcetopologies.v1alpha1.%v", topologyapi.GroupName)
return []framework.ClusterEvent{
{Resource: framework.Pod, ActionType: framework.Delete},
{Resource: framework.Node, ActionType: framework.Add | framework.UpdateNodeAllocatable},
{Resource: framework.GVK(nrtGVK), ActionType: framework.Add | framework.Update},
}
}

0 comments on commit 9a9b458

Please sign in to comment.