Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
songlinfeng
container-toolkit
Commits
0ccfece1
Commit
0ccfece1
authored
Nov 21, 2025
by
songlinfeng
Browse files
support docker swarm
parent
d2da0c28
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
10 deletions
+69
-10
internal/config/image/dtk_image.go
internal/config/image/dtk_image.go
+52
-1
internal/discover/graphics.go
internal/discover/graphics.go
+17
-7
internal/oci/spec.go
internal/oci/spec.go
+0
-2
No files found.
internal/config/image/dtk_image.go
View file @
0ccfece1
...
...
@@ -8,7 +8,8 @@ import (
"fmt"
"path/filepath"
"strings"
"dtk-container-toolkit/internal/hydcu"
"strconv"
"github.com/opencontainers/runtime-spec/specs-go"
"tags.cncf.io/container-device-interface/pkg/parser"
)
...
...
@@ -57,8 +58,29 @@ func (i DTK) Getenv(key string) string {
return
i
.
env
[
key
]
}
func
Contains
[
T
comparable
](
slice
[]
T
,
val
T
)
bool
{
for
_
,
item
:=
range
slice
{
if
item
==
val
{
return
true
}
}
return
false
}
// DevicesFromEnvvars returns the devices requested by the image through environment variables
func
(
i
DTK
)
DevicesFromEnvvars
(
envVars
...
string
)
VisibleDevices
{
isHexString
:=
func
(
s
string
)
bool
{
if
len
(
s
)
==
0
{
return
false
}
for
_
,
c
:=
range
s
{
if
!
((
c
>=
'0'
&&
c
<=
'9'
)
||
(
c
>=
'a'
&&
c
<=
'f'
)
||
(
c
>=
'A'
&&
c
<=
'F'
))
{
return
false
}
}
return
true
}
// We concantenate all the devices from the specified env.
var
isSet
bool
var
devices
[]
string
...
...
@@ -77,6 +99,35 @@ func (i DTK) DevicesFromEnvvars(envVars ...string) VisibleDevices {
}
}
uuidToDCUIdMap
,
err
:=
hydcu
.
GetUniqueIdToDeviceIndexMap
()
if
err
!=
nil
{
uuidToDCUIdMap
=
make
(
map
[
string
][]
int
)
}
for
key
,
value
:=
range
i
.
env
{
if
strings
.
HasPrefix
(
key
,
"DOCKER_RESOURCE_"
)
{
for
_
,
c
:=
range
strings
.
Split
(
value
,
","
)
{
if
strings
.
HasPrefix
(
c
,
"0x"
)
||
strings
.
HasPrefix
(
c
,
"0X"
)
||
(
len
(
c
)
>
8
&&
isHexString
(
c
))
{
uuid
:=
strings
.
ToLower
(
c
)
if
!
strings
.
HasPrefix
(
uuid
,
"0x"
)
{
uuid
=
"0x"
+
uuid
}
if
dcuId
,
exists
:=
uuidToDCUIdMap
[
uuid
];
exists
{
if
!
Contains
(
devices
,
strconv
.
Itoa
(
dcuId
[
0
]))
{
devices
=
append
(
devices
,
strconv
.
Itoa
(
dcuId
[
0
]))
}
}
else
{
uuid
=
strings
.
TrimPrefix
(
uuid
,
"0x"
)
if
dcuId
,
exists
:=
uuidToDCUIdMap
[
uuid
];
exists
{
devices
=
append
(
devices
,
strconv
.
Itoa
(
dcuId
[
0
]))
}
}
}
}
break
}
}
// Environment variable unset with legacy image: default to "all".
if
!
isSet
&&
len
(
devices
)
==
0
&&
i
.
IsLegacy
()
{
return
NewVisibleDevices
(
"all"
)
...
...
internal/discover/graphics.go
View file @
0ccfece1
...
...
@@ -121,12 +121,22 @@ func NewCommonHCUDiscoverer(logger logger.Interface, dtkCDIHookPath string, driv
trackHook
=
CreateTrackHook
(
dtkCDIHookPath
,
containerImage
.
ContainerId
)
}
d
:=
Merge
(
metaDevices
,
libraries
,
NewUserGroupDiscover
(
logger
),
linkHook
,
trackHook
,
)
var
d
Discover
if
trackHook
.
Lifecycle
==
""
{
d
=
Merge
(
metaDevices
,
libraries
,
NewUserGroupDiscover
(
logger
),
linkHook
,
)
}
else
{
d
=
Merge
(
metaDevices
,
libraries
,
NewUserGroupDiscover
(
logger
),
linkHook
,
trackHook
,
)
}
return
d
,
nil
}
internal/oci/spec.go
View file @
0ccfece1
...
...
@@ -7,7 +7,6 @@ package oci
import
(
"dtk-container-toolkit/internal/logger"
"fmt"
"github.com/opencontainers/runtime-spec/specs-go"
)
...
...
@@ -39,7 +38,6 @@ func NewSpec(logger logger.Interface, args []string) (Spec, error) {
ociSpecPath
:=
GetSpecFilePath
(
bundleDir
)
logger
.
Infof
(
"Using OCI specification file path: %v"
,
ociSpecPath
)
ociSpec
:=
NewFileSpec
(
ociSpecPath
)
return
ociSpec
,
nil
}
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