Skip to content

Commit 5531309

Browse files
authored
Merge pull request #11971 from k8s-infra-cherrypick-robot/cherry-pick-11916-to-release/2.1
[release/2.1] *: properly shutdown non-groupable shims to prevent resource leaks
2 parents a86074c + cff1feb commit 5531309

4 files changed

Lines changed: 220 additions & 26 deletions

File tree

core/runtime/v2/shim.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,11 @@ func (s *shimTask) delete(ctx context.Context, sandboxed bool, removeTask func(c
556556
removeTask(ctx, s.ID())
557557
}
558558

559+
const supportSandboxAPIVersion = 3
560+
if _, apiVer := s.ShimInstance.Endpoint(); apiVer < supportSandboxAPIVersion {
561+
sandboxed = false
562+
}
563+
559564
// Don't shutdown sandbox as there may be other containers running.
560565
// Let controller decide when to shutdown.
561566
if !sandboxed {

core/runtime/v2/shim_load.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,26 @@ func loadShimTask(ctx context.Context, bundle *Bundle, onClose func()) (_ *shimT
206206
defer cancel()
207207

208208
if _, err := s.PID(ctx); err != nil {
209-
return nil, err
209+
if !errdefs.IsNotImplemented(err) {
210+
return nil, err
211+
}
212+
213+
downgrader, ok := shim.(clientVersionDowngrader)
214+
if ok {
215+
if derr := downgrader.Downgrade(); derr == nil {
216+
log.G(ctx).WithError(err).WithField("id", shim.ID()).
217+
Warning("failed to call task.PID, downgrading client API version to try again")
218+
219+
s, err = newShimTask(shim)
220+
if err != nil {
221+
return nil, fmt.Errorf("failed to create shim task after downgrading: %w", err)
222+
}
223+
_, err = s.PID(ctx)
224+
}
225+
}
226+
if err != nil {
227+
return nil, err
228+
}
210229
}
211230
return s, nil
212231
}

integration/issue10467_linux_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ func TestIssue10467(t *testing.T) {
6666
})
6767

6868
t.Log("Prepare pods for current release")
69-
upgradeCaseFunc, hookFunc := shouldManipulateContainersInPodAfterUpgrade("")(t, 2, previousProc.criRuntimeService(t), previousProc.criImageService(t))
69+
upgradeCaseFuncs, hookFunc := shouldManipulateContainersInPodAfterUpgrade("")(t, 2, previousProc.criRuntimeService(t), previousProc.criImageService(t))
70+
upgradeCaseFunc := upgradeCaseFuncs[0]
7071
needToCleanup = false
7172
require.Nil(t, hookFunc)
7273

0 commit comments

Comments
 (0)