Skip to content

Commit

Permalink
fix: use correct namespace for runc restore
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ctrox committed Jun 1, 2024
1 parent 68cf778 commit 78da8a8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions zeropod/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -28,6 +29,7 @@ const (
portsDelim = containersDelim
mappingDelim = ";"
mapDelim = "="
defaultContainerdNS = "k8s.io"
)

type annotationConfig struct {
Expand All @@ -54,6 +56,7 @@ type Config struct {
PodName string
PodNamespace string
PodUID string
ContainerdNamespace string
spec *specs.Spec
}

Expand Down Expand Up @@ -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,
Expand All @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion zeropod/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 78da8a8

Please sign in to comment.