Compare commits

..

No commits in common. "master" and "v1.1.2" have entirely different histories.

17 changed files with 39 additions and 105 deletions

View File

@ -1,16 +0,0 @@
# Contributing to SMARTER
SMARTER is an open-source, software platform for the Edge. Contributions are an important part of the platform, and our goal is to make it as simple as possible to become a contributor.
# Project license, and developer certificate of origin
The SMARTER codebase is licensed under the Apache 2.0 open source license, individual components may have their own licenses.
Please see the LICENSE file in the SMARTER documentation repository for the full text of this license, or the LICENSE file
in respective repositories. New contributions are expected to be lisensed under the Apache 2.0 license or something compatible
with that license.
Please note that we expect contributors to the project to self-certify that they are authorized to contribute code
using the Linux Foundation's Developer Certificate of Origin. See http://developercertificate.org for more details.
Contributors sign-off that they adhere to these requirements by adding a Signed-off-by line to commit messages.
Pull requests for contributions without a signed-off-by line will not be accepted.

4
CONTRIBUTIONS Normal file
View File

@ -0,0 +1,4 @@
We sincerely appreciate your interest of contributing to this project but for now
we are not able to accept contributions. We expect to change this policy soon and
provide a contribution procedure. We suggest that the project be maintained on a
different branch until the contribution policy is changed.

View File

@ -5,18 +5,19 @@ RUN apk update && apk upgrade && apk add tar ca-certificates build-base
ENV GOPATH /go ENV GOPATH /go
RUN go version RUN go version
WORKDIR /arm.com/smarter-device-management WORKDIR /go/src/smarter-device-management
COPY . . COPY . .
RUN echo $PATH;export CGO_LDFLAGS_ALLOW='-Wl,--unresolved-symbols=ignore-in-object-files' && \ 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 install -ldflags="-s -w" -v smarter-device-management
CGO_ENABLED=0 go build -ldflags='-s -w -extldflags="-static"' .
FROM scratch FROM alpine
RUN apk update && apk upgrade
WORKDIR /root WORKDIR /root
COPY conf.yaml /root/config/conf.yaml COPY conf.yaml /root/config/conf.yaml
COPY --from=build /arm.com/smarter-device-management/smarter-device-management /usr/bin/smarter-device-management COPY --from=build /go/bin/smarter-device-management /usr/bin/smarter-device-management
CMD ["/usr/bin/smarter-device-management","-logtostderr=true","-v=0"] CMD ["smarter-device-management","-logtostderr=true","-v=0"]

View File

@ -17,10 +17,6 @@ The smarter-device-manager starts by reading a YAML configuration file. This con
nummaxdevices: 10 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 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. The node will show the devices it recognizes as resources in the node object in Kubernetes. The example below shows a raspberry PI.

View File

