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

View File

@ -12,13 +12,14 @@ import (
"github.com/containers/podman/v4/libpod/define"
"github.com/containers/podman/v4/pkg/bindings"
"github.com/containers/podman/v4/pkg/domain/entities"
"github.com/containers/podman/v4/pkg/domain/entities/types"
"github.com/sirupsen/logrus"
)
// 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
// 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)
if err != nil {
return err
@ -44,7 +45,7 @@ func Events(ctx context.Context, eventChan chan entities.Event, cancelChan chan
dec := json.NewDecoder(response.Body)
for err = (error)(nil); err == nil; {
var e = entities.Event{}
var e = types.Event{}
err = dec.Decode(&e)
if err == nil {
eventChan <- e

View File

@ -5,17 +5,11 @@ import (
"time"
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"
)
// 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"`
}
type Event = types.Event
// ConvertToLibpodEvent converts an entities event to a libpod one.
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.
func ConvertToEntitiesEvent(e libpodEvents.Event) *Event {
func ConvertToEntitiesEvent(e libpodEvents.Event) *types.Event {
attributes := e.Details.Attributes
if attributes == nil {
attributes = make(map[string]string)
@ -85,8 +79,8 @@ func ConvertToEntitiesEvent(e libpodEvents.Event) *Event {
Time: e.Time.Unix(),
TimeNano: e.Time.UnixNano(),
}
return &Event{
message,
e.HealthStatus,
return &types.Event{
Message: message,
HealthStatus: e.HealthStatus,
}
}

View File

@ -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"`
}