Skip to content

feat: add exit code in container deletion events#3779

Merged
dims merged 1 commit intogoogle:masterfrom
sambhav-jain-16:3722
Dec 11, 2025
Merged

feat: add exit code in container deletion events#3779
dims merged 1 commit intogoogle:masterfrom
sambhav-jain-16:3722

Conversation

@sambhav-jain-16
Copy link
Contributor

What

Container deletion events now include the container's exit code in the event data.
Fixes: #3722

Why

Users need to understand why containers terminated (success vs error vs signal). Exit codes provide critical debugging information for container lifecycle management and monitoring.

How

  • Added GetExitCode() method to ContainerHandler interface
  • Added ContainerDeletionEventData struct with ExitCode field to event system
  • Modified destroyContainer() to retrieve exit code before calling Stop()
  • Implemented for docker, containerd, and podman (uses runtime inspect APIs)
  • CRI-O and Raw handlers return errors (not supported by those runtimes)
  • Exit code defaults to -1 if unavailable (container still running, retrieval fails, etc.)

Testing

  • Unit tests for docker, containerd, and manager
  • Integration test validates end-to-end flow

API Example

  {
    "event_type": "containerDeletion",
    "container_name": "/docker/abc123",
    "event_data": {
      "container_deletion": {
        "exit_code": 1
      }
    }
  }

@dims
Copy link
Collaborator

dims commented Dec 11, 2025

@sambhav-jain-16 which container engines did you fully test this on? (containerd only?)

@sambhav-jain-16
Copy link
Contributor Author

sambhav-jain-16 commented Dec 11, 2025

@dims
This is tested on docker and containerd engines and is running already for some time in our setup.

(Not exactly the same code, but we are consuming the current deletion events and then hitting the same docker/containerd APIs to get the exit code)

@dims dims added this pull request to the merge queue Dec 11, 2025
Merged via the queue into google:master with commit e83bda0 Dec 11, 2025
10 of 13 checks passed
@sambhav-jain-16 sambhav-jain-16 deleted the 3722 branch December 11, 2025 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add ContainerExitCode to info.EventData in case of container deletion events

2 participants