mirror of
https://gitlab.com/arm-research/smarter/smarter-device-manager.git
synced 2025-04-05 22:48:57 +00:00
Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
fe5dca8f1c | ||
|
07f4b88b53 | ||
|
d65b7208db | ||
|
fe9b26d283 | ||
|
e20fb9b58f | ||
|
741d8edc23 | ||
|
261f70121a | ||
|
8a304aa5ee | ||
|
1421f564e5 | ||
|
567ac37994 | ||
|
a6c2189a98 | ||
|
1d718e57be | ||
|
733ac32871 | ||
|
ab97aba78f | ||
|
8adb22dc29 |
@ -10,15 +10,13 @@ COPY . .
|
||||
|
||||
RUN echo $PATH;export CGO_LDFLAGS_ALLOW='-Wl,--unresolved-symbols=ignore-in-object-files' && \
|
||||
go mod init arm.com/smarter-device-management && go mod tidy && go mod vendor && \
|
||||
go build -ldflags="-s -w" .
|
||||
CGO_ENABLED=0 go build -ldflags='-s -w -extldflags="-static"' .
|
||||
|
||||
FROM alpine
|
||||
|
||||
RUN apk update && apk upgrade
|
||||
FROM scratch
|
||||
|
||||
WORKDIR /root
|
||||
|
||||
COPY conf.yaml /root/config/conf.yaml
|
||||
COPY --from=build /arm.com/smarter-device-management/smarter-device-management /usr/bin/smarter-device-management
|
||||
|
||||
CMD ["smarter-device-management","-logtostderr=true","-v=0"]
|
||||
CMD ["/usr/bin/smarter-device-management","-logtostderr=true","-v=0"]
|
||||
|
@ -17,6 +17,10 @@ The smarter-device-manager starts by reading a YAML configuration file. This con
|
||||
nummaxdevices: 10
|
||||
```
|
||||
|
||||
Devices in subdirectories have the slash replaced with underscore in the
|
||||
resource name, due to kubernetes naming restrictions: e.g. `/dev/net/tun`
|
||||
becomes `smarter-devices/net_tun`.
|
||||
|
||||
The default config file provided will enable most of the devices available on a Raspberry Pi (vers 1-4) or equivalent boards. I2C, SPI, video devices, sound and others would be enabled. The config file can be replaced using a configmap to enable or disable access to different devices, like accelerators, GPUs, etc.
|
||||
|
||||
The node will show the devices it recognizes as resources in the node object in Kubernetes. The example below shows a raspberry PI.
|
||||
|
73
main.go
73
main.go
@ -55,18 +55,60 @@ func init() {
|
||||
flag.Parse()
|
||||
}
|
||||
|
||||
func readDevDirectory(dirToList string) (files []string, err error) {
|
||||
f, err := os.Open(dirToList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
files, err = f.Readdirnames(-1)
|
||||
f.Close()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
func readDevDirectory(dirToList string, allowedRecursions uint8) (files []string, err error) {
|
||||
var foundFiles []string
|
||||
|
||||
return files, nil
|
||||
fType, err := os.Stat(dirToList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !fType.IsDir() {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
f, err := os.Open(dirToList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
files, err = f.Readdirnames(-1)
|
||||
if err != nil {
|
||||
f.Close()
|
||||
return nil, err
|
||||
}
|
||||
f.Close()
|
||||
for _, subDir := range files {
|
||||
foundFiles = append(foundFiles, subDir)
|
||||
if allowedRecursions > 0 {
|
||||
filesDir, err := readDevDirectory(dirToList+"/"+subDir,allowedRecursions-1)
|
||||
if err == nil {
|
||||
for _, fileName := range filesDir {
|
||||
foundFiles = append(foundFiles, subDir+"/"+fileName)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return foundFiles, nil
|
||||
}
|
||||
|
||||
func sanitizeName(path string) string {
|
||||
sanitizeChar := func(r rune) rune {
|
||||
switch {
|
||||
case r >= 'A' && r <= 'Z':
|
||||
return r
|
||||
case r >= 'a' && r <= 'z':
|
||||
return r
|
||||
case r >= '0' && r <= '9':
|
||||
return r
|
||||
case r == '_':
|
||||
return r
|
||||
case r == '-':
|
||||
return r
|
||||
}
|
||||
return '_'
|
||||
}
|
||||
return strings.Map(sanitizeChar, path)
|
||||
}
|
||||
|
||||
func findDevicesPattern(listDevices []string, pattern string) ([]string,error) {
|
||||
@ -102,13 +144,13 @@ func main() {
|
||||
}
|
||||
|
||||
glog.V(0).Info("Reading existing devices on /dev")
|
||||
ExistingDevices, err := readDevDirectory("/dev")
|
||||
ExistingDevices, err := readDevDirectory("/dev",10)
|
||||
if err != nil {
|
||||
glog.Errorf(err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
ExistingDevicesSys, err := readDevDirectory("/sys/devices")
|
||||
ExistingDevicesSys, err := readDevDirectory("/sys/devices",0)
|
||||
if err != nil {
|
||||
glog.Errorf(err.Error())
|
||||
os.Exit(1)
|
||||
@ -151,9 +193,10 @@ func main() {
|
||||
if len(foundDevices) > 0 {
|
||||
for _, deviceToCreate := range foundDevices {
|
||||
var newDevice DeviceInstance
|
||||
deviceSafeName := sanitizeName(deviceToCreate)
|
||||
newDevice.deviceType = deviceFileType
|
||||
newDevice.deviceName = "smarter-devices/" + deviceToCreate
|
||||
newDevice.socketName = pluginapi.DevicePluginPath + "smarter-" + deviceToCreate + ".sock"
|
||||
newDevice.deviceName = "smarter-devices/" + deviceSafeName
|
||||
newDevice.socketName = pluginapi.DevicePluginPath + "smarter-" + deviceSafeName + ".sock"
|
||||
newDevice.deviceFile = "/dev/" + deviceToCreate
|
||||
newDevice.numDevices = deviceToTest.NumMaxDevices
|
||||
listDevicesAvailable = append(listDevicesAvailable, newDevice)
|
||||
|
@ -15,7 +15,7 @@ spec:
|
||||
nodeName: smarter-jetson-xavier-4bcc2584
|
||||
containers:
|
||||
- name: smarter-device-manager
|
||||
image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.1.2
|
||||
image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.20.11
|
||||
imagePullPolicy: IfNotPresent
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
|
@ -15,7 +15,7 @@ spec:
|
||||
nodeName: <replace with node to run>
|
||||
containers:
|
||||
- name: smarter-device-manager
|
||||
image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.1.2
|
||||
image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.20.11
|
||||
imagePullPolicy: IfNotPresent
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
|
@ -15,7 +15,7 @@ spec:
|
||||
nodeName: <replace with node to run>
|
||||
containers:
|
||||
- name: smarter-device-manager
|
||||
image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.1.2
|
||||
image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.20.11
|
||||
imagePullPolicy: IfNotPresent
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
|
@ -34,7 +34,7 @@ spec:
|
||||
dnsPolicy: ClusterFirstWithHostNet
|
||||
containers:
|
||||
- name: smarter-device-manager
|
||||
image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.1.2
|
||||
image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.20.11
|
||||
imagePullPolicy: IfNotPresent
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
|
@ -34,7 +34,7 @@ spec:
|
||||
dnsPolicy: ClusterFirstWithHostNet
|
||||
containers:
|
||||
- name: smarter-device-manager
|
||||
image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.1.2
|
||||
image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.20.11
|
||||
imagePullPolicy: IfNotPresent
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
|
@ -34,7 +34,7 @@ spec:
|
||||
dnsPolicy: ClusterFirstWithHostNet
|
||||
containers:
|
||||
- name: smarter-device-manager
|
||||
image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.1.2
|
||||
image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.20.11
|
||||
imagePullPolicy: IfNotPresent
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
|
@ -34,7 +34,7 @@ spec:
|
||||
dnsPolicy: ClusterFirstWithHostNet
|
||||
containers:
|
||||
- name: smarter-device-manager
|
||||
image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.1.2
|
||||
image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.20.11
|
||||
imagePullPolicy: IfNotPresent
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
|
@ -34,7 +34,7 @@ spec:
|
||||
dnsPolicy: ClusterFirstWithHostNet
|
||||
containers:
|
||||
- name: smarter-device-manager
|
||||
image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.1.2
|
||||
image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.20.11
|
||||
imagePullPolicy: IfNotPresent
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
|
@ -34,7 +34,7 @@ spec:
|
||||
dnsPolicy: ClusterFirstWithHostNet
|
||||
containers:
|
||||
- name: smarter-device-manager
|
||||
image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.1.2
|
||||
image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.20.11
|
||||
imagePullPolicy: IfNotPresent
|
||||
securityContext:
|
||||
allowPrivilegeEscalation: false
|
||||
|
Loading…
x
Reference in New Issue
Block a user