mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
Adjust debug logging and write containerd logs to a file
This commit is contained in:
parent
3df9155d02
commit
529aa431d1
@ -171,6 +171,9 @@ func get(envInfo *cmds.Agent) (*config.Node, error) {
|
||||
nodeConfig.Containerd.Config = filepath.Join(envInfo.DataDir, "etc/containerd/config.toml")
|
||||
nodeConfig.Containerd.Root = filepath.Join(envInfo.DataDir, "containerd")
|
||||
nodeConfig.Containerd.Opt = filepath.Join(envInfo.DataDir, "containerd")
|
||||
if !envInfo.Debug {
|
||||
nodeConfig.Containerd.Log = filepath.Join(envInfo.DataDir, "containerd/containerd.log")
|
||||
}
|
||||
nodeConfig.Containerd.State = "/run/k3s/containerd"
|
||||
nodeConfig.Containerd.Address = filepath.Join(nodeConfig.Containerd.State, "containerd.sock")
|
||||
nodeConfig.ServerAddress = serverURLParsed.Host
|
||||
|
@ -3,12 +3,14 @@ package containerd
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/natefinch/lumberjack"
|
||||
util2 "github.com/rancher/k3s/pkg/agent/util"
|
||||
"github.com/rancher/k3s/pkg/daemons/config"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -56,15 +58,30 @@ func Run(ctx context.Context, cfg *config.Node) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if logrus.GetLevel() >= logrus.DebugLevel {
|
||||
args = append(args, "-l", "debug")
|
||||
if os.Getenv("CONTAINERD_LOG_LEVEL") != "" {
|
||||
args = append(args, "-l", "CONTAINERD_LOG_LEVEL")
|
||||
}
|
||||
|
||||
stdOut := io.Writer(os.Stdout)
|
||||
stdErr := io.Writer(os.Stderr)
|
||||
|
||||
if cfg.Containerd.Log != "" {
|
||||
logrus.Infof("Logging containerd to %s", cfg.Containerd.Log)
|
||||
stdOut = &lumberjack.Logger{
|
||||
Filename: cfg.Containerd.Log,
|
||||
MaxSize: 50,
|
||||
MaxBackups: 3,
|
||||
MaxAge: 28,
|
||||
Compress: true,
|
||||
}
|
||||
stdErr = stdOut
|
||||
}
|
||||
|
||||
go func() {
|
||||
logrus.Infof("Running containerd %s", config.ArgString(args[1:]))
|
||||
cmd := exec.Command(args[0], args[1:]...)
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Stdout = stdOut
|
||||
cmd.Stderr = stdErr
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||
Pdeathsig: syscall.SIGKILL,
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ func Run(ctx *cli.Context) error {
|
||||
}
|
||||
|
||||
cfg := cmds.AgentConfig
|
||||
cfg.Debug = ctx.GlobalBool("debug")
|
||||
cfg.DataDir = dataDir
|
||||
|
||||
contextCtx := signal.SigTermCancelContext(context.Background())
|
||||
|
@ -8,8 +8,6 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"k8s.io/apimachinery/pkg/util/net"
|
||||
|
||||
"github.com/docker/docker/pkg/reexec"
|
||||
"github.com/natefinch/lumberjack"
|
||||
"github.com/rancher/k3s/pkg/agent"
|
||||
@ -18,6 +16,7 @@ import (
|
||||
"github.com/rancher/norman/signal"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/urfave/cli"
|
||||
"k8s.io/apimachinery/pkg/util/net"
|
||||
|
||||
_ "github.com/mattn/go-sqlite3" // ensure we have sqlite
|
||||
)
|
||||
@ -95,17 +94,18 @@ func run(app *cli.Context, cfg *cmds.Server) error {
|
||||
return err
|
||||
}
|
||||
|
||||
logrus.Info("k3s is up and running")
|
||||
|
||||
if cfg.DisableAgent {
|
||||
<-ctx.Done()
|
||||
return nil
|
||||
}
|
||||
|
||||
logFile := filepath.Join(serverConfig.ControlConfig.DataDir, "agent/agent.log")
|
||||
url := fmt.Sprintf("https://localhost:%d", serverConfig.TLSConfig.HTTPSPort)
|
||||
logrus.Infof("Agent starting, logging to %s", logFile)
|
||||
token := server.FormatToken(serverConfig.ControlConfig.Runtime.NodeToken, certs)
|
||||
|
||||
agentConfig := cmds.AgentConfig
|
||||
agentConfig.Debug = app.GlobalBool("bool")
|
||||
agentConfig.DataDir = filepath.Dir(serverConfig.ControlConfig.DataDir)
|
||||
agentConfig.ServerURL = url
|
||||
agentConfig.Token = token
|
||||
|
@ -23,6 +23,7 @@ type Node struct {
|
||||
|
||||
type Containerd struct {
|
||||
Address string
|
||||
Log string
|
||||
Root string
|
||||
State string
|
||||
Config string
|
||||
|
Loading…
Reference in New Issue
Block a user