diff --git a/pkg/cri/sbserver/podsandbox/controller.go b/pkg/cri/sbserver/podsandbox/controller.go index 0be73ffe5..68ac86029 100644 --- a/pkg/cri/sbserver/podsandbox/controller.go +++ b/pkg/cri/sbserver/podsandbox/controller.go @@ -43,10 +43,6 @@ import ( type CRIService interface { // TODO: we should implement Event backoff in Controller. BackOffEvent(id string, event interface{}) - - // TODO: refactor event generator for PLEG. - // GenerateAndSendContainerEvent is called by controller for sandbox container events. - GenerateAndSendContainerEvent(ctx context.Context, containerID string, sandboxID string, eventType runtime.ContainerEventType) } // ImageService specifies dependencies to CRI image service. diff --git a/pkg/cri/sbserver/podsandbox/sandbox_delete.go b/pkg/cri/sbserver/podsandbox/sandbox_delete.go index 678362053..4e388cd01 100644 --- a/pkg/cri/sbserver/podsandbox/sandbox_delete.go +++ b/pkg/cri/sbserver/podsandbox/sandbox_delete.go @@ -20,8 +20,6 @@ import ( "context" "fmt" - runtime "k8s.io/cri-api/pkg/apis/runtime/v1" - "github.com/containerd/containerd" "github.com/containerd/containerd/errdefs" "github.com/containerd/containerd/log" @@ -59,10 +57,5 @@ func (c *Controller) Shutdown(ctx context.Context, sandboxID string) error { } } - // Send CONTAINER_DELETED event with ContainerId equal to SandboxId. - c.cri.GenerateAndSendContainerEvent(ctx, sandboxID, sandboxID, runtime.ContainerEventType_CONTAINER_DELETED_EVENT) - - c.sandboxStore.Delete(sandboxID) - return nil } diff --git a/pkg/cri/sbserver/sandbox_remove.go b/pkg/cri/sbserver/sandbox_remove.go index 80b642151..41382ad0a 100644 --- a/pkg/cri/sbserver/sandbox_remove.go +++ b/pkg/cri/sbserver/sandbox_remove.go @@ -89,6 +89,9 @@ func (c *criService) RemovePodSandbox(ctx context.Context, r *runtime.RemovePodS return nil, fmt.Errorf("failed to delete sandbox %q: %w", id, err) } + // Send CONTAINER_DELETED event with ContainerId equal to SandboxId. + c.generateAndSendContainerEvent(ctx, id, id, runtime.ContainerEventType_CONTAINER_DELETED_EVENT) + err = c.nri.RemovePodSandbox(ctx, &sandbox) if err != nil { log.G(ctx).WithError(err).Errorf("NRI pod removal notification failed") diff --git a/pkg/cri/sbserver/service.go b/pkg/cri/sbserver/service.go index 09f7243dc..27bf6ac45 100644 --- a/pkg/cri/sbserver/service.go +++ b/pkg/cri/sbserver/service.go @@ -215,12 +215,6 @@ func (c *criService) BackOffEvent(id string, event interface{}) { c.eventMonitor.backOff.enBackOff(id, event) } -// GenerateAndSendContainerEvent is a temporary workaround to send PLEG events from podsandbopx/ controller -// TODO: refactor PLEG event generator so both podsandbox/ controller and CRI service can access it. -func (c *criService) GenerateAndSendContainerEvent(ctx context.Context, containerID string, sandboxID string, eventType runtime.ContainerEventType) { - c.generateAndSendContainerEvent(ctx, containerID, sandboxID, eventType) -} - // Register registers all required services onto a specific grpc server. // This is used by containerd cri plugin. func (c *criService) Register(s *grpc.Server) error {