@@ -142,19 +142,36 @@ 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
- for _ , pod := range pods {
145
+ for idx , pod := range pods {
146
+ // Ignore non-failed pods
148
147
if pod .Status .Phase != corev1 .PodFailed {
149
148
continue
150
149
}
150
+ if idx > 0 {
151
+ fmt .Fprintln (buf , strings .Repeat ("-" , 80 ))
152
+ }
153
+
151
154
logs , _ := getPodLogs (pod )
152
- fmt .Fprintf (buf , "Pod `%s`\n ```\n %s\n ```\n \n " , pod .Name , logs )
155
+ fmt .Fprintf (buf , "*Pod `%s`*\n \n Logs:\n \n ```\n %s\n ```\n \n " , pod .Name , logs )
156
+
157
+ // Log all terminated containers
158
+ fmt .Fprint (buf , "Failed containers:\n \n " )
159
+ for _ , cstate := range pod .Status .ContainerStatuses {
160
+ reason := cstate .State .Terminated .Reason
161
+ if reason != "Error" {
162
+ continue
163
+ }
153
164
165
+ containerId := cstate .Name
166
+ exitCode := cstate .State .Terminated .ExitCode
167
+ time := cstate .State .Terminated .FinishedAt
168
+
169
+ fmt .Fprintf (buf , "· `%s`, exited <!date^%d^{date_short_pretty} {time_secs}|at %s>, exit code %d\n \n " , containerId , time .Unix (), time , exitCode )
170
+ }
154
171
}
155
172
body = buf .String ()
156
173
} else {
157
- subject = "Job completed "
174
+ subject = "Job failed "
158
175
body = formatJob (job , false )
159
176
}
160
177
@@ -202,7 +219,7 @@ func getPodLogs(pod corev1.Pod) (string, error) {
202
219
if err != nil {
203
220
return "" , nil
204
221
}
205
- return buf .String (), nil
222
+ return strings . TrimSpace ( buf .String () ), nil
206
223
}
207
224
208
225
func collectJobOutputs (job * batchv1.Job ) (map [string ]string , error ) {
0 commit comments