Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: containerd update #360

Merged
merged 1 commit into from
Oct 22, 2024
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
8 changes: 4 additions & 4 deletions pkg/agent/containerd/config_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
fuseoverlayfs "github.com/containerd/fuse-overlayfs-snapshotter"
stargz "github.com/containerd/stargz-snapshotter/service"
"github.com/docker/docker/pkg/parsers/kernel"
"github.com/opencontainers/runc/libcontainer/userns"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/xiaods/k8e/pkg/agent/templates"
"github.com/xiaods/k8e/pkg/cgroups"
"github.com/xiaods/k8e/pkg/daemons/config"
"github.com/xiaods/k8e/pkg/version"
"github.com/opencontainers/runc/libcontainer/userns"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"golang.org/x/sys/unix"
"k8s.io/cri-client/pkg/util"
)
Expand Down Expand Up @@ -116,4 +116,4 @@ func FuseoverlayfsSupported(root string) error {

func StargzSupported(root string) error {
return stargz.Supported(root)
}
}
119 changes: 37 additions & 82 deletions pkg/agent/containerd/runtimes.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package containerd
import (
"errors"
"io/fs"
"path/filepath"
"os/exec"

"github.com/sirupsen/logrus"
"github.com/xiaods/k8e/pkg/agent/templates"
Expand All @@ -17,87 +17,51 @@ import (
type runtimeConfigs map[string]templates.ContainerdRuntimeConfig

// searchForRuntimes searches for runtimes and add into foundRuntimes
// It checks install locations provided via potentitalRuntimes variable.
// The binaries are searched at the locations specivied by locationsToCheck.
// The given fs.FS should represent the filesystem root directory to search in.
func searchForRuntimes(root fs.FS, potentialRuntimes runtimeConfigs, locationsToCheck []string, foundRuntimes runtimeConfigs) {
// Check these locations in order. The GPU operator's installation should
// take precedence over the package manager's installation.

// It checks the PATH for the executables
func searchForRuntimes(potentialRuntimes runtimeConfigs, foundRuntimes runtimeConfigs) {
// Fill in the binary location with just the name of the binary,
// and check against each of the possible locations. If a match is found,
// set the location to the full path.
for runtimeName, runtimeConfig := range potentialRuntimes {
for _, location := range locationsToCheck {
binaryPath := filepath.Join(location, runtimeConfig.BinaryName)
logrus.Debugf("Searching for %s container runtime at /%s", runtimeName, binaryPath)
if info, err := fs.Stat(root, binaryPath); err == nil {
if info.IsDir() {
logrus.Debugf("Found %s container runtime at /%s, but it is a directory. Skipping.", runtimeName, binaryPath)
continue
}
runtimeConfig.BinaryName = filepath.Join("/", binaryPath)
logrus.Infof("Found %s container runtime at %s", runtimeName, runtimeConfig.BinaryName)
foundRuntimes[runtimeName] = runtimeConfig
break
logrus.Debugf("Searching for %s container runtime", runtimeName)
path, err := exec.LookPath(runtimeConfig.BinaryName)
if err != nil {
if errors.Is(err, fs.ErrNotExist) {
logrus.Debugf("%s container runtime not found in $PATH: %v", runtimeName, err)
} else {
if errors.Is(err, fs.ErrNotExist) {
logrus.Debugf("%s container runtime not found at /%s", runtimeName, binaryPath)
} else {
logrus.Errorf("Error searching for %s container runtime at /%s: %v", runtimeName, binaryPath, err)
}
logrus.Debugf("Error searching for %s in $PATH: %v", runtimeName, err)
}
continue
}

logrus.Infof("Found %s container runtime at %s", runtimeName, path)
runtimeConfig.BinaryName = path
foundRuntimes[runtimeName] = runtimeConfig
}
}

// findContainerRuntimes is a function that searches for all the runtimes and
// return a list with all the runtimes that have been found
func findContainerRuntimes(root fs.FS) runtimeConfigs {
func findContainerRuntimes() runtimeConfigs {
foundRuntimes := runtimeConfigs{}
findCRunContainerRuntime(root, foundRuntimes)
findNvidiaContainerRuntimes(root, foundRuntimes)
findWasiRuntimes(root, foundRuntimes)
findCRunContainerRuntime(foundRuntimes)
findNvidiaContainerRuntimes(foundRuntimes)
findWasiRuntimes(foundRuntimes)
return foundRuntimes
}

// findCRunContainerRuntime finds if crun is available in the system and adds to foundRuntimes
func findCRunContainerRuntime(root fs.FS, foundRuntimes runtimeConfigs) {
// Check these locations in order.
locationsToCheck := []string{
"usr/sbin", // Path when installing via package manager
"usr/bin", // Path when installing via package manager
}

// Fill in the binary location with just the name of the binary,
// and check against each of the possible locations. If a match is found,
// set the location to the full path.
func findCRunContainerRuntime(foundRuntimes runtimeConfigs) {
potentialRuntimes := runtimeConfigs{
"crun": {
RuntimeType: "io.containerd.runc.v2",
BinaryName: "crun",
},
}

searchForRuntimes(root, potentialRuntimes, locationsToCheck, foundRuntimes)
searchForRuntimes(potentialRuntimes, foundRuntimes)
}

// findNvidiaContainerRuntimes finds the nvidia runtimes that are are available on the system
// and adds to foundRuntimes. It checks install locations used by the nvidia
// gpu operator and by system package managers. The gpu operator installation
// takes precedence over the system package manager installation.
// The given fs.FS should represent the filesystem root directory to search in.
func findNvidiaContainerRuntimes(root fs.FS, foundRuntimes runtimeConfigs) {
// Check these locations in order. The GPU operator's installation should
// take precedence over the package manager's installation.
locationsToCheck := []string{
"usr/local/nvidia/toolkit", // Path when installing via GPU Operator
"usr/bin", // Path when installing via package manager
}

// Fill in the binary location with just the name of the binary,
// and check against each of the possible locations. If a match is found,
// set the location to the full path.
func findNvidiaContainerRuntimes(foundRuntimes runtimeConfigs) {
potentialRuntimes := runtimeConfigs{
"nvidia": {
RuntimeType: "io.containerd.runc.v2",
Expand All @@ -107,55 +71,46 @@ func findNvidiaContainerRuntimes(root fs.FS, foundRuntimes runtimeConfigs) {
RuntimeType: "io.containerd.runc.v2",
BinaryName: "nvidia-container-runtime-experimental",
},
"nvidia-cdi": {
RuntimeType: "io.containerd.runc.v2",
BinaryName: "nvidia-container-runtime.cdi",
},
}
searchForRuntimes(root, potentialRuntimes, locationsToCheck, foundRuntimes)
}

// findWasiRuntimes finds the WebAssembly (WASI) container runtimes that
// are available on the system and adds to foundRuntimes. It checks install locations used by the kwasm
// operator and by system package managers. The kwasm operator installation
// takes precedence over the system package manager installation.
// The given fs.FS should represent the filesystem root directory to search in.
func findWasiRuntimes(root fs.FS, foundRuntimes runtimeConfigs) {
// Check these locations in order.
locationsToCheck := []string{
"opt/kwasm/bin", // Path when installing via kwasm Operator
"usr/bin", // Path when installing via package manager
"usr/sbin", // Path when installing via package manager
}
searchForRuntimes(potentialRuntimes, foundRuntimes)
}

// Fill in the binary location with just the name of the binary,
// and check against each of the possible locations. If a match is found,
// set the location to the full path.
func findWasiRuntimes(foundRuntimes runtimeConfigs) {
potentialRuntimes := runtimeConfigs{
"lunatic": {
RuntimeType: "io.containerd.lunatic.v2",
RuntimeType: "io.containerd.lunatic.v1",
BinaryName: "containerd-shim-lunatic-v1",
},
"slight": {
RuntimeType: "io.containerd.slight.v2",
RuntimeType: "io.containerd.slight.v1",
BinaryName: "containerd-shim-slight-v1",
},
"spin": {
RuntimeType: "io.containerd.spin.v2",
BinaryName: "containerd-shim-spin-v1",
BinaryName: "containerd-shim-spin-v2",
},
"wws": {
RuntimeType: "io.containerd.wws.v2",
RuntimeType: "io.containerd.wws.v1",
BinaryName: "containerd-shim-wws-v1",
},
"wasmedge": {
RuntimeType: "io.containerd.wasmedge.v2",
RuntimeType: "io.containerd.wasmedge.v1",
BinaryName: "containerd-shim-wasmedge-v1",
},
"wasmer": {
RuntimeType: "io.containerd.wasmer.v2",
RuntimeType: "io.containerd.wasmer.v1",
BinaryName: "containerd-shim-wasmer-v1",
},
"wasmtime": {
RuntimeType: "io.containerd.wasmtime.v2",
RuntimeType: "io.containerd.wasmtime.v1",
BinaryName: "containerd-shim-wasmtime-v1",
},
}
searchForRuntimes(root, potentialRuntimes, locationsToCheck, foundRuntimes)

searchForRuntimes(potentialRuntimes, foundRuntimes)
}
Loading
Loading