Skip to content

Commit

Permalink
Emit exit codes of console containers when terminating
Browse files Browse the repository at this point in the history
As part of the ConsoleTerminatedEvent messages to Pub/Sub the workloads
controller will also emit the exit codes of console containers when terminating.
  • Loading branch information
EsmeAR committed Jun 20, 2022
1 parent c6396c4 commit af1873b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
15 changes: 9 additions & 6 deletions apis/workloads/v1alpha1/lifecycle_recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,19 @@ func (l *lifecycleEventRecorderImpl) ConsoleAttach(ctx context.Context, csl *Con

func (l *lifecycleEventRecorderImpl) ConsoleTerminate(ctx context.Context, csl *Console, timedOut bool, pod *corev1.Pod) error {
containerStatuses := make(map[string]string)
exitCodes := make(map[string]int32)
if pod != nil {
appendStatusMessages(containerStatuses, pod.Status.InitContainerStatuses)
appendStatusMessages(containerStatuses, pod.Status.ContainerStatuses)
appendStatusMessages(containerStatuses, pod.Status.EphemeralContainerStatuses)
appendStatusMessages(containerStatuses, exitCodes, pod.Status.InitContainerStatuses)
appendStatusMessages(containerStatuses, exitCodes, pod.Status.ContainerStatuses)
appendStatusMessages(containerStatuses, exitCodes, pod.Status.EphemeralContainerStatuses)
}

event := &events.ConsoleTerminatedEvent{
CommonEvent: l.makeConsoleCommonEvent(events.EventTerminated, csl),
Spec: events.ConsoleTerminatedSpec{
TimedOut: timedOut,
ContainerStatuses: containerStatuses,
ExitCodes: exitCodes,
},
}

Expand All @@ -222,7 +224,7 @@ func (l *lifecycleEventRecorderImpl) ConsoleTerminate(ctx context.Context, csl *
return nil
}

func appendStatusMessages(result map[string]string, containerStatuses []corev1.ContainerStatus) {
func appendStatusMessages(containerStatusResult map[string]string, exitCodeResult map[string]int32, containerStatuses []corev1.ContainerStatus) {
if containerStatuses == nil {
return
}
Expand All @@ -241,7 +243,8 @@ func appendStatusMessages(result map[string]string, containerStatuses []corev1.C
if s.Message != "" {
message.WriteString(fmt.Sprintf(". Message: %s", s.Message))
}
result[containerStatus.Name] = message.String()
containerStatusResult[containerStatus.Name] = message.String()
exitCodeResult[containerStatus.Name] = s.ExitCode
} else if containerStatus.State.Waiting != nil {
s := containerStatus.State.Waiting
var message strings.Builder
Expand All @@ -252,7 +255,7 @@ func appendStatusMessages(result map[string]string, containerStatuses []corev1.C
if s.Message != "" {
message.WriteString(fmt.Sprintf(" Message: %s", s.Message))
}
result[containerStatus.Name] = message.String()
containerStatusResult[containerStatus.Name] = message.String()
}
}
}
1 change: 1 addition & 0 deletions pkg/workloads/console/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ type ConsoleAttachEvent struct {
type ConsoleTerminatedSpec struct {
TimedOut bool `json:"timed_out"`
ContainerStatuses map[string]string `json:"container_statuses"`
ExitCodes map[string]int32 `json:"exit_codes"`
}

type ConsoleTerminatedEvent struct {
Expand Down

0 comments on commit af1873b

Please sign in to comment.