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 <cpuguy83@gmail.com>
This commit is contained in:
Brian Goff 2024-10-01 17:25:04 +00:00
parent 05ee43a5fd
commit 11ffba3dc4
2 changed files with 19 additions and 4 deletions

View File

@ -40,7 +40,6 @@ import (
"github.com/containerd/containerd/v2/cmd/containerd-shim-runc-v2/runc" "github.com/containerd/containerd/v2/cmd/containerd-shim-runc-v2/runc"
"github.com/containerd/containerd/v2/core/mount" "github.com/containerd/containerd/v2/core/mount"
"github.com/containerd/containerd/v2/pkg/namespaces" "github.com/containerd/containerd/v2/pkg/namespaces"
"github.com/containerd/containerd/v2/pkg/oci"
"github.com/containerd/containerd/v2/pkg/schedcore" "github.com/containerd/containerd/v2/pkg/schedcore"
"github.com/containerd/containerd/v2/pkg/shim" "github.com/containerd/containerd/v2/pkg/shim"
"github.com/containerd/containerd/v2/version" "github.com/containerd/containerd/v2/version"
@ -112,7 +111,8 @@ func newCommand(ctx context.Context, id, containerdAddress, containerdTTRPCAddre
} }
func readSpec() (*spec, error) { func readSpec() (*spec, error) {
f, err := os.Open(oci.ConfigFilename) const configFileName = "config.json"
f, err := os.Open(configFileName)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -20,9 +20,10 @@ package runc
import ( import (
"context" "context"
"encoding/json"
"os"
"path/filepath" "path/filepath"
"github.com/containerd/containerd/v2/pkg/oci"
"github.com/containerd/log" "github.com/containerd/log"
"github.com/opencontainers/runtime-spec/specs-go" "github.com/opencontainers/runtime-spec/specs-go"
) )
@ -30,7 +31,7 @@ import (
// ShouldKillAllOnExit reads the bundle's OCI spec and returns true if // ShouldKillAllOnExit reads the bundle's OCI spec and returns true if
// there is an error reading the spec or if the container has a private PID namespace // there is an error reading the spec or if the container has a private PID namespace
func ShouldKillAllOnExit(ctx context.Context, bundlePath string) bool { func ShouldKillAllOnExit(ctx context.Context, bundlePath string) bool {
spec, err := oci.ReadSpec(filepath.Join(bundlePath, oci.ConfigFilename)) spec, err := readSpec(bundlePath)
if err != nil { if err != nil {
log.G(ctx).WithError(err).Error("shouldKillAllOnExit: failed to read config.json") log.G(ctx).WithError(err).Error("shouldKillAllOnExit: failed to read config.json")
return true return true
@ -45,3 +46,17 @@ func ShouldKillAllOnExit(ctx context.Context, bundlePath string) bool {
} }
return true return true
} }
func readSpec(p string) (*specs.Spec, error) {
const configFileName = "config.json"
f, err := os.Open(filepath.Join(p, configFileName))
if err != nil {
return nil, err
}
defer f.Close()
var s specs.Spec
if err := json.NewDecoder(f).Decode(&s); err != nil {
return nil, err
}
return &s, nil
}