Skip to content

Commit 3ed17e1

Browse files
committed
adjust syncRecords to include terminated jobs
Signed-off-by: Eric Pickard <piceri@github.com>
1 parent 6e22407 commit 3ed17e1

2 files changed

Lines changed: 59 additions & 1 deletion

File tree

internal/controller/reporting.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ func (c *Controller) makeSyncRecords(ctx context.Context, syncClusterPods []any)
167167
continue
168168
}
169169

170-
if pod.Status.Phase != corev1.PodRunning || !workload.HasSupportedOwner(pod) {
170+
isRunningSupported := pod.Status.Phase == corev1.PodRunning && workload.HasSupportedOwner(pod)
171+
isTerminalJob := workload.IsTerminalPhase(pod) && workload.GetJobOwnerName(pod) != ""
172+
if !isRunningSupported && !isTerminalJob {
171173
continue
172174
}
173175

internal/controller/reporting_test.go

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,62 @@ func TestProcessSyncEvents_PostCluster500(t *testing.T) {
239239
assert.Equal(t, 1, poster.getPostClusterCalls())
240240
}
241241

242+
func TestMakeSyncRecords_TerminalJobPodIncluded(t *testing.T) {
243+
t.Parallel()
244+
digest := "sha256:terminal-job-digest"
245+
poster := &mockPoster{}
246+
ctrl := newTestController(poster)
247+
ctrl.workloadResolver = &mockResolver{name: "test-job"}
248+
249+
pod := makeTestPod("worker", "test-job-abc123", digest, "Job")
250+
pod.Status.Phase = corev1.PodSucceeded
251+
252+
records := ctrl.makeSyncRecords(context.Background(), []any{pod})
253+
assert.Len(t, records, 1, "terminal Job pod should be included in sync records")
254+
}
255+
256+
func TestMakeSyncRecords_FailedJobPodIncluded(t *testing.T) {
257+
t.Parallel()
258+
digest := "sha256:failed-job-digest"
259+
poster := &mockPoster{}
260+
ctrl := newTestController(poster)
261+
ctrl.workloadResolver = &mockResolver{name: "test-job"}
262+
263+
pod := makeTestPod("worker", "test-job-abc123", digest, "Job")
264+
pod.Status.Phase = corev1.PodFailed
265+
266+
records := ctrl.makeSyncRecords(context.Background(), []any{pod})
267+
assert.Len(t, records, 1, "failed Job pod should be included in sync records")
268+
}
269+
270+
func TestMakeSyncRecords_TerminalNonJobPodExcluded(t *testing.T) {
271+
t.Parallel()
272+
digest := "sha256:terminal-non-job-digest"
273+
poster := &mockPoster{}
274+
ctrl := newTestController(poster)
275+
ctrl.workloadResolver = &mockResolver{name: "test-deploy"}
276+
277+
pod := makeTestPod("app", "test-deploy-abc123", digest, "ReplicaSet")
278+
pod.Status.Phase = corev1.PodSucceeded
279+
280+
records := ctrl.makeSyncRecords(context.Background(), []any{pod})
281+
assert.Empty(t, records, "terminal non-Job pod should not be included in sync records")
282+
}
283+
284+
func TestMakeSyncRecords_PendingJobPodExcluded(t *testing.T) {
285+
t.Parallel()
286+
digest := "sha256:pending-job-digest"
287+
poster := &mockPoster{}
288+
ctrl := newTestController(poster)
289+
ctrl.workloadResolver = &mockResolver{name: "test-job"}
290+
291+
pod := makeTestPod("worker", "test-job-abc123", digest, "Job")
292+
pod.Status.Phase = corev1.PodPending
293+
294+
records := ctrl.makeSyncRecords(context.Background(), []any{pod})
295+
assert.Empty(t, records, "pending Job pod should not be included in sync records")
296+
}
297+
242298
func makeTestPod(containerName string, parentName string, digest string, parentKind string) *corev1.Pod {
243299
return &corev1.Pod{
244300
ObjectMeta: metav1.ObjectMeta{

0 commit comments

Comments
 (0)