@@ -545,11 +545,67 @@ func TestPod_SetPreferredArchNodeAffinityWithCPPC(t *testing.T) {
545545 imageInspectionCache = fake .FacadeSingleton ()
546546 pod := newPod (tt .pod , ctx , nil )
547547 g := NewGomegaWithT (t )
548- pod .SetPreferredArchNodeAffinity (
549- NewClusterPodPlacementConfig ().
550- WithName (common .SingletonResourceObjectName ).
551- WithNodeAffinityScoring (true ).
552- WithNodeAffinityScoringTerm (utils .ArchitectureAmd64 , 1 ).Build ())
548+ cppc := NewClusterPodPlacementConfig ().
549+ WithName (common .SingletonResourceObjectName ).
550+ WithNodeAffinityScoring (true ).
551+ WithNodeAffinityScoringTerm (utils .ArchitectureAmd64 , 1 ).Build ()
552+ pod .SetPreferredArchNodeAffinity (cppc .Spec .Plugins .NodeAffinityScoring )
553+ g .Expect (pod .Spec .Affinity ).Should (Equal (tt .want .Spec .Affinity ))
554+ imageInspectionCache = mmoimage .FacadeSingleton ()
555+ })
556+ }
557+ }
558+
559+ func TestPod_SetPreferredArchNodeAffinityPPC (t * testing.T ) {
560+ tests := []struct {
561+ name string
562+ pod * v1.Pod
563+ want * v1.Pod
564+ }{
565+ {
566+ name : "pod with no predefined preferred affinity" ,
567+ pod : NewPod ().WithContainersImages (fake .SingleArchAmd64Image ).Build (),
568+ want : NewPod ().WithContainersImages (fake .SingleArchAmd64Image ).WithPreferredDuringSchedulingIgnoredDuringExecution (
569+ NewPreferredSchedulingTerm ().WithArchitecture (utils .ArchitectureAmd64 ).WithWeight (1 ).Build (),
570+ ).Build (),
571+ },
572+ {
573+ name : "pod with predefined preferred node affinity" ,
574+ pod : NewPod ().WithContainersImages (fake .SingleArchAmd64Image ).WithPreferredDuringSchedulingIgnoredDuringExecution (
575+ NewPreferredSchedulingTerm ().WithCustomKeyValue ("foo" , "bar" ).WithWeight (50 ).Build (),
576+ ).Build (),
577+ want : NewPod ().WithContainersImages (fake .SingleArchAmd64Image ).WithPreferredDuringSchedulingIgnoredDuringExecution (
578+ NewPreferredSchedulingTerm ().WithCustomKeyValue ("foo" , "bar" ).WithWeight (50 ).Build (),
579+ NewPreferredSchedulingTerm ().WithArchitecture (utils .ArchitectureAmd64 ).WithWeight (1 ).Build (),
580+ ).Build (),
581+ },
582+ {
583+ name : "pod with predefined preferred node affinity with arch label set" ,
584+ pod : NewPod ().WithContainersImages (fake .SingleArchAmd64Image ).WithPreferredDuringSchedulingIgnoredDuringExecution (
585+ NewPreferredSchedulingTerm ().WithArchitecture (utils .ArchitectureAmd64 ).WithWeight (30 ).Build (),
586+ ).Build (),
587+ want : NewPod ().WithContainersImages (fake .SingleArchAmd64Image ).WithPreferredDuringSchedulingIgnoredDuringExecution (
588+ NewPreferredSchedulingTerm ().WithArchitecture (utils .ArchitectureAmd64 ).WithWeight (30 ).Build (),
589+ ).Build (),
590+ },
591+ }
592+ for _ , tt := range tests {
593+ t .Run (tt .name , func (t * testing.T ) {
594+ imageInspectionCache = fake .FacadeSingleton ()
595+ pod := newPod (tt .pod , ctx , nil )
596+ g := NewGomegaWithT (t )
597+ ppc := NewPodPlacementConfig ().
598+ WithName ("test-high-priority" ).
599+ WithNodeAffinityScoring (true ).
600+ WithPriority (10 ).
601+ WithNodeAffinityScoringTerm (utils .ArchitectureAmd64 , 1 ).Build ()
602+ pod .SetPreferredArchNodeAffinity (ppc .Spec .Plugins .NodeAffinityScoring )
603+ ppc = NewPodPlacementConfig ().
604+ WithName ("test-low-priority" ).
605+ WithNodeAffinityScoring (true ).
606+ WithPriority (5 ).
607+ WithNodeAffinityScoringTerm (utils .ArchitectureAmd64 , 5 ).Build ()
608+ pod .SetPreferredArchNodeAffinity (ppc .Spec .Plugins .NodeAffinityScoring )
553609 g .Expect (pod .Spec .Affinity ).Should (Equal (tt .want .Spec .Affinity ))
554610 imageInspectionCache = mmoimage .FacadeSingleton ()
555611 })
@@ -573,7 +629,7 @@ func TestPod_SetPreferredArchNodeAffinity(t *testing.T) {
573629 imageInspectionCache = fake .FacadeSingleton ()
574630 pod := newPod (tt .pod , ctx , nil )
575631 g := NewGomegaWithT (t )
576- pod . SetPreferredArchNodeAffinity ( & v1beta1.ClusterPodPlacementConfig {
632+ cppc := & v1beta1.ClusterPodPlacementConfig {
577633 ObjectMeta : metav1.ObjectMeta {
578634 Name : "cluster" ,
579635 },
@@ -587,7 +643,8 @@ func TestPod_SetPreferredArchNodeAffinity(t *testing.T) {
587643 },
588644 },
589645 },
590- })
646+ }
647+ pod .SetPreferredArchNodeAffinity (cppc .Spec .Plugins .NodeAffinityScoring )
591648 g .Expect (pod .Spec .Affinity ).Should (Equal (tt .want .Spec .Affinity ))
592649 imageInspectionCache = mmoimage .FacadeSingleton ()
593650 })
0 commit comments