From 78da8a8131e2ce257e2371f0b6ec51ab1f35c9f4 Mon Sep 17 00:00:00 2001 From: Cyrill Troxler Date: Sat, 1 Jun 2024 18:05:33 +0200 Subject: [PATCH] fix: use correct namespace for runc restore For some reason the namespace used was wrong all along. We now get the namespace from the initial context and store it in the config so we can use it during restore. --- zeropod/config.go | 9 +++++++++ zeropod/restore.go | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/zeropod/config.go b/zeropod/config.go index 1dce1ac..9ed315b 100644 --- a/zeropod/config.go +++ b/zeropod/config.go @@ -8,6 +8,7 @@ import ( "strings" "time" + "github.com/containerd/containerd/namespaces" "github.com/containerd/log" "github.com/mitchellh/mapstructure" "github.com/opencontainers/runtime-spec/specs-go" @@ -28,6 +29,7 @@ const ( portsDelim = containersDelim mappingDelim = ";" mapDelim = "=" + defaultContainerdNS = "k8s.io" ) type annotationConfig struct { @@ -54,6 +56,7 @@ type Config struct { PodName string PodNamespace string PodUID string + ContainerdNamespace string spec *specs.Spec } @@ -125,6 +128,11 @@ func NewConfig(ctx context.Context, spec *specs.Spec) (*Config, error) { containerNames = strings.Split(cfg.ZeropodContainerNames, containersDelim) } + ns, ok := namespaces.Namespace(ctx) + if !ok { + ns = defaultContainerdNS + } + return &Config{ Ports: containerPorts, ScaleDownDuration: dur, @@ -136,6 +144,7 @@ func NewConfig(ctx context.Context, spec *specs.Spec) (*Config, error) { PodName: cfg.PodName, PodNamespace: cfg.PodNamespace, PodUID: cfg.PodUID, + ContainerdNamespace: ns, spec: spec, }, nil } diff --git a/zeropod/restore.go b/zeropod/restore.go index 54954b5..36bac07 100644 --- a/zeropod/restore.go +++ b/zeropod/restore.go @@ -48,7 +48,7 @@ func (c *Container) Restore(ctx context.Context) (*runc.Container, process.Proce createReq.Checkpoint = "" } - container, err := runc.NewContainer(namespaces.WithNamespace(ctx, "k8s"), c.platform, createReq) + container, err := runc.NewContainer(namespaces.WithNamespace(ctx, c.cfg.ContainerdNamespace), c.platform, createReq) if err != nil { return nil, nil, err }