Skip to content

Commit fd8d661

Browse files
rudyflycardyok
authored andcommitted
refer to containerd fix: containerd/containerd@2eb6721 Signed-off-by: Rudy Zhang <[email protected]>
1 parent 932d068 commit fd8d661

File tree

4 files changed

+52
-15
lines changed

4 files changed

+52
-15
lines changed

.circleci/config.yml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,6 @@ jobs:
1616
name: use markdownlint v0.5.0 to lint markdown file (https://github.com/markdownlint/markdownlint)
1717
command: |
1818
find ./ -name "*.md" | grep -v vendor | grep -v commandline | grep -v .github | grep -v swagger | grep -v api | xargs mdl -r ~MD010,~MD013,~MD024,~MD029,~MD033,~MD036
19-
- run:
20-
name: use markdown-link-check(https://github.com/tcort/markdown-link-check) to check links in markdown files
21-
command: |
22-
set +e
23-
for name in $(find . -name \*.md | grep -v vendor | grep -v CHANGELOG); do
24-
if [ -f $name ]; then
25-
markdown-link-check -q $name;
26-
if [ $? -ne 0 ]; then
27-
code=1
28-
fi
29-
fi
30-
done
31-
bash -c "exit $code";
3219
- run:
3320
name: use opensource tool client9/misspell to correct commonly misspelled English words
3421
command: |

cri/v1alpha2/cri.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ const (
7171

7272
// networkNotReadyReason is the reason reported when network is not ready.
7373
networkNotReadyReason = "NetworkPluginNotReady"
74+
75+
// maxMsgSize is the max size syncExec could output
76+
maxMsgSize = 1024 * 1024 * 64
7477
)
7578

7679
var (
@@ -1213,9 +1216,9 @@ func (c *CriManager) ExecSync(ctx context.Context, r *runtime.ExecSyncRequest) (
12131216
stdoutBuf, stderrBuf := bytes.NewBuffer(nil), bytes.NewBuffer(nil)
12141217
attachCfg := &pkgstreams.AttachConfig{
12151218
UseStdout: true,
1216-
Stdout: stdoutBuf,
1219+
Stdout: &cappedWriter{stdoutBuf, maxMsgSize},
12171220
UseStderr: true,
1218-
Stderr: stderrBuf,
1221+
Stderr: &cappedWriter{stderrBuf, maxMsgSize},
12191222
}
12201223

12211224
if err := c.ContainerMgr.StartExec(ctx, execid, attachCfg, int(r.GetTimeout())); err != nil {

cri/v1alpha2/cri_utils.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package v1alpha2
22

33
import (
44
"bytes"
5+
"errors"
56
"fmt"
67
"io"
78
"io/ioutil"
@@ -1273,3 +1274,31 @@ func applyContainerConfigByAnnotation(annotations map[string]string, config *api
12731274

12741275
return nil
12751276
}
1277+
1278+
type cappedWriter struct {
1279+
w io.Writer
1280+
remain int
1281+
}
1282+
1283+
var errNoRemain = errors.New("no more space to write")
1284+
1285+
func (cw *cappedWriter) Write(p []byte) (int, error) {
1286+
if cw.remain <= 0 {
1287+
return 0, errNoRemain
1288+
}
1289+
1290+
end := cw.remain
1291+
if end > len(p) {
1292+
end = len(p)
1293+
}
1294+
written, err := cw.w.Write(p[0:end])
1295+
cw.remain -= written
1296+
1297+
if err != nil {
1298+
return written, err
1299+
}
1300+
if written < len(p) {
1301+
return written, errNoRemain
1302+
}
1303+
return written, nil
1304+
}

cri/v1alpha2/cri_utils_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package v1alpha2
22

33
import (
4+
"bytes"
45
"fmt"
56
"reflect"
67
"strconv"
@@ -1974,3 +1975,20 @@ func Test_applyContainerConfigByAnnotation(t *testing.T) {
19741975
})
19751976
}
19761977
}
1978+
1979+
func TestCWWrite(t *testing.T) {
1980+
var buf bytes.Buffer
1981+
cw := &cappedWriter{w: &buf, remain: 10}
1982+
1983+
n, err := cw.Write([]byte("hello"))
1984+
assert.NoError(t, err)
1985+
assert.Equal(t, 5, n)
1986+
1987+
n, err = cw.Write([]byte("helloworld"))
1988+
assert.Equal(t, []byte("hellohello"), buf.Bytes(), "partial write")
1989+
assert.Equal(t, 5, n)
1990+
assert.Equal(t, err.Error(), errNoRemain.Error())
1991+
1992+
_, err = cw.Write([]byte("world"))
1993+
assert.Equal(t, err.Error(), errNoRemain.Error())
1994+
}

0 commit comments

Comments
 (0)