1- Modified patch to apply to version 1.21.7.
2- Modified-by: sumsharma@microsoft.com
3-
4- commit f032cf649ecc7e0c46718bd9e7814bfb317cb544 (from afab4b78d1d66fb5144ef003b20eba5e53833336)
5- Merge: afab4b78d 79e404fa5
6- Author: Peter Hunt <pehunt@redhat.com>
7- Date: Mon Jun 6 13:54:06 2022 -0400
8-
9- Merge pull request from GHSA-fcm2-6c3h-pg6j
10-
11- oci: add support for capping memory and disk usage from exec sync output
12- ---
13- internal/config/conmonmgr/conmonmgr.go | 32 +++++-
14- internal/config/conmonmgr/conmonmgr_test.go | 106 +++++++++++++++++-
15- internal/oci/oci.go | 5 +
16- internal/oci/runtime_oci.go | 19 +++-
17- internal/oci/runtime_oci_test.go | 39 +++++++
18- internal/oci/runtime_vm.go | 5 +-
19- pkg/config/config.go | 4 +
20- test/ctr.bats | 8 ++
21- .../pkg/kubelet/util/ioutils/ioutils.go | 70 ++++++++++++
22- vendor/modules.txt | 1 +
23- 10 files changed, 282 insertions(+), 7 deletions(-)
24- create mode 100644 vendor/k8s.io/kubernetes/pkg/kubelet/util/ioutils/ioutils.go
25-
261diff --git a/internal/config/conmonmgr/conmonmgr.go b/internal/config/conmonmgr/conmonmgr.go
27- index 9aef7ef..5276039 100644
2+ index 857437c..e95e274 100644
283--- a/internal/config/conmonmgr/conmonmgr.go
294+++ b/internal/config/conmonmgr/conmonmgr.go
305@@ -1,6 +1,7 @@
@@ -212,7 +187,7 @@ index a097312..e804c62 100644
212187+ })
213188 })
214189diff --git a/internal/oci/oci.go b/internal/oci/oci.go
215- index 478726d..d992e90 100644
190+ index 6c4efa9..89ecfb2 100644
216191--- a/internal/oci/oci.go
217192+++ b/internal/oci/oci.go
218193@@ -35,6 +35,11 @@ const (
@@ -228,10 +203,10 @@ index 478726d..d992e90 100644
228203
229204 // Runtime is the generic structure holding both global and specific
230205diff --git a/internal/oci/runtime_oci.go b/internal/oci/runtime_oci.go
231- index 4bf66ee..37f62c6 100644
206+ index 6295ff9..1ed9131 100644
232207--- a/internal/oci/runtime_oci.go
233208+++ b/internal/oci/runtime_oci.go
234- @@ -458 ,6 +458 ,9 @@ func (r *runtimeOCI) ExecSyncContainer(ctx context.Context, c *Container, comman
209+ @@ -461 ,6 +461 ,9 @@ func (r *runtimeOCI) ExecSyncContainer(ctx context.Context, c *Container, comman
235210 if r.config.ConmonSupportsSync() {
236211 args = append(args, "--sync")
237212 }
@@ -241,7 +216,7 @@ index 4bf66ee..37f62c6 100644
241216 if c.terminal {
242217 args = append(args, "-t")
243218 }
244- @@ -564 ,7 +567 ,7 @@ func (r *runtimeOCI) ExecSyncContainer(ctx context.Context, c *Container, comman
219+ @@ -567 ,7 +570 ,7 @@ func (r *runtimeOCI) ExecSyncContainer(ctx context.Context, c *Container, comman
245220 // ExecSyncResponse we have to read the logfile.
246221 // XXX: Currently runC dups the same console over both stdout and stderr,
247222 // so we can't differentiate between the two.
@@ -250,7 +225,7 @@ index 4bf66ee..37f62c6 100644
250225 if err != nil {
251226 return nil, &ExecSyncError{
252227 Stdout: stdoutBuf,
253- @@ -583 ,6 +586 ,20 @@ func (r *runtimeOCI) ExecSyncContainer(ctx context.Context, c *Container, comman
228+ @@ -586 ,6 +589 ,20 @@ func (r *runtimeOCI) ExecSyncContainer(ctx context.Context, c *Container, comman
254229 }, nil
255230 }
256231
@@ -329,19 +304,19 @@ index 3385e30..90901e8 100644
329304
330305 func waitContainerStopAndFailAfterTimeout(ctx context.Context,
331306diff --git a/internal/oci/runtime_vm.go b/internal/oci/runtime_vm.go
332- index 6f10cfc..be8a0fa 100644
307+ index 394b750..51465da 100644
333308--- a/internal/oci/runtime_vm.go
334309+++ b/internal/oci/runtime_vm.go
335- @@ -33 ,6 +33 ,7 @@ import (
310+ @@ -36 ,6 +36 ,7 @@ import (
336311 "golang.org/x/sys/unix"
337312 "k8s.io/client-go/tools/remotecommand"
338313 kubecontainer "k8s.io/kubernetes/pkg/kubelet/container"
339314+ kioutil "k8s.io/kubernetes/pkg/kubelet/util/ioutils"
340315 utilexec "k8s.io/utils/exec"
341316 )
342317
343- @@ -309 ,8 +310 ,8 @@ func (r *runtimeVM) ExecSyncContainer(ctx context.Context, c *Container, command
344- defer log.Debugf(ctx, "runtimeVM .ExecSyncContainer() end")
318+ @@ -339 ,8 +340 ,8 @@ func (r *runtimeVM) ExecSyncContainer(ctx context.Context, c *Container, command
319+ defer log.Debugf(ctx, "RuntimeVM .ExecSyncContainer() end")
345320
346321 var stdoutBuf, stderrBuf bytes.Buffer
347322- stdout := cioutil.NewNopWriteCloser(&stdoutBuf)
@@ -352,10 +327,10 @@ index 6f10cfc..be8a0fa 100644
352327 exitCode, err := r.execContainerCommon(ctx, c, command, timeout, nil, stdout, stderr, c.terminal, nil)
353328 if err != nil {
354329diff --git a/pkg/config/config.go b/pkg/config/config.go
355- index 25c51e2..606c7a9 100644
330+ index 7a75ff8..591623a 100644
356331--- a/pkg/config/config.go
357332+++ b/pkg/config/config.go
358- @@ -1011 ,6 +1011 ,10 @@ func (c *RuntimeConfig) ConmonSupportsSync() bool {
333+ @@ -1065 ,6 +1065 ,10 @@ func (c *RuntimeConfig) ConmonSupportsSync() bool {
359334 return c.conmonManager.SupportsSync()
360335 }
361336
@@ -367,7 +342,7 @@ index 25c51e2..606c7a9 100644
367342 var err error
368343 c.PinnsPath, err = validateExecutablePath(executable, c.PinnsPath)
369344diff --git a/test/ctr.bats b/test/ctr.bats
370- index 31cf6c7..a9f9393 100644
345+ index 3e7577d..ea7b635 100644
371346--- a/test/ctr.bats
372347+++ b/test/ctr.bats
373348@@ -487,6 +487,14 @@ function check_oci_annotation() {
@@ -385,93 +360,15 @@ index 31cf6c7..a9f9393 100644
385360 @test "ctr device add" {
386361 # In an user namespace we can only bind mount devices from the host, not mknod
387362 # https://github.com/opencontainers/runc/blob/master/libcontainer/rootfs_linux.go#L480-L481
388- diff --git a/vendor/k8s.io/kubernetes/pkg/kubelet/util/ioutils/ioutils.go b/vendor/k8s.io/kubernetes/pkg/kubelet/util/ioutils/ioutils.go
389- new file mode 100644
390- index 0000000..1b2b5a6
391- --- /dev/null
392- +++ b/vendor/k8s.io/kubernetes/pkg/kubelet/util/ioutils/ioutils.go
393- @@ -0,0 +1,70 @@
394- + /*
395- + Copyright 2016 The Kubernetes Authors.
396- +
397- + Licensed under the Apache License, Version 2.0 (the "License");
398- + you may not use this file except in compliance with the License.
399- + You may obtain a copy of the License at
400- +
401- + http://www.apache.org/licenses/LICENSE-2.0
402- +
403- + Unless required by applicable law or agreed to in writing, software
404- + distributed under the License is distributed on an "AS IS" BASIS,
405- + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
406- + See the License for the specific language governing permissions and
407- + limitations under the License.
408- + */
409- +
410- + package ioutils
411- +
412- + import "io"
413- +
414- + // writeCloserWrapper represents a WriteCloser whose closer operation is noop.
415- + type writeCloserWrapper struct {
416- + Writer io.Writer
417- + }
418- +
419- + func (w *writeCloserWrapper) Write(buf []byte) (int, error) {
420- + return w.Writer.Write(buf)
421- + }
422- +
423- + func (w *writeCloserWrapper) Close() error {
424- + return nil
425- + }
426- +
427- + // WriteCloserWrapper returns a writeCloserWrapper.
428- + func WriteCloserWrapper(w io.Writer) io.WriteCloser {
429- + return &writeCloserWrapper{w}
430- + }
431- +
432- + // LimitWriter is a copy of the standard library ioutils.LimitReader,
433- + // applied to the writer interface.
434- + // LimitWriter returns a Writer that writes to w
435- + // but stops with EOF after n bytes.
436- + // The underlying implementation is a *LimitedWriter.
437- + func LimitWriter(w io.Writer, n int64) io.Writer { return &LimitedWriter{w, n} }
438- +
439- + // A LimitedWriter writes to W but limits the amount of
440- + // data returned to just N bytes. Each call to Write
441- + // updates N to reflect the new amount remaining.
442- + // Write returns EOF when N <= 0 or when the underlying W returns EOF.
443- + type LimitedWriter struct {
444- + W io.Writer // underlying writer
445- + N int64 // max bytes remaining
446- + }
447- +
448- + func (l *LimitedWriter) Write(p []byte) (n int, err error) {
449- + if l.N <= 0 {
450- + return 0, io.ErrShortWrite
451- + }
452- + truncated := false
453- + if int64(len(p)) > l.N {
454- + p = p[0:l.N]
455- + truncated = true
456- + }
457- + n, err = l.W.Write(p)
458- + l.N -= int64(n)
459- + if err == nil && truncated {
460- + err = io.ErrShortWrite
461- + }
462- + return
463- + }
464363diff --git a/vendor/modules.txt b/vendor/modules.txt
465- index 030e1d1..d911968 100644
364+ index 6f8a08b..1899c90 100644
466365--- a/vendor/modules.txt
467366+++ b/vendor/modules.txt
468- @@ -1373 ,6 +1373 ,7 @@ k8s.io/kubernetes/pkg/kubelet/cri/streaming
367+ @@ -1517 ,6 +1517 ,7 @@ k8s.io/kubernetes/pkg/kubelet/cri/streaming
469368 k8s.io/kubernetes/pkg/kubelet/cri/streaming/portforward
470369 k8s.io/kubernetes/pkg/kubelet/cri/streaming/remotecommand
471370 k8s.io/kubernetes/pkg/kubelet/types
472371+ k8s.io/kubernetes/pkg/kubelet/util/ioutils
473372 k8s.io/kubernetes/pkg/proxy
474373 k8s.io/kubernetes/pkg/proxy/config
475374 k8s.io/kubernetes/pkg/proxy/healthcheck
476- - -
477- 2.25.1
0 commit comments