Skip to content

Commit b7015c1

Browse files
authored
Put the gvisor user log into sandbox log directory. (google#17)
Signed-off-by: Lantao Liu <[email protected]>
1 parent 326bc9f commit b7015c1

File tree

8 files changed

+49
-30
lines changed

8 files changed

+49
-30
lines changed

pkg/go-runsc/utils.go

+1-11
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,8 @@ func putBuf(b *bytes.Buffer) {
3939
}
4040

4141
// FormatLogPath parses runsc config, and fill in %ID% in the log path.
42-
// * For debug-log, it fills in the id in place;
43-
// * For user-log, it fills in the id, returns the user log path, and deletes
44-
// the `user-log` entry from the config, because it will only be added to runsc
45-
// calls that create a new sandbox.
46-
func FormatLogPath(id string, config map[string]string) string {
42+
func FormatLogPath(id string, config map[string]string) {
4743
if path, ok := config["debug-log"]; ok {
4844
config["debug-log"] = strings.Replace(path, "%ID%", id, -1)
4945
}
50-
var userLog string
51-
if path, ok := config["user-log"]; ok {
52-
userLog = strings.Replace(path, "%ID%", id, -1)
53-
delete(config, "user-log")
54-
}
55-
return userLog
5646
}

pkg/v1/shim/service.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ func newInit(ctx context.Context, path, workDir, runtimeRoot, namespace string,
551551
if err != nil {
552552
return nil, errors.Wrap(err, "read oci spec")
553553
}
554-
userLog := runsc.FormatLogPath(r.ID, config)
554+
runsc.FormatLogPath(r.ID, config)
555555
rootfs := filepath.Join(path, "rootfs")
556556
runtime := proc.NewRunsc(runtimeRoot, path, namespace, r.Runtime, config)
557557
p := proc.New(r.ID, runtime, rproc.Stdio{
@@ -567,7 +567,7 @@ func newInit(ctx context.Context, path, workDir, runtimeRoot, namespace string,
567567
p.IoUID = int(options.IoUid)
568568
p.IoGID = int(options.IoGid)
569569
p.Sandbox = utils.IsSandbox(spec)
570-
p.UserLog = userLog
570+
p.UserLog = utils.UserLogPath(spec)
571571
p.Monitor = shim.Default
572572
return p, nil
573573
}

pkg/v1/utils/utils.go

+9
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,12 @@ func IsSandbox(spec *specs.Spec) bool {
4848
t, ok := spec.Annotations[annotations.ContainerType]
4949
return !ok || t == annotations.ContainerTypeSandbox
5050
}
51+
52+
// UserLogPath gets user log path from OCI annotation.
53+
func UserLogPath(spec *specs.Spec) string {
54+
sandboxLogDir := spec.Annotations[annotations.SandboxLogDir]
55+
if sandboxLogDir == "" {
56+
return ""
57+
}
58+
return filepath.Join(sandboxLogDir, "gvisor.log")
59+
}

pkg/v2/service.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ func newInit(ctx context.Context, path, workDir, namespace string, platform rpro
696696
if err != nil {
697697
return nil, errors.Wrap(err, "read oci spec")
698698
}
699-
userLog := runsc.FormatLogPath(r.ID, options.RunscConfig)
699+
runsc.FormatLogPath(r.ID, options.RunscConfig)
700700
rootfs := filepath.Join(path, "rootfs")
701701
runtime := proc.NewRunsc(options.Root, path, namespace, options.BinaryName, options.RunscConfig)
702702
p := proc.New(r.ID, runtime, rproc.Stdio{
@@ -712,7 +712,7 @@ func newInit(ctx context.Context, path, workDir, namespace string, platform rpro
712712
p.IoUID = int(options.IoUid)
713713
p.IoGID = int(options.IoGid)
714714
p.Sandbox = utils.IsSandbox(spec)
715-
p.UserLog = userLog
715+
p.UserLog = utils.UserLogPath(spec)
716716
p.Monitor = shim.Default
717717
return p, nil
718718
}

vendor.conf

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ github.com/BurntSushi/toml v0.3.0
22
github.com/containerd/cgroups 5e610833b72089b37d0e615de9a92dfc043757c2
33
github.com/containerd/console c12b1e7919c14469339a5d38f2f8ed9b64a9de23
44
github.com/containerd/containerd v1.2.2
5-
github.com/containerd/cri 4dd6735020f5596dd41738f8c4f5cb07fa804c5e
5+
github.com/containerd/cri 8a0bd84b9a4c988a3098fca8fedcb9c0f14d9d08
66
github.com/containerd/fifo 3d5202aec260678c48179c56f40e6f38a095738c
77
github.com/containerd/go-runc 5a6d9f37cfa36b15efba46dc7ea349fa9b7143c3
88
github.com/containerd/ttrpc 2a805f71863501300ae1976d29f0454ae003e85a

vendor/github.com/containerd/cri/README.md

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/containerd/cri/pkg/annotations/annotations.go

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/containerd/cri/vendor.conf

+14-14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)