add containerd cli opts

Signed-off-by: Avi Deitcher <avi@deitcher.net>
This commit is contained in:
Avi Deitcher 2020-10-19 14:49:15 +03:00
parent a1427d0b7b
commit 865ed8a1ce
2 changed files with 35 additions and 1 deletions

View File

@ -37,6 +37,29 @@ If you're not seeing `containerd` logs in the console during boot, make sure tha
`init` and other processes like `containerd` will use the last defined console in the kernel `cmdline`. When using `qemu`, to see the console you need to list `ttyS0` as the last console to properly see the output.
## Enabling debug or trace log levels on containerd
On startup, linuxkit looks for and parses a file `/etc/containerd/cli-opts`. If it exists, the content is used as arguments to containerd. Thus, to enable
a higher log level, for example `debug`, create a file whose contents are `--log-level debug` and place it on the image:
```yml
files:
- path: /etc/containerd/cli-opts
contents: "--log-level debug"
```
Note that the package that parses the contents splits on _all_ whitespace. It does not, as of this writing, support shell-like parsing, so the following will work:
```
--log-level debug --arg abcd
```
while the following will not:
```
--log-level debug --arg 'abcd def'
```
## Troubleshooting containers
Linuxkit runs all services in a specific `containerd` namespace called `services.linuxkit`. To list all the defined containers:

View File

@ -8,6 +8,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"
"syscall"
"time"
@ -17,6 +18,10 @@ import (
log "github.com/sirupsen/logrus"
)
const (
containerdOptsFile = "/etc/containerd/cli-opts"
)
func cleanupTask(ctx context.Context, ctr containerd.Container) error {
task, err := ctr.Task(ctx, nil)
if err != nil {
@ -78,8 +83,14 @@ func systemInitCmd(ctx context.Context, args []string) {
// remove (unlikely) old containerd socket
_ = os.Remove(*sock)
// look for containerd options
ctrdArgs := []string{}
if b, err := ioutil.ReadFile(containerdOptsFile); err != nil {
ctrdArgs = strings.Fields(string(b))
}
// start up containerd
cmd := exec.Command(*binary)
cmd := exec.Command(*binary, ctrdArgs...)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Start(); err != nil {