in xds/filesystem-control-panel/server/main.go [61:129]
func main() {
flag.Parse()
// Create a snaphost
snaphost := cache.NewSnapshotCache(false, cache.IDHash{}, l)
go func() {
// Create the config that we'll serve to Envoy
config := GenerateSnapshotPixiuFromFile()
if err := config.Consistent(); err != nil {
l.Errorf("config inconsistency: %+v\n%+v", config, err)
os.Exit(1)
}
l.Debugf("will serve config %+v", config)
// Add the config to the snaphost
if err := snaphost.SetSnapshot(context.Background(), nodeID, config); err != nil {
l.Errorf("config error %q for %+v", err, config)
os.Exit(1)
}
go func() {
watcher, err := fsnotify.NewWatcher()
if err != nil {
log.Fatal(err)
}
defer watcher.Close()
done := make(chan bool)
go func() {
for {
select {
case event, ok := <-watcher.Events:
if !ok {
return
}
if event.Op == fsnotify.Write {
log.Println("event:", event)
log.Println("modified file:", event.Name)
conf := GenerateSnapshotPixiuFromFile()
// Add the config to the snaphost
if err := snaphost.SetSnapshot(context.Background(), nodeID, conf); err != nil {
l.Errorf("config error %q for %+v", err, config)
os.Exit(1)
}
}
case err, ok := <-watcher.Errors:
if !ok {
return
}
log.Println("error:", err)
}
}
}()
err = watcher.Add("../pixiu")
if err != nil {
log.Fatal(err)
}
<-done
}()
}()
// Run the xDS server
ctx := context.Background()
cb := &test.Callbacks{Debug: l.Debug}
srv := server.NewServer(ctx, snaphost, cb)
RunServer(ctx, srv, port)
}