Skip to content
Open
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
1 change: 1 addition & 0 deletions pkg/agent/phases/nodestart/assets/containerd.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ oom_score = 0
version = 2

[plugins."io.containerd.grpc.v1.cri"]
device_ownership_from_security_context = true
sandbox_image = "{{.SandboxImage}}"

[plugins."io.containerd.grpc.v1.cri".containerd]
Expand Down
31 changes: 31 additions & 0 deletions pkg/agent/phases/nodestart/cri_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"os"
"path/filepath"
"strings"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -35,6 +36,36 @@ func TestConfigureContainerdWritesGantryHostsConfig(t *testing.T) {
require.Equal(t, os.FileMode(0o644), info.Mode().Perm())
}

func TestConfigureContainerdEnablesDeviceOwnershipFromSecurityContext(t *testing.T) {
t.Parallel()

machineDir := t.TempDir()
goalState := &goalstates.NodeStart{
MachineDir: machineDir,
Containerd: goalstates.ResolveContainerd(""),
}

require.NoError(t, ConfigureContainerd(goalState).Do(context.Background()))

path := filepath.Join(machineDir, goalstates.ContainerdConfigPath)
data, err := os.ReadFile(path)
require.NoError(t, err)

config := string(data)

const sectionHeader = `[plugins."io.containerd.grpc.v1.cri"]`

sectionStart := strings.Index(config, sectionHeader)
require.NotEqual(t, -1, sectionStart)

section := config[sectionStart+len(sectionHeader):]
if sectionEnd := strings.Index(section, "\n["); sectionEnd >= 0 {
section = section[:sectionEnd]
}

require.Contains(t, section, "device_ownership_from_security_context = true")
}

func TestConfigureContainerdUpdatesManagedGantryHostsConfig(t *testing.T) {
t.Parallel()

Expand Down
Loading