@@ -142,19 +142,27 @@ func handleUpdate(obj interface{}, newObj interface{}) {
142
142
buf := new (strings.Builder )
143
143
buf .WriteString ("\n " )
144
144
145
- buf .WriteString ("*Failed Pods*\n \n " )
146
-
147
145
for _ , pod := range pods {
146
+ // Ignore non-failed pods
148
147
if pod .Status .Phase != corev1 .PodFailed {
149
148
continue
150
149
}
150
+
151
151
logs , _ := getPodLogs (pod )
152
152
fmt .Fprintf (buf , "Pod `%s`\n ```\n %s\n ```\n \n " , pod .Name , logs )
153
153
154
+ // Log all terminated containers
155
+ for _ , cstate := range pod .Status .ContainerStatuses {
156
+ containerId := cstate .Name
157
+ exitCode := cstate .State .Terminated .ExitCode
158
+ reason := cstate .State .Terminated .Reason
159
+ time := cstate .State .Terminated .FinishedAt
160
+ fmt .Fprintf (buf , "Container `%s` exited at %s with code `%d` (reason `%s`)\n " , containerId , time , exitCode , reason )
161
+ }
154
162
}
155
163
body = buf .String ()
156
164
} else {
157
- subject = "Job completed "
165
+ subject = "Job failed "
158
166
body = formatJob (job , false )
159
167
}
160
168
@@ -202,7 +210,7 @@ func getPodLogs(pod corev1.Pod) (string, error) {
202
210
if err != nil {
203
211
return "" , nil
204
212
}
205
- return buf .String (), nil
213
+ return strings . TrimSpace ( buf .String () ), nil
206
214
}
207
215
208
216
func collectJobOutputs (job * batchv1.Job ) (map [string ]string , error ) {
0 commit comments