Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions daemon/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,8 @@ type Config struct {
// runtimes config
Runtimes map[string]types.Runtime `json:"add-runtime,omitempty"`

// Namespace is passed to containerd, Namespace is not a daemon flag,
// do not marshal this field to config file.
Namespace string `json:"-"`
// DefaultNamespace is passed to containerd.
DefaultNamespace string `json:"default-namespace,omitempty"`
}

// Validate validates the user input config.
Expand Down
8 changes: 1 addition & 7 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/alibaba/pouch/apis/plugins"
"github.com/alibaba/pouch/apis/server"
criservice "github.com/alibaba/pouch/cri"
criconfig "github.com/alibaba/pouch/cri/config"
"github.com/alibaba/pouch/ctrd"
"github.com/alibaba/pouch/daemon/config"
"github.com/alibaba/pouch/daemon/events"
Expand Down Expand Up @@ -72,18 +71,13 @@ func NewDaemon(cfg *config.Config) *Daemon {
containerdBinaryFile = cfg.ContainerdPath
}

// the default unix socket path to the containerd socket
if cfg.IsCriEnabled {
cfg.Namespace = criconfig.K8sNamespace
}

containerd, err := ctrd.NewClient(cfg.HomeDir,
ctrd.WithDebugLog(cfg.Debug),
ctrd.WithStartDaemon(true),
ctrd.WithContainerdBinary(containerdBinaryFile),
ctrd.WithRPCAddr(cfg.ContainerdAddr),
ctrd.WithOOMScoreAdjust(cfg.OOMScoreAdjust),
ctrd.WithDefaultNamespace(cfg.Namespace),
ctrd.WithDefaultNamespace(cfg.DefaultNamespace),
)
if err != nil {
logrus.Errorf("failed to new containerd's client: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion daemon/mgr/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -1981,7 +1981,7 @@ func (mgr *ContainerManager) setBaseFS(ctx context.Context, c *Container, id str

// io.containerd.runtime.v1.linux as a const used by runc
c.Lock()
c.BaseFS = filepath.Join(mgr.Config.HomeDir, "containerd/state", "io.containerd.runtime.v1.linux", mgr.Config.Namespace, info.Name, "rootfs")
c.BaseFS = filepath.Join(mgr.Config.HomeDir, "containerd/state", "io.containerd.runtime.v1.linux", mgr.Config.DefaultNamespace, info.Name, "rootfs")
c.Unlock()
}

Expand Down
8 changes: 5 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ func setupFlags(cmd *cobra.Command) {
flagSet.StringVar(&cfg.Pidfile, "pidfile", "/var/run/pouch.pid", "Save daemon pid")
flagSet.IntVar(&cfg.OOMScoreAdjust, "oom-score-adj", -500, "Set the oom_score_adj for the daemon")
flagSet.Var(optscfg.NewRuntime(&cfg.Runtimes), "add-runtime", "register a OCI runtime to daemon")

// Notes(ziren): default-namespace is passed to containerd, the default
// value is 'default'. So if IsCriEnabled is true for k8s, we should set the DefaultNamespace
// to k8s.io
flagSet.StringVar(&cfg.DefaultNamespace, "default-namespace", namespaces.Default, "default-namespace is passed to containerd, the default value is 'default'")
}

// runDaemon prepares configs, setups essential details and runs pouchd daemon.
Expand All @@ -129,9 +134,6 @@ func runDaemon(cmd *cobra.Command) error {
return fmt.Errorf("failed to load daemon file: %s", err)
}

// set containerd namespace, we use containerd default namespace as pouch namespaces
cfg.Namespace = namespaces.Default

// parse log driver config
logOptMap, err := opts.ParseLogOptions(cfg.DefaultLogConfig.LogDriver, logOpts)
if err != nil {
Expand Down