@@ -10,6 +10,9 @@ import (
1010
1111 "github.com/armadaproject/armada/internal/common/types"
1212 "github.com/armadaproject/armada/internal/scheduler/internaltypes"
13+
14+ configuration2 "github.com/armadaproject/armada/internal/scheduler/configuration"
15+ "github.com/armadaproject/armada/internal/server/configuration"
1316)
1417
1518var jobSchedulingInfo = & internaltypes.JobSchedulingInfo {
@@ -26,6 +29,35 @@ var jobSchedulingInfo = &internaltypes.JobSchedulingInfo{
2629 },
2730}
2831
32+ var jobSchedulingInfoWithRetryEnabled = & internaltypes.JobSchedulingInfo {
33+ PodRequirements : & internaltypes.PodRequirements {
34+ ResourceRequirements : v1.ResourceRequirements {
35+ Requests : v1.ResourceList {
36+ "cpu" : k8sResource .MustParse ("1" ),
37+ "storage-connections" : k8sResource .MustParse ("1" ),
38+ },
39+ },
40+ Annotations : map [string ]string {
41+ configuration .PreemptionRetryEnabledAnnotation : "true" ,
42+ configuration .PreemptionRetryCountMaxAnnotation : "1" ,
43+ },
44+ },
45+ }
46+
47+ var jobSchedulingInfoWithRetryDisabled = & internaltypes.JobSchedulingInfo {
48+ PodRequirements : & internaltypes.PodRequirements {
49+ ResourceRequirements : v1.ResourceRequirements {
50+ Requests : v1.ResourceList {
51+ "cpu" : k8sResource .MustParse ("1" ),
52+ "storage-connections" : k8sResource .MustParse ("1" ),
53+ },
54+ },
55+ Annotations : map [string ]string {
56+ configuration .PreemptionRetryEnabledAnnotation : "false" ,
57+ },
58+ },
59+ }
60+
2961var baseJob , _ = jobDb .NewJob (
3062 "test-job" ,
3163 "test-jobSet" ,
@@ -42,6 +74,38 @@ var baseJob, _ = jobDb.NewJob(
4274 []string {},
4375)
4476
77+ var baseJobWithRetryEnabled , _ = jobDb .NewJob (
78+ "test-job" ,
79+ "test-jobSet" ,
80+ "test-queue" ,
81+ 2 ,
82+ jobSchedulingInfoWithRetryEnabled ,
83+ true ,
84+ 0 ,
85+ false ,
86+ false ,
87+ false ,
88+ 3 ,
89+ false ,
90+ []string {},
91+ )
92+
93+ var baseJobWithRetryDisabled , _ = jobDb .NewJob (
94+ "test-job" ,
95+ "test-jobSet" ,
96+ "test-queue" ,
97+ 2 ,
98+ jobSchedulingInfoWithRetryDisabled ,
99+ true ,
100+ 0 ,
101+ false ,
102+ false ,
103+ false ,
104+ 3 ,
105+ false ,
106+ []string {},
107+ )
108+
45109var baseRun = & JobRun {
46110 id : uuid .New ().String (),
47111 created : 3 ,
@@ -425,3 +489,85 @@ func TestJob_TestKubernetesResourceRequirements(t *testing.T) {
425489 assert .Equal (t , int64 (1000 ), baseJob .KubernetesResourceRequirements ().GetByNameZeroIfMissing ("cpu" ))
426490 assert .Equal (t , int64 (0 ), baseJob .KubernetesResourceRequirements ().GetByNameZeroIfMissing ("storage-connections" ))
427491}
492+
493+ func TestIsEligibleForPreemptionRetry (t * testing.T ) {
494+ premptedRun1 := & JobRun {
495+ id : uuid .New ().String (),
496+ created : 3 ,
497+ executor : "test-executor" ,
498+ preempted : true ,
499+ }
500+
501+ premptedRun2 := & JobRun {
502+ id : uuid .New ().String (),
503+ created : 5 ,
504+ executor : "test-executor" ,
505+ preempted : true ,
506+ }
507+
508+ defaultMaxRetryCountEnabled := uint (5 )
509+ platformDefaultEnabled := configuration2.PreemptionRetryConfig {
510+ Enabled : true ,
511+ DefaultMaxRetryCount : & defaultMaxRetryCountEnabled ,
512+ }
513+
514+ defaultMaxRetryCountDisabled := uint (0 )
515+ platformDefaultDisabled := configuration2.PreemptionRetryConfig {
516+ Enabled : false ,
517+ DefaultMaxRetryCount : & defaultMaxRetryCountDisabled ,
518+ }
519+
520+ // no runs
521+ t .Run ("job with retry enabled and platform disabled and no runs" , func (t * testing.T ) {
522+ assert .True (t , baseJobWithRetryEnabled .IsEligibleForPreemptionRetry (platformDefaultDisabled ))
523+ })
524+
525+ t .Run ("job with retry disabled and platform enabled and no runs" , func (t * testing.T ) {
526+ assert .False (t , baseJobWithRetryDisabled .IsEligibleForPreemptionRetry (platformDefaultEnabled ))
527+ })
528+
529+ t .Run ("job with platform retry enabled and no runs" , func (t * testing.T ) {
530+ assert .True (t , baseJob .IsEligibleForPreemptionRetry (platformDefaultEnabled ))
531+ })
532+
533+ t .Run ("job with platform retry disabled and no runs" , func (t * testing.T ) {
534+ assert .False (t , baseJob .IsEligibleForPreemptionRetry (platformDefaultDisabled ))
535+ })
536+
537+ // runs but none are preempted
538+ t .Run ("job with retry enabled and platform disabled runs but no preempted runs" , func (t * testing.T ) {
539+ updatedJob := baseJobWithRetryEnabled .WithUpdatedRun (baseRun ).WithUpdatedRun (baseRun )
540+ assert .True (t , updatedJob .IsEligibleForPreemptionRetry (platformDefaultDisabled ))
541+ })
542+
543+ t .Run ("job with platform enabled runs but no preempted runs" , func (t * testing.T ) {
544+ updatedJob := baseJob .WithUpdatedRun (baseRun ).WithUpdatedRun (baseRun )
545+ assert .True (t , updatedJob .IsEligibleForPreemptionRetry (platformDefaultEnabled ))
546+ })
547+
548+ t .Run ("job with retry enabled and platform disabled and one run" , func (t * testing.T ) {
549+ updatedJob := baseJobWithRetryEnabled .WithUpdatedRun (premptedRun1 )
550+ assert .True (t , updatedJob .IsEligibleForPreemptionRetry (platformDefaultDisabled ))
551+ })
552+
553+ t .Run ("job with platform enabled and one run" , func (t * testing.T ) {
554+ updatedJob := baseJob .WithUpdatedRun (premptedRun1 )
555+ assert .True (t , updatedJob .IsEligibleForPreemptionRetry (platformDefaultEnabled ))
556+ })
557+
558+ // runs that are preempted
559+ t .Run ("job with retry enabled and platform disabled and out of retries" , func (t * testing.T ) {
560+ updatedJob := baseJobWithRetryEnabled .WithUpdatedRun (premptedRun1 ).WithUpdatedRun (premptedRun2 )
561+ assert .False (t , updatedJob .IsEligibleForPreemptionRetry (platformDefaultDisabled ))
562+ })
563+
564+ t .Run ("job with retry enabled with platform enabled and out of retries" , func (t * testing.T ) {
565+ updatedJob := baseJobWithRetryEnabled .WithUpdatedRun (premptedRun1 ).WithUpdatedRun (premptedRun2 )
566+ assert .False (t , updatedJob .IsEligibleForPreemptionRetry (platformDefaultEnabled ))
567+ })
568+
569+ t .Run ("job with platform enabled and retries left" , func (t * testing.T ) {
570+ updatedJob := baseJob .WithUpdatedRun (premptedRun1 ).WithUpdatedRun (premptedRun2 )
571+ assert .True (t , updatedJob .IsEligibleForPreemptionRetry (platformDefaultEnabled ))
572+ })
573+ }
0 commit comments