@@ -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 {
@@ -1217,10 +1221,7 @@ func TestSyncPendingJob(t *testing.T) {
12171221 ExpectedURL : "boop-42/error" ,
12181222 },
12191223 {
1220- // TODO: this test case tests the current behavior, but the behavior
1221- // is non-ideal: the pod execution did not fail, instead the node on which
1222- // the pod was running terminated
1223- Name : "a terminated pod is handled as-if it failed" ,
1224+ Name : "delete terminated pod" ,
12241225 PJ : prowapi.ProwJob {
12251226 ObjectMeta : metav1.ObjectMeta {
12261227 Name : "boop-42" ,
@@ -1246,8 +1247,72 @@ func TestSyncPendingJob(t *testing.T) {
12461247 },
12471248 },
12481249 },
1250+ ExpectedComplete : false ,
1251+ ExpectedState : prowapi .PendingState ,
1252+ ExpectedNumPods : 0 ,
1253+ },
1254+ {
1255+ Name : "delete terminated pod and remove its k8sreporter finalizer" ,
1256+ PJ : prowapi.ProwJob {
1257+ ObjectMeta : metav1.ObjectMeta {
1258+ Name : "boop-42" ,
1259+ Namespace : "prowjobs" ,
1260+ },
1261+ Spec : prowapi.ProwJobSpec {
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+ Finalizers : []string {"prow.x-k8s.io/gcsk8sreporter" },
1275+ },
1276+ Status : v1.PodStatus {
1277+ Phase : v1 .PodFailed ,
1278+ Reason : Terminated ,
1279+ },
1280+ },
1281+ },
1282+ ExpectedComplete : false ,
1283+ ExpectedState : prowapi .PendingState ,
1284+ ExpectedNumPods : 0 ,
1285+ },
1286+ {
1287+ Name : "don't delete terminated pod w/ error_on_termination, complete PJ instead" ,
1288+ PJ : prowapi.ProwJob {
1289+ ObjectMeta : metav1.ObjectMeta {
1290+ Name : "boop-42" ,
1291+ Namespace : "prowjobs" ,
1292+ },
1293+ Spec : prowapi.ProwJobSpec {
1294+ ErrorOnTermination : true ,
1295+ PodSpec : & v1.PodSpec {Containers : []v1.Container {{Name : "test-name" , Env : []v1.EnvVar {}}}},
1296+ },
1297+ Status : prowapi.ProwJobStatus {
1298+ State : prowapi .PendingState ,
1299+ PodName : "boop-42" ,
1300+ },
1301+ },
1302+ Pods : []v1.Pod {
1303+ {
1304+ ObjectMeta : metav1.ObjectMeta {
1305+ Name : "boop-42" ,
1306+ Namespace : "pods" ,
1307+ },
1308+ Status : v1.PodStatus {
1309+ Phase : v1 .PodFailed ,
1310+ Reason : Terminated ,
1311+ },
1312+ },
1313+ },
12491314 ExpectedComplete : true ,
1250- ExpectedState : prowapi .FailureState ,
1315+ ExpectedState : prowapi .ErrorState ,
12511316 ExpectedNumPods : 1 ,
12521317 ExpectedURL : "boop-42/error" ,
12531318 },
0 commit comments