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
4 changes: 2 additions & 2 deletions cmd/containerd-shim-nerdbox-v1/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (

"github.com/containerd/containerd/v2/pkg/shim"

"github.com/containerd/nerdbox/internal/shim/manager"
"github.com/containerd/nerdbox/pkg/shim/manager"

_ "github.com/containerd/nerdbox/plugins/shim/sandbox"
_ "github.com/containerd/nerdbox/plugins/shim/streaming"
Expand All @@ -31,5 +31,5 @@ import (
)

func main() {
shim.RunShim(context.Background(), manager.NewShimManager("io.containerd.nerdbox.v1"))
shim.RunShim(context.Background(), manager.New("io.containerd.nerdbox.v1"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ import (
"github.com/containerd/containerd/v2/pkg/shim"
)

// NewShimManager returns an implementation of the shim manager
// using run_vminitd
func NewShimManager(name string) shim.Shim {
// New returns a shim manager implementation that launches the nerdbox shim
// process. The name is the runtime identifier reported to containerd (for
// example "io.containerd.nerdbox.v1"). External callers building variants
// of the nerdbox shim use this to assemble their own main package.
func New(name string) shim.Shim {
return &manager{
name: name,
}
Expand Down
93 changes: 93 additions & 0 deletions pkg/shim/manager/manager_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
Copyright The containerd Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package manager

import (
"context"
"os"
"path/filepath"
"strings"
"testing"
)

func TestNewName(t *testing.T) {
const name = "io.containerd.nerdbox.v1"
s := New(name)
if got := s.Name(); got != name {
t.Errorf("Name() = %q, want %q", got, name)
}
}

func TestInfo(t *testing.T) {
const name = "io.containerd.nerdbox.v1"
s := New(name)
info, err := s.Info(context.Background(), strings.NewReader(""))
if err != nil {
t.Fatalf("Info() error: %v", err)
}
if info.Name != name {
t.Errorf("Info().Name = %q, want %q", info.Name, name)
}
if got := info.Annotations["containerd.io/runtime-allow-mounts"]; got == "" {
t.Errorf("Info().Annotations missing runtime-allow-mounts: %v", info.Annotations)
}
}

func TestReadSpec(t *testing.T) {
dir := t.TempDir()
configPath := filepath.Join(dir, "config.json")
const body = `{"annotations":{"io.kubernetes.cri.sandbox-id":"abc123","other":"value"}}`
if err := os.WriteFile(configPath, []byte(body), 0o600); err != nil {
t.Fatal(err)
}

cwd, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { os.Chdir(cwd) })
if err := os.Chdir(dir); err != nil {
t.Fatal(err)
}

spec, err := readSpec()
if err != nil {
t.Fatalf("readSpec() error: %v", err)
}
if got := spec.Annotations["io.kubernetes.cri.sandbox-id"]; got != "abc123" {
t.Errorf("annotation sandbox-id = %q, want %q", got, "abc123")
}
if got := spec.Annotations["other"]; got != "value" {
t.Errorf("annotation other = %q, want %q", got, "value")
}
}

func TestReadSpecMissing(t *testing.T) {
dir := t.TempDir()
cwd, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { os.Chdir(cwd) })
if err := os.Chdir(dir); err != nil {
t.Fatal(err)
}

if _, err := readSpec(); !os.IsNotExist(err) {
t.Errorf("readSpec() error = %v, want os.IsNotExist", err)
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading