mirror of
https://github.com/containers/podman.git
synced 2025-09-25 15:55:32 +08:00
add libimage events
libimage now supports events which `libpod.Runtime` now uses for image events. Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
This commit is contained in:
2
go.mod
2
go.mod
@ -12,7 +12,7 @@ require (
|
||||
github.com/containernetworking/cni v0.8.1
|
||||
github.com/containernetworking/plugins v0.9.1
|
||||
github.com/containers/buildah v1.20.2-0.20210519094241-c3a3fe847ee1
|
||||
github.com/containers/common v0.38.4-0.20210519112800-40a1e9ee42fb
|
||||
github.com/containers/common v0.38.4
|
||||
github.com/containers/conmon v2.0.20+incompatible
|
||||
github.com/containers/image/v5 v5.12.0
|
||||
github.com/containers/ocicrypt v1.1.1
|
||||
|
4
go.sum
4
go.sum
@ -218,8 +218,8 @@ github.com/containernetworking/plugins v0.9.1/go.mod h1:xP/idU2ldlzN6m4p5LmGiwRD
|
||||
github.com/containers/buildah v1.20.2-0.20210519094241-c3a3fe847ee1 h1:XrHrbHwkTMmZCNhRglW4H3k8ApOWyupsSp5snJmsb24=
|
||||
github.com/containers/buildah v1.20.2-0.20210519094241-c3a3fe847ee1/go.mod h1:7qXQ9hVQxgkE3XCoCjtzrV0VKh5GzgugkQDfvFxcVus=
|
||||
github.com/containers/common v0.38.3/go.mod h1:egfpX/Y3+19Dz4Wa1eRZDdgzoEOeneieF9CQppKzLBg=
|
||||
github.com/containers/common v0.38.4-0.20210519112800-40a1e9ee42fb h1:KEwgtZFf3o/Dk8oLkYrh+CrKENV2fRbZHfcJwgpA9i4=
|
||||
github.com/containers/common v0.38.4-0.20210519112800-40a1e9ee42fb/go.mod h1:egfpX/Y3+19Dz4Wa1eRZDdgzoEOeneieF9CQppKzLBg=
|
||||
github.com/containers/common v0.38.4 h1:WYv4R6Sw1qiOPZtBNbKglrmisXdPcq3fZ3bGy4prrjo=
|
||||
github.com/containers/common v0.38.4/go.mod h1:egfpX/Y3+19Dz4Wa1eRZDdgzoEOeneieF9CQppKzLBg=
|
||||
github.com/containers/conmon v2.0.20+incompatible h1:YbCVSFSCqFjjVwHTPINGdMX1F6JXHGTUje2ZYobNrkg=
|
||||
github.com/containers/conmon v2.0.20+incompatible/go.mod h1:hgwZ2mtuDrppv78a/cOBNiCm6O0UMWGx1mu7P00nu5I=
|
||||
github.com/containers/image/v5 v5.12.0 h1:1hNS2QkzFQ4lH3GYQLyAXB0acRMhS1Ubm6oV++8vw4w=
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
"strings"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/containers/common/libimage"
|
||||
"github.com/containers/common/pkg/config"
|
||||
@ -68,17 +69,18 @@ type Runtime struct {
|
||||
storageConfig storage.StoreOptions
|
||||
storageSet storageSet
|
||||
|
||||
state State
|
||||
store storage.Store
|
||||
storageService *storageService
|
||||
imageContext *types.SystemContext
|
||||
defaultOCIRuntime OCIRuntime
|
||||
ociRuntimes map[string]OCIRuntime
|
||||
runtimeFlags []string
|
||||
netPlugin ocicni.CNIPlugin
|
||||
conmonPath string
|
||||
libimageRuntime *libimage.Runtime
|
||||
lockManager lock.Manager
|
||||
state State
|
||||
store storage.Store
|
||||
storageService *storageService
|
||||
imageContext *types.SystemContext
|
||||
defaultOCIRuntime OCIRuntime
|
||||
ociRuntimes map[string]OCIRuntime
|
||||
runtimeFlags []string
|
||||
netPlugin ocicni.CNIPlugin
|
||||
conmonPath string
|
||||
libimageRuntime *libimage.Runtime
|
||||
libimageEventsShutdown chan bool
|
||||
lockManager lock.Manager
|
||||
|
||||
// doRenumber indicates that the runtime should perform a lock renumber
|
||||
// during initialization.
|
||||
@ -215,6 +217,8 @@ func newRuntimeFromConfig(ctx context.Context, conf *config.Config, options ...R
|
||||
return nil, err
|
||||
}
|
||||
|
||||
runtime.libimageEventsShutdown = make(chan bool)
|
||||
|
||||
return runtime, nil
|
||||
}
|
||||
|
||||
@ -680,6 +684,62 @@ func (r *Runtime) GetConfig() (*config.Config, error) {
|
||||
return config, nil
|
||||
}
|
||||
|
||||
// libimageEventsMap translates a libimage event type to a libpod event status.
|
||||
var libimageEventsMap = map[libimage.EventType]events.Status{
|
||||
libimage.EventTypeImagePull: events.Pull,
|
||||
libimage.EventTypeImagePush: events.Push,
|
||||
libimage.EventTypeImageRemove: events.Remove,
|
||||
libimage.EventTypeImageLoad: events.LoadFromArchive,
|
||||
libimage.EventTypeImageSave: events.Save,
|
||||
libimage.EventTypeImageTag: events.Tag,
|
||||
libimage.EventTypeImageUntag: events.Untag,
|
||||
libimage.EventTypeImageMount: events.Mount,
|
||||
libimage.EventTypeImageUnmount: events.Unmount,
|
||||
}
|
||||
|
||||
// libimageEvents spawns a goroutine in the background which is listenting for
|
||||
// events on the libimage.Runtime. The gourtine will be cleaned up implicitly
|
||||
// when the main() exists.
|
||||
func (r *Runtime) libimageEvents() {
|
||||
toLibpodEventStatus := func(e *libimage.Event) events.Status {
|
||||
status, found := libimageEventsMap[e.Type]
|
||||
if !found {
|
||||
return "Unknown"
|
||||
}
|
||||
return status
|
||||
}
|
||||
|
||||
go func() {
|
||||
eventChannel := r.libimageRuntime.EventChannel()
|
||||
|
||||
for {
|
||||
// Make sure to read and write all events before
|
||||
// checking if we're about to shutdown.
|
||||
for len(eventChannel) > 0 {
|
||||
libimageEvent := <-eventChannel
|
||||
e := events.Event{
|
||||
ID: libimageEvent.ID,
|
||||
Name: libimageEvent.Name,
|
||||
Status: toLibpodEventStatus(libimageEvent),
|
||||
Time: libimageEvent.Time,
|
||||
Type: events.Image,
|
||||
}
|
||||
if err := r.eventer.Write(e); err != nil {
|
||||
logrus.Errorf("unable to write image event: %q", err)
|
||||
}
|
||||
}
|
||||
|
||||
select {
|
||||
case <-r.libimageEventsShutdown:
|
||||
return
|
||||
|
||||
default:
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
// DeferredShutdown shuts down the runtime without exposing any
|
||||
// errors. This is only meant to be used when the runtime is being
|
||||
// shutdown within a defer statement; else use Shutdown
|
||||
@ -719,7 +779,11 @@ func (r *Runtime) Shutdown(force bool) error {
|
||||
// If no store was requested, it can be nil and there is no need to
|
||||
// attempt to shut it down
|
||||
if r.store != nil {
|
||||
if _, err := r.store.Shutdown(force); err != nil {
|
||||
// Wait for the events to be written.
|
||||
r.libimageEventsShutdown <- true
|
||||
|
||||
// Note that the libimage runtime shuts down the store.
|
||||
if err := r.libimageRuntime.Shutdown(force); err != nil {
|
||||
lastError = errors.Wrapf(err, "error shutting down container storage")
|
||||
}
|
||||
}
|
||||
@ -845,6 +909,8 @@ func (r *Runtime) configureStore() error {
|
||||
return err
|
||||
}
|
||||
r.libimageRuntime = libimageRuntime
|
||||
// Run the libimage events routine.
|
||||
r.libimageEvents()
|
||||
|
||||
return nil
|
||||
}
|
||||
|
@ -25,3 +25,39 @@ load helpers
|
||||
run_podman events --filter type=container --filter container=$cname --filter event=start --stream=false
|
||||
is "$output" "$expect" "filtering just by label"
|
||||
}
|
||||
|
||||
@test "image events" {
|
||||
skip_if_remote "FIXME: remove events on podman-remote seem to be broken"
|
||||
pushedDir=$PODMAN_TMPDIR/dir
|
||||
mkdir -p $pushedDir
|
||||
|
||||
tarball=$PODMAN_TMPDIR/ball.tar
|
||||
|
||||
run_podman image inspect --format "{{.ID}}" $IMAGE
|
||||
imageID="$output"
|
||||
|
||||
t0=$(date --iso-8601=seconds)
|
||||
tag=registry.com/$(random_string 10 | tr A-Z a-z)
|
||||
|
||||
# Force using the file backend since the journal backend is eating events
|
||||
# (see containers/podman/pull/10219#issuecomment-842325032).
|
||||
run_podman --events-backend=file push $IMAGE dir:$pushedDir
|
||||
run_podman --events-backend=file save $IMAGE -o $tarball
|
||||
run_podman --events-backend=file load -i $tarball
|
||||
run_podman --events-backend=file pull docker-archive:$tarball
|
||||
run_podman --events-backend=file tag $IMAGE $tag
|
||||
run_podman --events-backend=file untag $IMAGE $tag
|
||||
run_podman --events-backend=file tag $IMAGE $tag
|
||||
run_podman --events-backend=file rmi $tag
|
||||
|
||||
run_podman --events-backend=file events --stream=false --filter type=image --since $t0
|
||||
is "$output" ".*image push $imageID dir:$pushedDir
|
||||
.*image save $imageID $tarball
|
||||
.*image loadfromarchive *$tarball
|
||||
.*image pull *docker-archive:$tarball
|
||||
.*image tag $imageID $tag
|
||||
.*image untag $imageID $tag:latest
|
||||
.*image tag $imageID $tag
|
||||
.*image remove $imageID $tag.*" \
|
||||
"podman events"
|
||||
}
|
||||
|
2
vendor/github.com/containers/common/version/version.go
generated
vendored
2
vendor/github.com/containers/common/version/version.go
generated
vendored
@ -1,4 +1,4 @@
|
||||
package version
|
||||
|
||||
// Version is the version of the build.
|
||||
const Version = "0.38.4-dev"
|
||||
const Version = "0.38.4"
|
||||
|
2
vendor/modules.txt
vendored
2
vendor/modules.txt
vendored
@ -91,7 +91,7 @@ github.com/containers/buildah/pkg/overlay
|
||||
github.com/containers/buildah/pkg/parse
|
||||
github.com/containers/buildah/pkg/rusage
|
||||
github.com/containers/buildah/util
|
||||
# github.com/containers/common v0.38.4-0.20210519112800-40a1e9ee42fb
|
||||
# github.com/containers/common v0.38.4
|
||||
github.com/containers/common/libimage
|
||||
github.com/containers/common/libimage/manifests
|
||||
github.com/containers/common/pkg/apparmor
|
||||
|
Reference in New Issue
Block a user