properly implement pull-error event status

Commit 03f6589f3 added basic support for pull-error event from libimage
but it contains several problems:
1. storing the error as error type prevents it from being unmarshalled,
   thus change it to a string
2. the error was never propagated from the libimage event to the podman
   event struct
3. the error message was not wired into the cli and API

This commit fixes these problems.

Fixes #21458

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
Paul Holzinger
2024-03-04 18:36:07 +01:00
parent 3e1d2ab874
commit 9ee96a9569
10 changed files with 57 additions and 24 deletions

View File

@ -42,7 +42,7 @@ type Event struct {
// Health status of the current container
HealthStatus string `json:"health_status,omitempty"`
// Error code for certain events involving errors.
Error error `json:"error,omitempty"`
Error string `json:"error,omitempty"`
Details
}

View File

@ -90,6 +90,9 @@ func (e *Event) ToHumanReadable(truncate bool) string {
humanFormat = fmt.Sprintf("%s %s %s %s (container=%s, name=%s)", e.Time, e.Type, e.Status, id, id, e.Network)
case Image:
humanFormat = fmt.Sprintf("%s %s %s %s %s", e.Time, e.Type, e.Status, id, e.Name)
if e.Error != "" {
humanFormat += " " + e.Error
}
case System:
if e.Name != "" {
humanFormat = fmt.Sprintf("%s %s %s %s", e.Time, e.Type, e.Status, e.Name)

View File

@ -43,8 +43,8 @@ func (e EventJournalD) Write(ee Event) error {
case Image:
m["PODMAN_NAME"] = ee.Name
m["PODMAN_ID"] = ee.ID
if ee.Error != nil {
m["ERROR"] = ee.Error.Error()
if ee.Error != "" {
m["ERROR"] = ee.Error
}
case Container, Pod:
m["PODMAN_IMAGE"] = ee.Image
@ -231,8 +231,8 @@ func newEventFromJournalEntry(entry *sdjournal.JournalEntry) (*Event, error) {
newEvent.Network = entry.Fields["PODMAN_NETWORK_NAME"]
case Image:
newEvent.ID = entry.Fields["PODMAN_ID"]
if _, ok := entry.Fields["ERROR"]; ok {
newEvent.Error = errors.New(entry.Fields["ERROR"])
if val, ok := entry.Fields["ERROR"]; ok {
newEvent.Error = val
}
}
return &newEvent, nil