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
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
78 deletions
+35
-78
config_linux.go
pkg/agent/containerd/config_linux.go
+10
-2
runtimes.go
pkg/agent/containerd/runtimes.go
+25
-76
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 (
...
@@ -23,7 +23,10 @@ import (
"k8s.io/kubernetes/pkg/kubelet/util"
"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
{
func
getContainerdArgs
(
cfg
*
config
.
Node
)
[]
string
{
args
:=
[]
string
{
args
:=
[]
string
{
...
@@ -53,7 +56,12 @@ func setupContainerdConfig(ctx context.Context, cfg *config.Node) error {
...
@@ -53,7 +56,12 @@ func setupContainerdConfig(ctx context.Context, cfg *config.Node) error {
cfg
.
AgentConfig
.
Systemd
=
!
isRunningInUserNS
&&
controllers
[
"cpuset"
]
&&
os
.
Getenv
(
"INVOCATION_ID"
)
!=
""
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
// Verifies if the DefaultRuntime can be found
if
_
,
ok
:=
extraRuntimes
[
cfg
.
DefaultRuntime
];
!
ok
&&
cfg
.
DefaultRuntime
!=
""
{
if
_
,
ok
:=
extraRuntimes
[
cfg
.
DefaultRuntime
];
!
ok
&&
cfg
.
DefaultRuntime
!=
""
{
...
...
pkg/agent/containerd/runtimes.go
View file @
0b361c37
...
@@ -6,7 +6,7 @@ package containerd
...
@@ -6,7 +6,7 @@ package containerd
import
(
import
(
"errors"
"errors"
"io/fs"
"io/fs"
"
path/filepath
"
"
os/exec
"
"github.com/k3s-io/k3s/pkg/agent/templates"
"github.com/k3s-io/k3s/pkg/agent/templates"
"github.com/sirupsen/logrus"
"github.com/sirupsen/logrus"
...
@@ -17,63 +17,40 @@ import (
...
@@ -17,63 +17,40 @@ import (
type
runtimeConfigs
map
[
string
]
templates
.
ContainerdRuntimeConfig
type
runtimeConfigs
map
[
string
]
templates
.
ContainerdRuntimeConfig
// searchForRuntimes searches for runtimes and add into foundRuntimes
// searchForRuntimes searches for runtimes and add into foundRuntimes
// It checks install locations provided via potentitalRuntimes variable.
// It checks the PATH for the executables
// The binaries are searched at the locations specivied by locationsToCheck.
func
searchForRuntimes
(
potentialRuntimes
runtimeConfigs
,
foundRuntimes
runtimeConfigs
)
{
// 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.
// Fill in the binary location with just the name of the binary,
// 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,
// and check against each of the possible locations. If a match is found,
// set the location to the full path.
// set the location to the full path.
for
runtimeName
,
runtimeConfig
:=
range
potentialRuntimes
{
for
runtimeName
,
runtimeConfig
:=
range
potentialRuntimes
{
for
_
,
location
:=
range
locationsToCheck
{
logrus
.
Debugf
(
"Searching for %s container runtime"
,
runtimeName
)
binaryPath
:=
filepath
.
Join
(
location
,
runtimeConfig
.
BinaryName
)
path
,
err
:=
exec
.
LookPath
(
runtimeConfig
.
BinaryName
)
logrus
.
Debugf
(
"Searching for %s container runtime at /%s"
,
runtimeName
,
binaryPath
)
if
err
!=
nil
{
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
}
else
{
if
errors
.
Is
(
err
,
fs
.
ErrNotExist
)
{
if
errors
.
Is
(
err
,
fs
.
ErrNotExist
)
{
logrus
.
Debugf
(
"%s container runtime not found at /%s"
,
runtimeName
,
binaryPath
)
logrus
.
Debugf
(
"%s container runtime not found in $PATH: %v"
,
runtimeName
,
err
)
}
else
{
}
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
// findContainerRuntimes is a function that searches for all the runtimes and
// return a list with all the runtimes that have been found
// return a list with all the runtimes that have been found
func
findContainerRuntimes
(
root
fs
.
FS
)
runtimeConfigs
{
func
findContainerRuntimes
()
runtimeConfigs
{
foundRuntimes
:=
runtimeConfigs
{}
foundRuntimes
:=
runtimeConfigs
{}
findCRunContainerRuntime
(
root
,
foundRuntimes
)
findCRunContainerRuntime
(
foundRuntimes
)
findNvidiaContainerRuntimes
(
root
,
foundRuntimes
)
findNvidiaContainerRuntimes
(
foundRuntimes
)
findWasiRuntimes
(
root
,
foundRuntimes
)
findWasiRuntimes
(
foundRuntimes
)
return
foundRuntimes
return
foundRuntimes
}
}
// findCRunContainerRuntime finds if crun is available in the system and adds to foundRuntimes
func
findCRunContainerRuntime
(
foundRuntimes
runtimeConfigs
)
{
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.
potentialRuntimes
:=
runtimeConfigs
{
potentialRuntimes
:=
runtimeConfigs
{
"crun"
:
{
"crun"
:
{
RuntimeType
:
"io.containerd.runc.v2"
,
RuntimeType
:
"io.containerd.runc.v2"
,
...
@@ -81,25 +58,10 @@ func findCRunContainerRuntime(root fs.FS, foundRuntimes runtimeConfigs) {
...
@@ -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
func
findNvidiaContainerRuntimes
(
foundRuntimes
runtimeConfigs
)
{
// 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.
potentialRuntimes
:=
runtimeConfigs
{
potentialRuntimes
:=
runtimeConfigs
{
"nvidia"
:
{
"nvidia"
:
{
RuntimeType
:
"io.containerd.runc.v2"
,
RuntimeType
:
"io.containerd.runc.v2"
,
...
@@ -110,25 +72,11 @@ func findNvidiaContainerRuntimes(root fs.FS, foundRuntimes runtimeConfigs) {
...
@@ -110,25 +72,11 @@ func findNvidiaContainerRuntimes(root fs.FS, foundRuntimes runtimeConfigs) {
BinaryName
:
"nvidia-container-runtime-experimental"
,
BinaryName
:
"nvidia-container-runtime-experimental"
,
},
},
}
}
searchForRuntimes
(
root
,
potentialRuntimes
,
locationsToCheck
,
foundRuntimes
)
}
// findWasiRuntimes finds the WebAssembly (WASI) container runtimes that
searchForRuntimes
(
potentialRuntimes
,
foundRuntimes
)
// 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
}
// Fill in the binary location with just the name of the binary,
func
findWasiRuntimes
(
foundRuntimes
runtimeConfigs
)
{
// and check against each of the possible locations. If a match is found,
// set the location to the full path.
potentialRuntimes
:=
runtimeConfigs
{
potentialRuntimes
:=
runtimeConfigs
{
"lunatic"
:
{
"lunatic"
:
{
RuntimeType
:
"io.containerd.lunatic.v2"
,
RuntimeType
:
"io.containerd.lunatic.v2"
,
...
@@ -159,5 +107,6 @@ func findWasiRuntimes(root fs.FS, foundRuntimes runtimeConfigs) {
...
@@ -159,5 +107,6 @@ func findWasiRuntimes(root fs.FS, foundRuntimes runtimeConfigs) {
BinaryName
:
"containerd-shim-wasmtime-v1"
,
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