domain: move Event to types sub-package

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
Giuseppe Scrivano
2024-01-25 12:05:40 +01:00
parent 01b2243e73
commit 48a99c6514
3 changed files with 23 additions and 14 deletions
pkg
bindings/system
domain/entities

@ -12,13 +12,14 @@ import (
"github.com/containers/podman/v4/libpod/define" "github.com/containers/podman/v4/libpod/define"
"github.com/containers/podman/v4/pkg/bindings" "github.com/containers/podman/v4/pkg/bindings"
"github.com/containers/podman/v4/pkg/domain/entities" "github.com/containers/podman/v4/pkg/domain/entities"
"github.com/containers/podman/v4/pkg/domain/entities/types"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
) )
// Events allows you to monitor libdpod related events like container creation and // Events allows you to monitor libdpod related events like container creation and
// removal. The events are then passed to the eventChan provided. The optional cancelChan // removal. The events are then passed to the eventChan provided. The optional cancelChan
// can be used to cancel the read of events and close down the HTTP connection. // can be used to cancel the read of events and close down the HTTP connection.
func Events(ctx context.Context, eventChan chan entities.Event, cancelChan chan bool, options *EventsOptions) error { func Events(ctx context.Context, eventChan chan types.Event, cancelChan chan bool, options *EventsOptions) error {
conn, err := bindings.GetClient(ctx) conn, err := bindings.GetClient(ctx)
if err != nil { if err != nil {
return err return err
@ -44,7 +45,7 @@ func Events(ctx context.Context, eventChan chan entities.Event, cancelChan chan
dec := json.NewDecoder(response.Body) dec := json.NewDecoder(response.Body)
for err = (error)(nil); err == nil; { for err = (error)(nil); err == nil; {
var e = entities.Event{} var e = types.Event{}
err = dec.Decode(&e) err = dec.Decode(&e)
if err == nil { if err == nil {
eventChan <- e eventChan <- e

@ -5,17 +5,11 @@ import (
"time" "time"
libpodEvents "github.com/containers/podman/v4/libpod/events" libpodEvents "github.com/containers/podman/v4/libpod/events"
types "github.com/containers/podman/v4/pkg/domain/entities/types"
dockerEvents "github.com/docker/docker/api/types/events" dockerEvents "github.com/docker/docker/api/types/events"
) )
// Event combines various event-related data such as time, event type, status type Event = types.Event
// and more.
type Event struct {
// TODO: it would be nice to have full control over the types at some
// point and fork such Docker types.
dockerEvents.Message
HealthStatus string `json:",omitempty"`
}
// ConvertToLibpodEvent converts an entities event to a libpod one. // ConvertToLibpodEvent converts an entities event to a libpod one.
func ConvertToLibpodEvent(e Event) *libpodEvents.Event { func ConvertToLibpodEvent(e Event) *libpodEvents.Event {
@ -59,7 +53,7 @@ func ConvertToLibpodEvent(e Event) *libpodEvents.Event {
} }
// ConvertToEntitiesEvent converts a libpod event to an entities one. // ConvertToEntitiesEvent converts a libpod event to an entities one.
func ConvertToEntitiesEvent(e libpodEvents.Event) *Event { func ConvertToEntitiesEvent(e libpodEvents.Event) *types.Event {
attributes := e.Details.Attributes attributes := e.Details.Attributes
if attributes == nil { if attributes == nil {
attributes = make(map[string]string) attributes = make(map[string]string)
@ -85,8 +79,8 @@ func ConvertToEntitiesEvent(e libpodEvents.Event) *Event {
Time: e.Time.Unix(), Time: e.Time.Unix(),
TimeNano: e.Time.UnixNano(), TimeNano: e.Time.UnixNano(),
} }
return &Event{ return &types.Event{
message, Message: message,
e.HealthStatus, HealthStatus: e.HealthStatus,
} }
} }

@ -0,0 +1,14 @@
package types
import (
dockerEvents "github.com/docker/docker/api/types/events"
)
// Event combines various event-related data such as time, event type, status
// and more.
type Event struct {
// TODO: it would be nice to have full control over the types at some
// point and fork such Docker types.
dockerEvents.Message
HealthStatus string `json:",omitempty"`
}