@@ -65,7 +65,10 @@ const (
6565 podDeletionPreventionFinalizer = "keep-from-vanishing"
6666)
6767
68- var maxRevivals = 3
68+ var (
69+ maxRevivals = 3
70+ terminationConditionReasons = []string {"DeletionByPodGC" , "DeletionByGCPControllerManager" }
71+ )
6972
7073func newFakeConfigAgent (t * testing.T , maxConcurrency int , queueCapacities map [string ]int ) * fca {
7174 presubmits := []config.Presubmit {
@@ -104,11 +107,12 @@ func newFakeConfigAgent(t *testing.T, maxConcurrency int, queueCapacities map[st
104107 MaxConcurrency : maxConcurrency ,
105108 MaxGoroutines : 20 ,
106109 },
107- JobQueueCapacities : queueCapacities ,
108- PodPendingTimeout : & metav1.Duration {Duration : podPendingTimeout },
109- PodRunningTimeout : & metav1.Duration {Duration : podRunningTimeout },
110- PodUnscheduledTimeout : & metav1.Duration {Duration : podUnscheduledTimeout },
111- MaxRevivals : & maxRevivals ,
110+ JobQueueCapacities : queueCapacities ,
111+ PodPendingTimeout : & metav1.Duration {Duration : podPendingTimeout },
112+ PodRunningTimeout : & metav1.Duration {Duration : podRunningTimeout },
113+ PodUnscheduledTimeout : & metav1.Duration {Duration : podUnscheduledTimeout },
114+ MaxRevivals : & maxRevivals ,
115+ TerminationConditionReasons : terminationConditionReasons ,
112116 },
113117 },
114118 JobConfig : config.JobConfig {
@@ -1184,10 +1188,7 @@ func TestSyncPendingJob(t *testing.T) {
11841188 ExpectedURL : "boop-42/error" ,
11851189 },
11861190 {
1187- // TODO: this test case tests the current behavior, but the behavior
1188- // is non-ideal: the pod execution did not fail, instead the node on which
1189- // the pod was running terminated
1190- Name : "a terminated pod is handled as-if it failed" ,
1191+ Name : "delete terminated pod" ,
11911192 PJ : prowapi.ProwJob {
11921193 ObjectMeta : metav1.ObjectMeta {
11931194 Name : "boop-42" ,
@@ -1213,8 +1214,72 @@ func TestSyncPendingJob(t *testing.T) {
12131214 },
12141215 },
12151216 },
1217+ ExpectedComplete : false ,
1218+ ExpectedState : prowapi .PendingState ,
1219+ ExpectedNumPods : 0 ,
1220+ },
1221+ {
1222+ Name : "delete terminated pod and remove its k8sreporter finalizer" ,
1223+ PJ : prowapi.ProwJob {
1224+ ObjectMeta : metav1.ObjectMeta {
1225+ Name : "boop-42" ,
1226+ Namespace : "prowjobs" ,
1227+ },
1228+ Spec : prowapi.ProwJobSpec {
1229+ PodSpec : & v1.PodSpec {Containers : []v1.Container {{Name : "test-name" , Env : []v1.EnvVar {}}}},
1230+ },
1231+ Status : prowapi.ProwJobStatus {
1232+ State : prowapi .PendingState ,
1233+ PodName : "boop-42" ,
1234+ },
1235+ },
1236+ Pods : []v1.Pod {
1237+ {
1238+ ObjectMeta : metav1.ObjectMeta {
1239+ Name : "boop-42" ,
1240+ Namespace : "pods" ,
1241+ Finalizers : []string {"prow.x-k8s.io/gcsk8sreporter" },
1242+ },
1243+ Status : v1.PodStatus {
1244+ Phase : v1 .PodFailed ,
1245+ Reason : Terminated ,
1246+ },
1247+ },
1248+ },
1249+ ExpectedComplete : false ,
1250+ ExpectedState : prowapi .PendingState ,
1251+ ExpectedNumPods : 0 ,
1252+ },
1253+ {
1254+ Name : "don't delete terminated pod w/ error_on_termination, complete PJ instead" ,
1255+ PJ : prowapi.ProwJob {
1256+ ObjectMeta : metav1.ObjectMeta {
1257+ Name : "boop-42" ,
1258+ Namespace : "prowjobs" ,
1259+ },
1260+ Spec : prowapi.ProwJobSpec {
1261+ ErrorOnTermination : true ,
1262+ PodSpec : & v1.PodSpec {Containers : []v1.Container {{Name : "test-name" , Env : []v1.EnvVar {}}}},
1263+ },
1264+ Status : prowapi.ProwJobStatus {
1265+ State : prowapi .PendingState ,
1266+ PodName : "boop-42" ,
1267+ },
1268+ },
1269+ Pods : []v1.Pod {
1270+ {
1271+ ObjectMeta : metav1.ObjectMeta {
1272+ Name : "boop-42" ,
1273+ Namespace : "pods" ,
1274+ },
1275+ Status : v1.PodStatus {
1276+ Phase : v1 .PodFailed ,
1277+ Reason : Terminated ,
1278+ },
1279+ },
1280+ },
12161281 ExpectedComplete : true ,
1217- ExpectedState : prowapi .FailureState ,
1282+ ExpectedState : prowapi .ErrorState ,
12181283 ExpectedNumPods : 1 ,
12191284 ExpectedURL : "boop-42/error" ,
12201285 },
0 commit comments