Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
0b361c37
Commit
0b361c37
authored
Jan 28, 2024
by
Vitor Savian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Runtimes refactor using exec.LookPath
Signed-off-by:
Vitor Savian
<
vitor.savian@suse.com
>
parent
6f3675d7
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
79 deletions
+36
-79
config_linux.go
pkg/agent/containerd/config_linux.go
+10
-2
runtimes.go
pkg/agent/containerd/runtimes.go
+26
-77
runtimes_test.go
pkg/agent/containerd/runtimes_test.go
+0
-0
No files found.
pkg/agent/containerd/config_linux.go
View file @
0b361c37
...
...
@@ -23,7 +23,10 @@ import (
"k8s.io/kubernetes/pkg/kubelet/util"
)
const
socketPrefix
=
"unix://"
const
(
socketPrefix
=
"unix://"
runtimesPath
=
"/usr/local/nvidia/toolkit:/opt/kwasm/bin:/usr/sbin:/usr/local/sbin:/usr/bin:/usr/local/bin"
)
func
getContainerdArgs
(
cfg
*
config
.
Node
)
[]
string
{
args
:=
[]
string
{
...
...
@@ -53,7 +56,12 @@ func setupContainerdConfig(ctx context.Context, cfg *config.Node) error {
cfg
.
AgentConfig
.
Systemd
=
!
isRunningInUserNS
&&
controllers
[
"cpuset"
]
&&
os
.
Getenv
(
"INVOCATION_ID"
)
!=
""
}
extraRuntimes
:=
findContainerRuntimes
(
os
.
DirFS
(
string
(
os
.
PathSeparator
)))
// set the path to include the runtimes and then remove the aditional path entries
// that we added after finding the runtimes
originalPath
:=
os
.
Getenv
(
"PATH"
)
os
.
Setenv
(
"PATH"
,
runtimesPath
)
extraRuntimes
:=
findContainerRuntimes
()
os
.
Setenv
(
"PATH"
,
originalPath
)
// Verifies if the DefaultRuntime can be found
if
_
,
ok
:=
extraRuntimes
[
cfg
.
DefaultRuntime
];
!
ok
&&
cfg
.
DefaultRuntime
!=
""
{
...
...
pkg/agent/containerd/runtimes.go
View file @
0b361c37
...
...
@@ -6,7 +6,7 @@ package containerd
import
(
"errors"
"io/fs"
"
path/filepath
"
"
os/exec
"
"github.com/k3s-io/k3s/pkg/agent/templates"
"github.com/sirupsen/logrus"
...
...
@@ -17,63 +17,40 @@ 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
"usr/local/bin"
,
// Path when installing manually
"usr/local/sbin"
,
// Path when installing manually
}
// 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"
,
...
...
@@ -81,25 +58,10 @@ func findCRunContainerRuntime(root fs.FS, foundRuntimes runtimeConfigs) {
},
}
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"
,
...
...
@@ -110,25 +72,11 @@ func findNvidiaContainerRuntimes(root fs.FS, foundRuntimes runtimeConfigs) {
BinaryName
:
"nvidia-container-runtime-experimental"
,
},
}
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"
,
...
...
@@ -159,5 +107,6 @@ func findWasiRuntimes(root fs.FS, foundRuntimes runtimeConfigs) {
BinaryName
:
"containerd-shim-wasmtime-v1"
,
},
}
searchForRuntimes
(
root
,
potentialRuntimes
,
locationsToCheck
,
foundRuntimes
)
searchForRuntimes
(
potentialRuntimes
,
foundRuntimes
)
}
pkg/agent/containerd/runtimes_test.go
View file @
0b361c37
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment