cri,nri: block NRI plugin sync. during event processing.
Block the synchronization of registering NRI plugins during CRI events to avoid the plugin ending up in an inconsistent starting state after initial sync (missing pods, containers or missed events for some pods or containers). Signed-off-by: Krisztian Litkey <krisztian.litkey@intel.com>
This commit is contained in:
@@ -313,6 +313,8 @@ func (c *criService) CreateContainer(ctx context.Context, r *runtime.CreateConta
|
||||
}
|
||||
}()
|
||||
|
||||
defer c.nri.BlockPluginSync().Unblock()
|
||||
|
||||
var cntr containerd.Container
|
||||
if cntr, err = c.client.NewContainer(ctx, id, opts...); err != nil {
|
||||
return nil, fmt.Errorf("failed to create containerd container: %w", err)
|
||||
|
||||
@@ -44,6 +44,9 @@ func (c *criService) RemoveContainer(ctx context.Context, r *runtime.RemoveConta
|
||||
log.G(ctx).Tracef("RemoveContainer called for container %q that does not exist", ctrID)
|
||||
return &runtime.RemoveContainerResponse{}, nil
|
||||
}
|
||||
|
||||
defer c.nri.BlockPluginSync().Unblock()
|
||||
|
||||
id := container.ID
|
||||
span.SetAttributes(tracing.Attribute("container.id", id))
|
||||
i, err := container.Container.Info(ctx)
|
||||
|
||||
@@ -156,6 +156,8 @@ func (c *criService) StartContainer(ctx context.Context, r *runtime.StartContain
|
||||
return nil, fmt.Errorf("failed to wait for containerd task: %w", err)
|
||||
}
|
||||
|
||||
defer c.nri.BlockPluginSync().Unblock()
|
||||
|
||||
defer func() {
|
||||
if retErr != nil {
|
||||
deferCtx, deferCancel := ctrdutil.DeferContext()
|
||||
|
||||
@@ -51,6 +51,9 @@ func (c *criService) StopContainer(ctx context.Context, r *runtime.StopContainer
|
||||
// https://github.com/kubernetes/cri-api/blob/c20fa40/pkg/apis/runtime/v1/api.proto#L67-L68
|
||||
return &runtime.StopContainerResponse{}, nil
|
||||
}
|
||||
|
||||
defer c.nri.BlockPluginSync().Unblock()
|
||||
|
||||
span.SetAttributes(tracing.Attribute("container.id", container.ID))
|
||||
if err := c.stopContainer(ctx, container, time.Duration(r.GetTimeout())*time.Second); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -47,6 +47,8 @@ func (c *criService) UpdateContainerResources(ctx context.Context, r *runtime.Up
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer c.nri.BlockPluginSync().Unblock()
|
||||
|
||||
resources := r.GetLinux()
|
||||
updated, err := c.nri.UpdateContainerResources(ctx, &sandbox, &container, resources)
|
||||
if err != nil {
|
||||
|
||||
@@ -44,6 +44,9 @@ func (c *criService) RemovePodSandbox(ctx context.Context, r *runtime.RemovePodS
|
||||
r.GetPodSandboxId())
|
||||
return &runtime.RemovePodSandboxResponse{}, nil
|
||||
}
|
||||
|
||||
defer c.nri.BlockPluginSync().Unblock()
|
||||
|
||||
// Use the full sandbox id.
|
||||
id := sandbox.ID
|
||||
span.SetAttributes(tracing.Attribute("sandbox.id", id))
|
||||
|
||||
@@ -300,6 +300,8 @@ func (c *criService) RunPodSandbox(ctx context.Context, r *runtime.RunPodSandbox
|
||||
|
||||
sandbox.ProcessLabel = labels["selinux_label"]
|
||||
|
||||
defer c.nri.BlockPluginSync().Unblock()
|
||||
|
||||
err = c.nri.RunPodSandbox(ctx, &sandbox)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("NRI RunPodSandbox failed: %w", err)
|
||||
|
||||
@@ -46,6 +46,9 @@ func (c *criService) StopPodSandbox(ctx context.Context, r *runtime.StopPodSandb
|
||||
// https://github.com/kubernetes/cri-api/blob/c20fa40/pkg/apis/runtime/v1/api.proto#L45-L46
|
||||
return &runtime.StopPodSandboxResponse{}, nil
|
||||
}
|
||||
|
||||
defer c.nri.BlockPluginSync().Unblock()
|
||||
|
||||
span.SetAttributes(tracing.Attribute("sandbox.id", sandbox.ID))
|
||||
if err := c.stopPodSandbox(ctx, sandbox); err != nil {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user