@ -4,7 +4,7 @@ package main
import ( import (
"github.com/golang/glog" "github.com/golang/glog"
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1" pluginapi "k8s.io/kubernetes/pkg/kubelet/apis/deviceplugin/v1beta1"
) )
func check(err error) { func check(err error) {

59
main.go
View File

@ -14,7 +14,7 @@ import (
"github.com/fsnotify/fsnotify" "github.com/fsnotify/fsnotify"
"github.com/golang/glog" "github.com/golang/glog"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1" pluginapi "k8s.io/kubernetes/pkg/kubelet/apis/deviceplugin/v1beta1"
) )
var confFileName string var confFileName string
@ -55,60 +55,18 @@ func init() {
flag.Parse() flag.Parse()
} }
func readDevDirectory(dirToList string, allowedRecursions uint8) (files []string, err error) { func readDevDirectory(dirToList string) (files []string, err error) {
var foundFiles []string
fType, err := os.Stat(dirToList)
if err != nil {
return nil, err
}
if !fType.IsDir() {
return nil, nil
}
f, err := os.Open(dirToList) f, err := os.Open(dirToList)
if err != nil { if err != nil {
return nil, err return nil, err
} }
files, err = f.Readdirnames(-1) files, err = f.Readdirnames(-1)
if err != nil {
f.Close() f.Close()
if err != nil {
return nil, err 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 return files, 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) { func findDevicesPattern(listDevices []string, pattern string) ([]string,error) {
@ -144,13 +102,13 @@ func main() {
} }
glog.V(0).Info("Reading existing devices on /dev") glog.V(0).Info("Reading existing devices on /dev")
ExistingDevices, err := readDevDirectory("/dev",10) ExistingDevices, err := readDevDirectory("/dev")
if err != nil { if err != nil {
glog.Errorf(err.Error()) glog.Errorf(err.Error())
os.Exit(1) os.Exit(1)
} }
ExistingDevicesSys, err := readDevDirectory("/sys/devices",0) ExistingDevicesSys, err := readDevDirectory("/sys/devices")
if err != nil { if err != nil {
glog.Errorf(err.Error()) glog.Errorf(err.Error())
os.Exit(1) os.Exit(1)
@ -193,10 +151,9 @@ func main() {
if len(foundDevices) > 0 { if len(foundDevices) > 0 {
for _, deviceToCreate := range foundDevices { for _, deviceToCreate := range foundDevices {
var newDevice DeviceInstance var newDevice DeviceInstance
deviceSafeName := sanitizeName(deviceToCreate)
newDevice.deviceType = deviceFileType newDevice.deviceType = deviceFileType
newDevice.deviceName = "smarter-devices/" + deviceSafeName newDevice.deviceName = "smarter-devices/" + deviceToCreate
newDevice.socketName = pluginapi.DevicePluginPath + "smarter-" + deviceSafeName + ".sock" newDevice.socketName = pluginapi.DevicePluginPath + "smarter-" + deviceToCreate + ".sock"
newDevice.deviceFile = "/dev/" + deviceToCreate newDevice.deviceFile = "/dev/" + deviceToCreate
newDevice.numDevices = deviceToTest.NumMaxDevices newDevice.numDevices = deviceToTest.NumMaxDevices
listDevicesAvailable = append(listDevicesAvailable, newDevice) listDevicesAvailable = append(listDevicesAvailable, newDevice)

View File

@ -13,7 +13,7 @@ import (
"github.com/golang/glog" "github.com/golang/glog"
"golang.org/x/net/context" "golang.org/x/net/context"
"google.golang.org/grpc" "google.golang.org/grpc"
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1" pluginapi "k8s.io/kubernetes/pkg/kubelet/apis/deviceplugin/v1beta1"
) )
var passDeviceSpecs = flag.Bool("pass-device-specs", false, "pass the list of DeviceSpecs to the kubelet on Allocate()") var passDeviceSpecs = flag.Bool("pass-device-specs", false, "pass the list of DeviceSpecs to the kubelet on Allocate()")
@ -182,10 +182,6 @@ func (m *NvidiaDevicePlugin) PreStartContainer(context.Context, *pluginapi.PreSt
return &pluginapi.PreStartContainerResponse{}, nil return &pluginapi.PreStartContainerResponse{}, nil
} }
func (m *NvidiaDevicePlugin) GetPreferredAllocation(context.Context, *pluginapi.PreferredAllocationRequest) (*pluginapi.PreferredAllocationResponse, error) {
return &pluginapi.PreferredAllocationResponse{}, nil
}
func (m *NvidiaDevicePlugin) cleanup() error { func (m *NvidiaDevicePlugin) cleanup() error {
if err := os.Remove(m.socket); err != nil && !os.IsNotExist(err) { if err := os.Remove(m.socket); err != nil && !os.IsNotExist(err) {
return err return err

View File

@ -13,7 +13,7 @@ import (
"github.com/golang/glog" "github.com/golang/glog"
"golang.org/x/net/context" "golang.org/x/net/context"
"google.golang.org/grpc" "google.golang.org/grpc"
pluginapi "k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1" pluginapi "k8s.io/kubernetes/pkg/kubelet/apis/deviceplugin/v1beta1"
) )
const ( const (
@ -180,10 +180,6 @@ func (m *SmarterDevicePlugin) PreStartContainer(context.Context, *pluginapi.PreS
return &pluginapi.PreStartContainerResponse{}, nil return &pluginapi.PreStartContainerResponse{}, nil
} }
func (m *SmarterDevicePlugin) GetPreferredAllocation(context.Context, *pluginapi.PreferredAllocationRequest) (*pluginapi.PreferredAllocationResponse, error) {
return &pluginapi.PreferredAllocationResponse{}, nil
}
func (m *SmarterDevicePlugin) cleanup() error { func (m *SmarterDevicePlugin) cleanup() error {
glog.V(0).Info("Removing file ",m.socket) glog.V(0).Info("Removing file ",m.socket)
if err := os.Remove(m.socket); err != nil && !os.IsNotExist(err) { if err := os.Remove(m.socket); err != nil && !os.IsNotExist(err) {

View File

@ -15,7 +15,7 @@ spec:
nodeName: smarter-jetson-xavier-4bcc2584 nodeName: smarter-jetson-xavier-4bcc2584
containers: containers:
- name: smarter-device-manager - name: smarter-device-manager
image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.20.11 image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.1.2
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
securityContext: securityContext:
allowPrivilegeEscalation: false allowPrivilegeEscalation: false

View File

@ -15,7 +15,7 @@ spec:
nodeName: <replace with node to run> nodeName: <replace with node to run>
containers: containers:
- name: smarter-device-manager - name: smarter-device-manager
image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.20.11 image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.1.2
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
securityContext: securityContext:
allowPrivilegeEscalation: false allowPrivilegeEscalation: false

View File

@ -15,7 +15,7 @@ spec:
nodeName: <replace with node to run> nodeName: <replace with node to run>
containers: containers:
- name: smarter-device-manager - name: smarter-device-manager
image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.20.11 image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.1.2
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
securityContext: securityContext:
allowPrivilegeEscalation: false allowPrivilegeEscalation: false

View File

@ -34,7 +34,7 @@ spec:
dnsPolicy: ClusterFirstWithHostNet dnsPolicy: ClusterFirstWithHostNet
containers: containers:
- name: smarter-device-manager - name: smarter-device-manager
image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.20.11 image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.1.2
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
securityContext: securityContext:
allowPrivilegeEscalation: false allowPrivilegeEscalation: false

View File

@ -34,7 +34,7 @@ spec:
dnsPolicy: ClusterFirstWithHostNet dnsPolicy: ClusterFirstWithHostNet
containers: containers:
- name: smarter-device-manager - name: smarter-device-manager
image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.20.11 image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.1.2
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
securityContext: securityContext:
allowPrivilegeEscalation: false allowPrivilegeEscalation: false

View File

@ -34,7 +34,7 @@ spec:
dnsPolicy: ClusterFirstWithHostNet dnsPolicy: ClusterFirstWithHostNet
containers: containers:
- name: smarter-device-manager - name: smarter-device-manager
image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.20.11 image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.1.2
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
securityContext: securityContext:
allowPrivilegeEscalation: false allowPrivilegeEscalation: false

View File

@ -34,7 +34,7 @@ spec:
dnsPolicy: ClusterFirstWithHostNet dnsPolicy: ClusterFirstWithHostNet
containers: containers:
- name: smarter-device-manager - name: smarter-device-manager
image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.20.11 image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.1.2
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
securityContext: securityContext:
allowPrivilegeEscalation: false allowPrivilegeEscalation: false

View File

@ -34,7 +34,7 @@ spec:
dnsPolicy: ClusterFirstWithHostNet dnsPolicy: ClusterFirstWithHostNet
containers: containers:
- name: smarter-device-manager - name: smarter-device-manager
image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.20.11 image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.1.2
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
securityContext: securityContext:
allowPrivilegeEscalation: false allowPrivilegeEscalation: false

View File

@ -34,7 +34,7 @@ spec:
dnsPolicy: ClusterFirstWithHostNet dnsPolicy: ClusterFirstWithHostNet
containers: containers:
- name: smarter-device-manager - name: smarter-device-manager
image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.20.11 image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.1.2
imagePullPolicy: IfNotPresent imagePullPolicy: IfNotPresent
securityContext: securityContext:
allowPrivilegeEscalation: false allowPrivilegeEscalation: false