forked from KAIST-NCL/Accelerator-K8S
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
74 lines (69 loc) · 1.78 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"os"
"syscall"
"github.com/fsnotify/fsnotify"
k8sPluginApi "k8s.io/kubernetes/pkg/kubelet/apis/deviceplugin/v1beta1"
"log"
)
func main(){
manager,err := initializeAccManager()
if err != nil {
log.Println("Cannot initialize manager")
os.Exit(1)
}
defer manager.Shutdown()
go manager.HealthCheck()
restart := true
var devicePlugins []*AccDevicePlugin
for {
//Restart all device plugin servers
if restart {
if devicePlugins != nil {
for _,dp := range devicePlugins{
dp.StopServer()
}
}
devicePlugins = initializeAccDevicePlugins(manager)
for _,dp := range devicePlugins{
if err := dp.Serve(); err != nil{
log.Println("Cannot serve device plugin servers")
}else{
restart = false
}
}
}
select {
case <-manager.restartChan:
log.Println("Restarting device plugins")
restart = true
// Accelerator health watch
case e := <-manager.healthWatcher.Events:
if (e.Name == USR_LIST_DEFAULT || e.Name == STAT_LIST_DEFAULT) && (e.Op&fsnotify.Create == fsnotify.Create || e.Op&fsnotify.Write == fsnotify.Write) {
log.Println("Restarting device plugins")
restart = true
}
// Device Plugin path (/var/lib/kubelet/device-plugins) watch
case e := <-manager.dpWatcher.Events:
if e.Name == k8sPluginApi.KubeletSocket && e.Op&fsnotify.Create == fsnotify.Create{
log.Println("Restarting device plugins")
restart = true
}
case e := <-manager.dpWatcher.Errors:
log.Println("Error watching file : "+e.Error())
os.Exit(1)
case s := <-manager.osWatcher :
switch s {
case syscall.SIGHUP:
log.Println("Restarting device plugins")
restart = true
default:
log.Println("Shutting down")
for _,dp := range devicePlugins{
dp.StopServer()
}
os.Exit(0)
}
}
}
}