Skip to content

Commit ab21d60

Browse files
committed
pkg/cri/server: add criService as argument when handle exit event
Signed-off-by: Wei Fu <[email protected]>
1 parent a229883 commit ab21d60

3 files changed

Lines changed: 14 additions & 14 deletions

File tree

pkg/cri/server/container_stop.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (c *criService) stopContainer(ctx context.Context, container containerstore
7777
}
7878
// Don't return for unknown state, some cleanup needs to be done.
7979
if state == runtime.ContainerState_CONTAINER_UNKNOWN {
80-
return cleanupUnknownContainer(ctx, id, container)
80+
return cleanupUnknownContainer(ctx, id, container, c)
8181
}
8282
return nil
8383
}
@@ -92,7 +92,7 @@ func (c *criService) stopContainer(ctx context.Context, container containerstore
9292
if !errdefs.IsNotFound(err) {
9393
return fmt.Errorf("failed to wait for task for %q: %w", id, err)
9494
}
95-
return cleanupUnknownContainer(ctx, id, container)
95+
return cleanupUnknownContainer(ctx, id, container, c)
9696
}
9797

9898
exitCtx, exitCancel := context.WithCancel(context.Background())
@@ -195,13 +195,13 @@ func (c *criService) waitContainerStop(ctx context.Context, container containers
195195
}
196196

197197
// cleanupUnknownContainer cleanup stopped container in unknown state.
198-
func cleanupUnknownContainer(ctx context.Context, id string, cntr containerstore.Container) error {
198+
func cleanupUnknownContainer(ctx context.Context, id string, cntr containerstore.Container, c *criService) error {
199199
// Reuse handleContainerExit to do the cleanup.
200200
return handleContainerExit(ctx, &eventtypes.TaskExit{
201201
ContainerID: id,
202202
ID: id,
203203
Pid: 0,
204204
ExitStatus: unknownExitCode,
205205
ExitedAt: time.Now(),
206-
}, cntr)
206+
}, cntr, c)
207207
}

pkg/cri/server/events.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func (em *eventMonitor) startSandboxExitMonitor(ctx context.Context, id string,
137137

138138
sb, err := em.c.sandboxStore.Get(e.ID)
139139
if err == nil {
140-
if err := handleSandboxExit(dctx, e, sb); err != nil {
140+
if err := handleSandboxExit(dctx, e, sb, em.c); err != nil {
141141
return err
142142
}
143143
return nil
@@ -188,7 +188,7 @@ func (em *eventMonitor) startContainerExitMonitor(ctx context.Context, id string
188188

189189
cntr, err := em.c.containerStore.Get(e.ID)
190190
if err == nil {
191-
if err := handleContainerExit(dctx, e, cntr); err != nil {
191+
if err := handleContainerExit(dctx, e, cntr, em.c); err != nil {
192192
return err
193193
}
194194
return nil
@@ -314,7 +314,7 @@ func (em *eventMonitor) handleEvent(any interface{}) error {
314314
// Use ID instead of ContainerID to rule out TaskExit event for exec.
315315
cntr, err := em.c.containerStore.Get(e.ID)
316316
if err == nil {
317-
if err := handleContainerExit(ctx, e, cntr); err != nil {
317+
if err := handleContainerExit(ctx, e, cntr, em.c); err != nil {
318318
return fmt.Errorf("failed to handle container TaskExit event: %w", err)
319319
}
320320
return nil
@@ -323,7 +323,7 @@ func (em *eventMonitor) handleEvent(any interface{}) error {
323323
}
324324
sb, err := em.c.sandboxStore.Get(e.ID)
325325
if err == nil {
326-
if err := handleSandboxExit(ctx, e, sb); err != nil {
326+
if err := handleSandboxExit(ctx, e, sb, em.c); err != nil {
327327
return fmt.Errorf("failed to handle sandbox TaskExit event: %w", err)
328328
}
329329
return nil
@@ -363,7 +363,7 @@ func (em *eventMonitor) handleEvent(any interface{}) error {
363363
}
364364

365365
// handleContainerExit handles TaskExit event for container.
366-
func handleContainerExit(ctx context.Context, e *eventtypes.TaskExit, cntr containerstore.Container) error {
366+
func handleContainerExit(ctx context.Context, e *eventtypes.TaskExit, cntr containerstore.Container, c *criService) error {
367367
// Attach container IO so that `Delete` could cleanup the stream properly.
368368
task, err := cntr.Container.Task(ctx,
369369
func(*containerdio.FIFOSet) (containerdio.IO, error) {
@@ -461,7 +461,7 @@ func handleContainerExit(ctx context.Context, e *eventtypes.TaskExit, cntr conta
461461
}
462462

463463
// handleSandboxExit handles TaskExit event for sandbox.
464-
func handleSandboxExit(ctx context.Context, e *eventtypes.TaskExit, sb sandboxstore.Sandbox) error {
464+
func handleSandboxExit(ctx context.Context, e *eventtypes.TaskExit, sb sandboxstore.Sandbox, c *criService) error {
465465
// No stream attached to sandbox container.
466466
task, err := sb.Container.Task(ctx, nil)
467467
if err != nil {

pkg/cri/server/sandbox_stop.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func (c *criService) stopSandboxContainer(ctx context.Context, sandbox sandboxst
119119
}
120120
// Don't return for unknown state, some cleanup needs to be done.
121121
if state == sandboxstore.StateUnknown {
122-
return cleanupUnknownSandbox(ctx, id, sandbox)
122+
return cleanupUnknownSandbox(ctx, id, sandbox, c)
123123
}
124124
return nil
125125
}
@@ -135,7 +135,7 @@ func (c *criService) stopSandboxContainer(ctx context.Context, sandbox sandboxst
135135
if !errdefs.IsNotFound(err) {
136136
return fmt.Errorf("failed to wait for task: %w", err)
137137
}
138-
return cleanupUnknownSandbox(ctx, id, sandbox)
138+
return cleanupUnknownSandbox(ctx, id, sandbox, c)
139139
}
140140

141141
exitCtx, exitCancel := context.WithCancel(context.Background())
@@ -197,13 +197,13 @@ func (c *criService) teardownPodNetwork(ctx context.Context, sandbox sandboxstor
197197
}
198198

199199
// cleanupUnknownSandbox cleanup stopped sandbox in unknown state.
200-
func cleanupUnknownSandbox(ctx context.Context, id string, sandbox sandboxstore.Sandbox) error {
200+
func cleanupUnknownSandbox(ctx context.Context, id string, sandbox sandboxstore.Sandbox, c *criService) error {
201201
// Reuse handleSandboxExit to do the cleanup.
202202
return handleSandboxExit(ctx, &eventtypes.TaskExit{
203203
ContainerID: id,
204204
ID: id,
205205
Pid: 0,
206206
ExitStatus: unknownExitCode,
207207
ExitedAt: time.Now(),
208-
}, sandbox)
208+
}, sandbox, c)
209209
}

0 commit comments

Comments
 (0)