@@ -27,6 +27,7 @@ import (
27
27
"k8s.io/apimachinery/pkg/runtime"
28
28
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
29
29
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
30
+ corelisters "k8s.io/client-go/listers/core/v1"
30
31
"k8s.io/klog/v2"
31
32
"k8s.io/kubernetes/pkg/scheduler/framework"
32
33
@@ -35,8 +36,8 @@ import (
35
36
pluginconfig "sigs.k8s.io/scheduler-plugins/apis/config"
36
37
networkawareutil "sigs.k8s.io/scheduler-plugins/pkg/networkaware/util"
37
38
38
- appgroupv1a1 "github.com/diktyo-io/appgroup-api/pkg/apis/appgroup/v1alpha1"
39
- nettopov1a1 "github.com/diktyo-io/networktopology-api/pkg/apis/networktopology/v1alpha1"
39
+ agv1alpha1 "github.com/diktyo-io/appgroup-api/pkg/apis/appgroup/v1alpha1"
40
+ ntv1alpha1 "github.com/diktyo-io/networktopology-api/pkg/apis/networktopology/v1alpha1"
40
41
)
41
42
42
43
var _ framework.PreFilterPlugin = & NetworkOverhead {}
@@ -64,6 +65,7 @@ const (
64
65
type NetworkOverhead struct {
65
66
client.Client
66
67
68
+ podLister corelisters.PodLister
67
69
handle framework.Handle
68
70
namespaces []string
69
71
weightsName string
@@ -79,13 +81,13 @@ type PreFilterState struct {
79
81
agName string
80
82
81
83
// AppGroup CR
82
- appGroup * appgroupv1a1 .AppGroup
84
+ appGroup * agv1alpha1 .AppGroup
83
85
84
86
// NetworkTopology CR
85
- networkTopology * nettopov1a1 .NetworkTopology
87
+ networkTopology * ntv1alpha1 .NetworkTopology
86
88
87
89
// Dependency List of the given pod
88
- dependencyList []appgroupv1a1 .DependenciesInfo
90
+ dependencyList []agv1alpha1 .DependenciesInfo
89
91
90
92
// Pods already scheduled based on the dependency list
91
93
scheduledList networkawareutil.ScheduledList
@@ -140,8 +142,8 @@ func New(obj runtime.Object, handle framework.Handle) (framework.Plugin, error)
140
142
141
143
utilruntime .Must (clientgoscheme .AddToScheme (scheme ))
142
144
143
- utilruntime .Must (appgroupv1a1 .AddToScheme (scheme ))
144
- utilruntime .Must (nettopov1a1 .AddToScheme (scheme ))
145
+ utilruntime .Must (agv1alpha1 .AddToScheme (scheme ))
146
+ utilruntime .Must (ntv1alpha1 .AddToScheme (scheme ))
145
147
146
148
client , err := client .New (handle .KubeConfig (), client.Options {
147
149
Scheme : scheme ,
@@ -151,7 +153,9 @@ func New(obj runtime.Object, handle framework.Handle) (framework.Plugin, error)
151
153
}
152
154
153
155
no := & NetworkOverhead {
154
- Client : client ,
156
+ Client : client ,
157
+
158
+ podLister : handle .SharedInformerFactory ().Core ().V1 ().Pods ().Lister (),
155
159
handle : handle ,
156
160
namespaces : args .Namespaces ,
157
161
weightsName : args .WeightsName ,
@@ -199,28 +203,22 @@ func (no *NetworkOverhead) PreFilter(ctx context.Context, state *framework.Cycle
199
203
return nil , framework .NewStatus (framework .Success , "Pod has no dependencies, return" )
200
204
}
201
205
202
- podList := & corev1.PodList {}
203
- if err := no .List (ctx , podList ,
204
- client.MatchingLabelsSelector {
205
- Selector : labels .Set (map [string ]string {
206
- appgroupv1a1 .AppGroupLabel : agName ,
207
- }).AsSelector (),
208
- }); err != nil {
209
- klog .ErrorS (err , "List pods for group failed" )
210
- return nil , framework .NewStatus (
211
- framework .Success , "Error while returning pods from appGroup, return" )
206
+ // Get pods from lister
207
+ selector := labels .Set (map [string ]string {agv1alpha1 .AppGroupLabel : agName }).AsSelector ()
208
+ pods , err := no .podLister .List (selector )
209
+ if err != nil {
210
+ return nil , framework .NewStatus (framework .Success , "Error while returning pods from appGroup, return" )
212
211
}
213
- pods := podList .Items
214
212
215
213
// Return if pods are not yet allocated for the AppGroup...
216
- if pods == nil || len (pods ) == 0 {
214
+ if len (pods ) == 0 {
217
215
return nil , framework .NewStatus (framework .Success , "No pods yet allocated, return" )
218
216
}
219
217
220
218
// Pods already scheduled: Get Scheduled List (Deployment name, replicaID, hostname)
221
219
scheduledList := networkawareutil .GetScheduledList (pods )
222
220
// Check if scheduledList is empty...
223
- if scheduledList == nil || len (scheduledList ) == 0 {
221
+ if len (scheduledList ) == 0 {
224
222
klog .ErrorS (nil , "Scheduled list is empty, return" )
225
223
return nil , framework .NewStatus (framework .Success , "Scheduled list is empty, return" )
226
224
}
@@ -432,8 +430,8 @@ func getMinMaxScores(scores framework.NodeScoreList) (int64, int64) {
432
430
}
433
431
434
432
// sortNetworkTopologyCosts : sort costs if manual weights were selected
435
- func (no * NetworkOverhead ) sortNetworkTopologyCosts (networkTopology * nettopov1a1 .NetworkTopology ) {
436
- if no .weightsName != nettopov1a1 .NetworkTopologyNetperfCosts { // Manual weights were selected
433
+ func (no * NetworkOverhead ) sortNetworkTopologyCosts (networkTopology * ntv1alpha1 .NetworkTopology ) {
434
+ if no .weightsName != ntv1alpha1 .NetworkTopologyNetperfCosts { // Manual weights were selected
437
435
for _ , w := range networkTopology .Spec .Weights {
438
436
// Sort Costs by TopologyKey, might not be sorted since were manually defined
439
437
sort .Sort (networkawareutil .ByTopologyKey (w .TopologyList ))
@@ -444,7 +442,7 @@ func (no *NetworkOverhead) sortNetworkTopologyCosts(networkTopology *nettopov1a1
444
442
// populateCostMap : Populates costMap based on the node being filtered/scored
445
443
func (no * NetworkOverhead ) populateCostMap (
446
444
costMap map [networkawareutil.CostKey ]int64 ,
447
- networkTopology * nettopov1a1 .NetworkTopology ,
445
+ networkTopology * ntv1alpha1 .NetworkTopology ,
448
446
region string ,
449
447
zone string ) {
450
448
for _ , w := range networkTopology .Spec .Weights { // Check the weights List
@@ -454,9 +452,9 @@ func (no *NetworkOverhead) populateCostMap(
454
452
455
453
if region != "" { // Add Region Costs
456
454
// Binary search through CostList: find the Topology Key for region
457
- topologyList := networkawareutil .FindTopologyKey (w .TopologyList , nettopov1a1 .NetworkTopologyRegion )
455
+ topologyList := networkawareutil .FindTopologyKey (w .TopologyList , ntv1alpha1 .NetworkTopologyRegion )
458
456
459
- if no .weightsName != nettopov1a1 .NetworkTopologyNetperfCosts {
457
+ if no .weightsName != ntv1alpha1 .NetworkTopologyNetperfCosts {
460
458
// Sort Costs by origin, might not be sorted since were manually defined
461
459
sort .Sort (networkawareutil .ByOrigin (topologyList ))
462
460
}
@@ -473,9 +471,9 @@ func (no *NetworkOverhead) populateCostMap(
473
471
}
474
472
if zone != "" { // Add Zone Costs
475
473
// Binary search through CostList: find the Topology Key for zone
476
- topologyList := networkawareutil .FindTopologyKey (w .TopologyList , nettopov1a1 .NetworkTopologyZone )
474
+ topologyList := networkawareutil .FindTopologyKey (w .TopologyList , ntv1alpha1 .NetworkTopologyZone )
477
475
478
- if no .weightsName != nettopov1a1 .NetworkTopologyNetperfCosts {
476
+ if no .weightsName != ntv1alpha1 .NetworkTopologyNetperfCosts {
479
477
// Sort Costs by origin, might not be sorted since were manually defined
480
478
sort .Sort (networkawareutil .ByOrigin (topologyList ))
481
479
}
@@ -496,7 +494,7 @@ func (no *NetworkOverhead) populateCostMap(
496
494
// checkMaxNetworkCostRequirements : verifies the number of met and unmet dependencies based on the pod being filtered
497
495
func checkMaxNetworkCostRequirements (
498
496
scheduledList networkawareutil.ScheduledList ,
499
- dependencyList []appgroupv1a1 .DependenciesInfo ,
497
+ dependencyList []agv1alpha1 .DependenciesInfo ,
500
498
nodeInfo * framework.NodeInfo ,
501
499
region string ,
502
500
zone string ,
@@ -571,7 +569,7 @@ func checkMaxNetworkCostRequirements(
571
569
// getAccumulatedCost : calculate the accumulated cost based on the Pod's dependencies
572
570
func (no * NetworkOverhead ) getAccumulatedCost (
573
571
scheduledList networkawareutil.ScheduledList ,
574
- dependencyList []appgroupv1a1 .DependenciesInfo ,
572
+ dependencyList []agv1alpha1 .DependenciesInfo ,
575
573
nodeName string ,
576
574
region string ,
577
575
zone string ,
@@ -647,12 +645,12 @@ func getPreFilterState(cycleState *framework.CycleState) (*PreFilterState, error
647
645
return state , nil
648
646
}
649
647
650
- func (no * NetworkOverhead ) findAppGroupNetworkOverhead (agName string ) * appgroupv1a1 .AppGroup {
648
+ func (no * NetworkOverhead ) findAppGroupNetworkOverhead (agName string ) * agv1alpha1 .AppGroup {
651
649
klog .V (6 ).InfoS ("namespaces: %s" , no .namespaces )
652
650
for _ , namespace := range no .namespaces {
653
651
klog .V (6 ).InfoS ("appGroup CR" , "namespace" , namespace , "name" , agName )
654
652
// AppGroup could not be placed in several namespaces simultaneously
655
- appGroup := & appgroupv1a1 .AppGroup {}
653
+ appGroup := & agv1alpha1 .AppGroup {}
656
654
err := no .Get (context .TODO (), client.ObjectKey {
657
655
Namespace : namespace ,
658
656
Name : agName ,
@@ -668,12 +666,12 @@ func (no *NetworkOverhead) findAppGroupNetworkOverhead(agName string) *appgroupv
668
666
return nil
669
667
}
670
668
671
- func (no * NetworkOverhead ) findNetworkTopologyNetworkOverhead () * nettopov1a1 .NetworkTopology {
669
+ func (no * NetworkOverhead ) findNetworkTopologyNetworkOverhead () * ntv1alpha1 .NetworkTopology {
672
670
klog .V (6 ).InfoS ("namespaces: %s" , no .namespaces )
673
671
for _ , namespace := range no .namespaces {
674
672
klog .V (6 ).InfoS ("networkTopology CR:" , "namespace" , namespace , "name" , no .ntName )
675
673
// NetworkTopology could not be placed in several namespaces simultaneously
676
- networkTopology := & nettopov1a1 .NetworkTopology {}
674
+ networkTopology := & ntv1alpha1 .NetworkTopology {}
677
675
err := no .Get (context .TODO (), client.ObjectKey {
678
676
Namespace : namespace ,
679
677
Name : no .ntName ,
0 commit comments