Move image event publishing to metadata store
The metadata store is in the best place to handle events directly after the database has been updated. This prevents every user of the image store interface from having to know whether or not they are responsible for publishing events and avoid double events if the grpc local service is used. Signed-off-by: Derek McGowan <derek@mcg.dev>
This commit is contained in:
@@ -38,7 +38,6 @@ import (
|
||||
imagespec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
runtime "k8s.io/cri-api/pkg/apis/runtime/v1"
|
||||
|
||||
eventstypes "github.com/containerd/containerd/v2/api/events"
|
||||
containerd "github.com/containerd/containerd/v2/client"
|
||||
"github.com/containerd/containerd/v2/core/diff"
|
||||
containerdimages "github.com/containerd/containerd/v2/core/images"
|
||||
@@ -322,14 +321,6 @@ func (c *CRIImageService) createImageReference(ctx context.Context, name string,
|
||||
// TODO: Call CRIImageService directly
|
||||
oldImg, err := c.images.Create(ctx, img)
|
||||
if err == nil {
|
||||
if c.publisher != nil {
|
||||
if err := c.publisher.Publish(ctx, "/images/create", &eventstypes.ImageCreate{
|
||||
Name: img.Name,
|
||||
Labels: img.Labels,
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
} else if !errdefs.IsAlreadyExists(err) {
|
||||
return err
|
||||
@@ -338,16 +329,6 @@ func (c *CRIImageService) createImageReference(ctx context.Context, name string,
|
||||
return nil
|
||||
}
|
||||
_, err = c.images.Update(ctx, img, "target", "labels."+crilabels.ImageLabelKey)
|
||||
if err == nil && c.publisher != nil {
|
||||
if c.publisher != nil {
|
||||
if err := c.publisher.Publish(ctx, "/images/update", &eventstypes.ImageUpdate{
|
||||
Name: img.Name,
|
||||
Labels: img.Labels,
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
eventstypes "github.com/containerd/containerd/v2/api/events"
|
||||
"github.com/containerd/containerd/v2/core/images"
|
||||
"github.com/containerd/containerd/v2/pkg/tracing"
|
||||
"github.com/containerd/errdefs"
|
||||
@@ -63,14 +62,6 @@ func (c *GRPCCRIImageService) RemoveImage(ctx context.Context, r *runtime.Remove
|
||||
if err := c.imageStore.Update(ctx, ref); err != nil {
|
||||
return nil, fmt.Errorf("failed to update image reference %q for %q: %w", ref, image.ID, err)
|
||||
}
|
||||
|
||||
if c.publisher != nil {
|
||||
if err := c.publisher.Publish(ctx, "/images/delete", &eventstypes.ImageDelete{
|
||||
Name: ref,
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
return nil, fmt.Errorf("failed to delete image reference %q for %q: %w", ref, image.ID, err)
|
||||
|
||||
@@ -28,7 +28,6 @@ import (
|
||||
imagestore "github.com/containerd/containerd/v2/internal/cri/store/image"
|
||||
snapshotstore "github.com/containerd/containerd/v2/internal/cri/store/snapshot"
|
||||
"github.com/containerd/containerd/v2/internal/kmutex"
|
||||
"github.com/containerd/containerd/v2/pkg/events"
|
||||
"github.com/containerd/log"
|
||||
"github.com/containerd/platforms"
|
||||
docker "github.com/distribution/reference"
|
||||
@@ -54,8 +53,6 @@ type CRIImageService struct {
|
||||
// images is the lower level image store used for raw storage,
|
||||
// no event publishing should currently be assumed
|
||||
images images.Store
|
||||
// publisher is the events publisher
|
||||
publisher events.Publisher
|
||||
// client is a subset of the containerd client
|
||||
// and will be replaced by image store and transfer service
|
||||
client imageClient
|
||||
@@ -88,8 +85,6 @@ type CRIImageServiceOptions struct {
|
||||
|
||||
Snapshotters map[string]snapshots.Snapshotter
|
||||
|
||||
Publisher events.Publisher
|
||||
|
||||
Client imageClient
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user