Skip to content

Commit 11ffba3

Browse files
committed
shim: Do not depend on pkg/oci
pkg/oci is a general utility package with dependency chains that are uneccessary for the shim. The shim only actually used it for a convenience function for reading an oci spec file. Instead of pulling in those deps just re-implement that internally in the shim command. Signed-off-by: Brian Goff <[email protected]>
1 parent 05ee43a commit 11ffba3

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

cmd/containerd-shim-runc-v2/manager/manager_linux.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ import (
4040
"github.com/containerd/containerd/v2/cmd/containerd-shim-runc-v2/runc"
4141
"github.com/containerd/containerd/v2/core/mount"
4242
"github.com/containerd/containerd/v2/pkg/namespaces"
43-
"github.com/containerd/containerd/v2/pkg/oci"
4443
"github.com/containerd/containerd/v2/pkg/schedcore"
4544
"github.com/containerd/containerd/v2/pkg/shim"
4645
"github.com/containerd/containerd/v2/version"
@@ -112,7 +111,8 @@ func newCommand(ctx context.Context, id, containerdAddress, containerdTTRPCAddre
112111
}
113112

114113
func readSpec() (*spec, error) {
115-
f, err := os.Open(oci.ConfigFilename)
114+
const configFileName = "config.json"
115+
f, err := os.Open(configFileName)
116116
if err != nil {
117117
return nil, err
118118
}

cmd/containerd-shim-runc-v2/runc/util.go

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,18 @@ package runc
2020

2121
import (
2222
"context"
23+
"encoding/json"
24+
"os"
2325
"path/filepath"
2426

25-
"github.com/containerd/containerd/v2/pkg/oci"
2627
"github.com/containerd/log"
2728
"github.com/opencontainers/runtime-spec/specs-go"
2829
)
2930

3031
// ShouldKillAllOnExit reads the bundle's OCI spec and returns true if
3132
// there is an error reading the spec or if the container has a private PID namespace
3233
func ShouldKillAllOnExit(ctx context.Context, bundlePath string) bool {
33-
spec, err := oci.ReadSpec(filepath.Join(bundlePath, oci.ConfigFilename))
34+
spec, err := readSpec(bundlePath)
3435
if err != nil {
3536
log.G(ctx).WithError(err).Error("shouldKillAllOnExit: failed to read config.json")
3637
return true
@@ -45,3 +46,17 @@ func ShouldKillAllOnExit(ctx context.Context, bundlePath string) bool {
4546
}
4647
return true
4748
}
49+
50+
func readSpec(p string) (*specs.Spec, error) {
51+
const configFileName = "config.json"
52+
f, err := os.Open(filepath.Join(p, configFileName))
53+
if err != nil {
54+
return nil, err
55+
}
56+
defer f.Close()
57+
var s specs.Spec
58+
if err := json.NewDecoder(f).Decode(&s); err != nil {
59+
return nil, err
60+
}
61+
return &s, nil
62+
}

0 commit comments

Comments
 (0)