Compare commits

...

9 Commits

Author SHA1 Message Date
Alexandre Peixoto Ferreira
fe5dca8f1c
Use v1.20.11 in YAML files
Signed-off-by: Alexandre Peixoto Ferreira <alexandref75@gmail.com>
2022-09-11 10:42:00 -05:00
Alexandre Peixoto Ferreira
07f4b88b53
Compile device-manager statically and use scratch base image
Signed-off-by: Alexandre Peixoto Ferreira <alexandref75@gmail.com>
2022-09-11 09:39:34 -05:00
Alexandre Peixoto Ferreira
d65b7208db
Fix characteres on filenames not allowed on resources v2
Signed-off-by: Alexandre Peixoto Ferreira <alexandref75@gmail.com>
2022-07-18 13:33:38 -05:00
Alexandre Peixoto Ferreira
fe9b26d283
Fix sanitizing filenames
Signed-off-by: Alexandre Peixoto Ferreira <alexandref75@gmail.com>
2022-07-18 12:45:02 -05:00
Alexandre Peixoto Ferreira
e20fb9b58f
Update version tusing an up-to-date alpine image
Signed-off-by: Alexandre Peixoto Ferreira <alexandref75@gmail.com>
2022-07-07 14:33:32 -05:00
Alexandre Ferreira
741d8edc23 Merge branch 'dev' into 'master'
Fix examples to tag 1.20.7

See merge request arm-research/smarter/smarter-device-manager!19
2021-05-18 21:18:07 +00:00
Alexandre Ferreira
261f70121a Fix examples to tag 1.20.7 2021-05-18 16:16:55 -05:00
Alexandre Ferreira
8a304aa5ee Merge branch 'dev' into 'master'
Fix recursion problem

See merge request arm-research/smarter/smarter-device-manager!18
2021-05-18 21:16:01 +00:00
Alexandre Ferreira
1421f564e5 Fix recursion problem 2021-05-18 16:06:16 -05:00
11 changed files with 37 additions and 22 deletions

View File

@ -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"]

33
main.go
View File

@ -55,7 +55,7 @@ func init() {
flag.Parse()
}
func readDevDirectory(dirToList string) (files []string, err error) {
func readDevDirectory(dirToList string, allowedRecursions uint8) (files []string, err error) {
var foundFiles []string
fType, err := os.Stat(dirToList)
@ -79,10 +79,12 @@ func readDevDirectory(dirToList string) (files []string, err error) {
f.Close()
for _, subDir := range files {
foundFiles = append(foundFiles, subDir)
filesDir, err := readDevDirectory(dirToList+"/"+subDir)
if err == nil {
for _, fileName := range filesDir {
foundFiles = append(foundFiles, subDir+"/"+fileName)
if allowedRecursions > 0 {
filesDir, err := readDevDirectory(dirToList+"/"+subDir,allowedRecursions-1)
if err == nil {
for _, fileName := range filesDir {
foundFiles = append(foundFiles, subDir+"/"+fileName)
}
}
}
}
@ -91,7 +93,22 @@ func readDevDirectory(dirToList string) (files []string, err error) {
}
func sanitizeName(path string) string {
return strings.Replace(path, "/", "_" ,-1)
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) {
@ -127,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)

View File

@ -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.20.6
image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.20.11
imagePullPolicy: IfNotPresent
securityContext:
allowPrivilegeEscalation: false

View File

@ -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.20.6
image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.20.11
imagePullPolicy: IfNotPresent
securityContext:
allowPrivilegeEscalation: false

View File

@ -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.20.6
image: registry.gitlab.com/arm-research/smarter/smarter-device-manager:v1.20.11
imagePullPolicy: IfNotPresent
securityContext:
allowPrivilegeEscalation: false

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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