This repository has been archived by the owner on Jul 16, 2020. It is now read-only.
/
overseer.go
772 lines (659 loc) · 18.6 KB
/
overseer.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
/*
// Copyright (c) 2016 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
*/
package main
import (
"container/list"
"fmt"
"os"
"path/filepath"
"sync"
"time"
"gopkg.in/yaml.v2"
"github.com/ciao-project/ciao/deviceinfo"
"github.com/ciao-project/ciao/payloads"
"github.com/ciao-project/ciao/ssntp"
"github.com/golang/glog"
)
type ovsAddResult struct {
cmdCh chan<- interface{}
errorCode payloads.StartFailureReason // Empty string indicates no error
}
type ovsAddCmd struct {
instance string
cfg *vmConfig
targetCh chan<- ovsAddResult
}
type ovsGetResult struct {
cmdCh chan<- interface{}
running ovsRunningState
}
type ovsGetCmd struct {
instance string
targetCh chan<- ovsGetResult
}
type ovsInstance struct {
instance string
cmdCh chan<- interface{}
}
type ovsGetAllResult struct {
instances []ovsInstance
}
type ovsGetAllCmd struct {
targetCh chan<- ovsGetAllResult
}
type ovsRemoveCmd struct {
instance string
errCh chan<- error
}
type ovsStateChange struct {
instance string
state ovsRunningState
}
type ovsStatsUpdateCmd struct {
instance string
memoryUsageMB int
diskUsageMB int
CPUUsage int
volumes []string
}
type ovsMaintenanceCmd struct {
doneCh chan struct{}
}
type ovsRestoreCmd struct {
doneCh chan struct{}
}
type ovsTraceFrame struct {
frame *ssntp.Frame
}
type ovsStatusCmd struct{}
type ovsStatsStatusCmd struct{}
type ovsRunningState int
type deviceInfo interface {
GetLoadAvg() int
GetFSInfo(path string) (total, available int)
GetOnlineCPUs() int
GetMemoryInfo() (total, available int)
}
type realDeviceInfo struct{}
func (realDeviceInfo) GetLoadAvg() int {
return deviceinfo.GetLoadAvg()
}
func (realDeviceInfo) GetFSInfo(path string) (total, available int) {
return deviceinfo.GetFSInfo(path)
}
func (realDeviceInfo) GetOnlineCPUs() int {
return deviceinfo.GetOnlineCPUs()
}
func (realDeviceInfo) GetMemoryInfo() (total, available int) {
return deviceinfo.GetMemoryInfo()
}
const (
ovsPending ovsRunningState = iota
ovsRunning
ovsStopped
)
const (
diskSpaceHWM = 80 * 1000
memHWM = 1 * 1000
diskSpaceLWM = 40 * 1000
memLWM = 512
)
type ovsInstanceState struct {
cmdCh chan<- interface{}
running ovsRunningState
memoryUsageMB int
diskUsageMB int
CPUUsage int
maxDiskUsageMB int
maxVCPUs int
maxMemoryMB int
sshIP string
sshPort int
volumes []string
}
type overseer struct {
instancesDir string
instances map[string]*ovsInstanceState
ovsCh chan interface{}
ovsInstanceCh chan interface{}
childDoneCh chan struct{}
parentWg *sync.WaitGroup
childWg *sync.WaitGroup
ac *agentClient
vcpusAllocated int
diskSpaceAllocated int
memoryAllocated int
diskSpaceAvailable int
memoryAvailable int
traceFrames *list.List
statsInterval time.Duration
di deviceInfo
maintenance bool
}
type cnStats struct {
totalMemMB int
availableMemMB int
totalDiskMB int
availableDiskMB int
load int
cpusOnline int
}
func (ovs *overseer) roomAvailable(cfg *vmConfig) payloads.StartFailureReason {
if ovs.maintenance {
return payloads.NodeInMaintenance
}
if len(ovs.instances) >= maxInstances {
glog.Warningf("We're FULL. Too many instances %d", len(ovs.instances))
return payloads.FullComputeNode
}
diskSpaceAvailable := ovs.diskSpaceAvailable - cfg.Disk
memoryAvailable := ovs.memoryAvailable - cfg.Mem
glog.Infof("disk Avail %d MemAvail %d", diskSpaceAvailable, memoryAvailable)
if diskSpaceAvailable < diskSpaceLWM {
if diskLimit == true {
return payloads.FullComputeNode
}
}
if memoryAvailable < memLWM {
if memLimit == true {
return payloads.FullComputeNode
}
}
return ""
}
func (ovs *overseer) updateAvailableResources(cns *cnStats) {
diskSpaceConsumed := 0
memConsumed := 0
for _, target := range ovs.instances {
if target.diskUsageMB != -1 {
diskSpaceConsumed += target.diskUsageMB
}
if target.memoryUsageMB != -1 {
if target.memoryUsageMB < target.maxMemoryMB {
memConsumed += target.memoryUsageMB
} else {
memConsumed += target.maxMemoryMB
}
}
}
ovs.diskSpaceAvailable = (cns.availableDiskMB + diskSpaceConsumed) -
ovs.diskSpaceAllocated
ovs.memoryAvailable = (cns.availableMemMB + memConsumed) -
ovs.memoryAllocated
if glog.V(1) {
glog.Infof("Memory Available: %d Disk space Available %d",
ovs.memoryAvailable, ovs.diskSpaceAvailable)
}
}
func (ovs *overseer) computeStatus() ssntp.Status {
if ovs.maintenance {
return ssntp.MAINTENANCE
}
if len(ovs.instances) >= maxInstances {
return ssntp.FULL
}
if ovs.diskSpaceAvailable < diskSpaceHWM {
if diskLimit == true {
return ssntp.FULL
}
}
if ovs.memoryAvailable < memHWM {
if memLimit == true {
return ssntp.FULL
}
}
return ssntp.READY
}
func (ovs *overseer) sendReadyStatusCommand(cns *cnStats) {
var s payloads.Ready
s.Init()
s.NodeUUID = ovs.ac.conn.UUID()
s.MemTotalMB, s.MemAvailableMB = cns.totalMemMB, cns.availableMemMB
s.Load = cns.load
s.CpusOnline = cns.cpusOnline
s.DiskTotalMB, s.DiskAvailableMB = cns.totalDiskMB, cns.availableDiskMB
s.Networks = make([]payloads.NetworkStat, len(nicInfo))
for i, nic := range nicInfo {
s.Networks[i] = *nic
}
s.NodeHostName = hostname
payload, err := yaml.Marshal(&s)
if err != nil {
glog.Errorf("Unable to Marshall status payload %v", err)
return
}
_, err = ovs.ac.conn.SendStatus(ssntp.READY, payload)
if err != nil {
glog.Errorf("Failed to send READY status command %v", err)
}
}
func (ovs *overseer) sendStatusCommand(cns *cnStats, status ssntp.Status) {
switch status {
case ssntp.READY:
ovs.sendReadyStatusCommand(cns)
case ssntp.FULL:
fallthrough
case ssntp.MAINTENANCE:
fallthrough
case ssntp.OFFLINE:
_, err := ovs.ac.conn.SendStatus(status, nil)
if err != nil {
glog.Errorf("Failed to send %s status command %v", status, err)
}
default:
glog.Errorf("Unsupported status command: %s", status)
}
}
func (ovs *overseer) sendStats(cns *cnStats, status ssntp.Status) {
var s payloads.Stat
s.Init()
s.NodeUUID = ovs.ac.conn.UUID()
s.Status = status.String()
s.MemTotalMB, s.MemAvailableMB = cns.totalMemMB, cns.availableMemMB
s.Load = cns.load
s.CpusOnline = cns.cpusOnline
s.DiskTotalMB, s.DiskAvailableMB = cns.totalDiskMB, cns.availableDiskMB
s.NodeHostName = hostname // global from network.go
s.Networks = make([]payloads.NetworkStat, len(nicInfo))
for i, nic := range nicInfo {
s.Networks[i] = *nic
}
s.Instances = make([]payloads.InstanceStat, len(ovs.instances))
i := 0
for uuid, state := range ovs.instances {
s.Instances[i].InstanceUUID = uuid
if state.running == ovsRunning {
s.Instances[i].State = payloads.Running
} else if state.running == ovsStopped {
s.Instances[i].State = payloads.Exited
} else {
s.Instances[i].State = payloads.Pending
}
s.Instances[i].MemoryUsageMB = state.memoryUsageMB
s.Instances[i].DiskUsageMB = state.diskUsageMB
s.Instances[i].CPUUsage = state.CPUUsage
s.Instances[i].SSHIP = state.sshIP
s.Instances[i].SSHPort = state.sshPort
s.Instances[i].Volumes = state.volumes
i++
}
payload, err := yaml.Marshal(&s)
if err != nil {
glog.Errorf("Unable to Marshall STATS %v", err)
return
}
_, err = ovs.ac.conn.SendCommand(ssntp.STATS, payload)
if err != nil {
glog.Errorf("Failed to send stats command %v", err)
return
}
}
func (ovs *overseer) sendTraceReport() {
var s payloads.Trace
if ovs.traceFrames.Len() == 0 {
return
}
for e := ovs.traceFrames.Front(); e != nil; e = e.Next() {
f := e.Value.(*ssntp.Frame)
frameTrace, err := f.DumpTrace()
if err != nil {
glog.Errorf("Unable to dump traced frame %v", err)
continue
}
s.Frames = append(s.Frames, *frameTrace)
}
ovs.traceFrames = list.New()
payload, err := yaml.Marshal(&s)
if err != nil {
glog.Errorf("Unable to Marshall TraceReport %v", err)
return
}
_, err = ovs.ac.conn.SendEvent(ssntp.TraceReport, payload)
if err != nil {
glog.Errorf("Failed to send TraceReport event %v", err)
return
}
}
func getStats(instancesDir string) *cnStats {
var s cnStats
s.totalMemMB, s.availableMemMB = deviceinfo.GetMemoryInfo()
s.load = deviceinfo.GetLoadAvg()
s.cpusOnline = deviceinfo.GetOnlineCPUs()
s.totalDiskMB, s.availableDiskMB = deviceinfo.GetFSInfo(instancesDir)
return &s
}
func (ovs *overseer) processGetCommand(cmd *ovsGetCmd) {
glog.Infof("Overseer: looking for instance %s", cmd.instance)
var insState ovsGetResult
target := ovs.instances[cmd.instance]
if target != nil {
insState.cmdCh = target.cmdCh
insState.running = target.running
}
cmd.targetCh <- insState
}
func (ovs *overseer) processGetAllCommand(cmd *ovsGetAllCmd) {
glog.Infof("Overseer: Enumerating instances")
var res ovsGetAllResult
for k, v := range ovs.instances {
glog.Infof("Overseer: Found %s", k)
res.instances = append(res.instances,
ovsInstance{
instance: k,
cmdCh: v.cmdCh,
})
}
cmd.targetCh <- res
}
func (ovs *overseer) processAddCommand(cmd *ovsAddCmd) {
var targetCh chan<- interface{}
var errCode payloads.StartFailureReason
glog.Infof("Overseer: adding %s", cmd.instance)
target := ovs.instances[cmd.instance]
cfg := cmd.cfg
if target != nil {
targetCh = target.cmdCh
} else if errCode = ovs.roomAvailable(cfg); errCode == "" {
ovs.vcpusAllocated += cfg.Cpus
ovs.diskSpaceAllocated += cfg.Disk
ovs.memoryAllocated += cfg.Mem
targetCh = startInstance(cmd.instance, cfg, ovs.childWg, ovs.childDoneCh,
ovs.ac, ovs.ovsInstanceCh)
ovs.instances[cmd.instance] = &ovsInstanceState{
cmdCh: targetCh,
running: ovsPending,
diskUsageMB: -1,
CPUUsage: -1,
memoryUsageMB: -1,
maxDiskUsageMB: cfg.Disk,
maxVCPUs: cfg.Cpus,
maxMemoryMB: cfg.Mem,
sshIP: cfg.ConcIP,
sshPort: cfg.SSHPort,
}
}
cmd.targetCh <- ovsAddResult{targetCh, errCode}
}
func (ovs *overseer) processRemoveCommand(cmd *ovsRemoveCmd) {
glog.Infof("Overseer: removing %s", cmd.instance)
target := ovs.instances[cmd.instance]
if target == nil {
cmd.errCh <- fmt.Errorf("Instance does not exist")
return
}
ovs.diskSpaceAllocated -= target.maxDiskUsageMB
if ovs.diskSpaceAllocated < 0 {
ovs.diskSpaceAllocated = 0
}
ovs.vcpusAllocated -= target.maxVCPUs
if ovs.vcpusAllocated < 0 {
ovs.vcpusAllocated = 0
}
ovs.memoryAllocated -= target.maxMemoryMB
if ovs.memoryAllocated < 0 {
ovs.memoryAllocated = 0
}
delete(ovs.instances, cmd.instance)
cmd.errCh <- nil
}
func (ovs *overseer) processStatusCommand(cmd *ovsStatusCmd) {
glog.Info("Overseer: Received Status Command")
if !ovs.ac.conn.isConnected() {
return
}
cns := getStats(ovs.instancesDir)
ovs.updateAvailableResources(cns)
ovs.sendStatusCommand(cns, ovs.computeStatus())
}
func (ovs *overseer) processStatsStatusCommand(cmd *ovsStatsStatusCmd) {
glog.Info("Overseer: Received StatsStatus Command")
if !ovs.ac.conn.isConnected() {
return
}
cns := getStats(ovs.instancesDir)
ovs.updateAvailableResources(cns)
status := ovs.computeStatus()
ovs.sendStatusCommand(cns, status)
ovs.sendStats(cns, status)
}
func (ovs *overseer) processStateChangeCommand(cmd *ovsStateChange) {
glog.Infof("Overseer: Received State Change %v", *cmd)
target := ovs.instances[cmd.instance]
if target != nil {
target.running = cmd.state
}
}
func (ovs *overseer) processStatusUpdateCommand(cmd *ovsStatsUpdateCmd) {
if glog.V(1) {
glog.Infof("STATS Update for %s: Mem %d Disk %d Cpu %d",
cmd.instance, cmd.memoryUsageMB,
cmd.diskUsageMB, cmd.CPUUsage)
}
target := ovs.instances[cmd.instance]
if target != nil {
target.memoryUsageMB = cmd.memoryUsageMB
target.diskUsageMB = cmd.diskUsageMB
target.CPUUsage = cmd.CPUUsage
target.volumes = cmd.volumes
}
}
func (ovs *overseer) processTraceFrameCommand(cmd *ovsTraceFrame) {
cmd.frame.SetEndStamp()
ovs.traceFrames.PushBack(cmd.frame)
}
func (ovs *overseer) processMaintenanceCommand(cmd *ovsMaintenanceCmd) {
defer close(cmd.doneCh)
if ovs.maintenance {
glog.Warning("Node is already in maintenance mode")
return
}
glog.Info("Node entering maintenance mode")
ovs.maintenance = true
f, err := os.OpenFile(maintenanceFile, os.O_CREATE|os.O_RDWR, 0600)
if err != nil {
glog.Errorf("Unable to create maintenance file %s : %v",
maintenanceFile, err)
} else {
_ = f.Close()
}
}
func (ovs *overseer) processRestoreCommand(cmd *ovsRestoreCmd) {
defer close(cmd.doneCh)
if !ovs.maintenance {
glog.Warning("Node not in maintenance mode")
return
}
glog.Info("Restoring node")
ovs.maintenance = false
err := os.Remove(maintenanceFile)
if err != nil {
glog.Errorf("Unable to remove maintenance file %s : %v",
maintenanceFile, err)
}
}
func (ovs *overseer) processCommand(cmd interface{}) {
switch cmd := cmd.(type) {
case *ovsGetCmd:
ovs.processGetCommand(cmd)
case *ovsGetAllCmd:
ovs.processGetAllCommand(cmd)
case *ovsAddCmd:
ovs.processAddCommand(cmd)
case *ovsRemoveCmd:
ovs.processRemoveCommand(cmd)
case *ovsStatusCmd:
ovs.processStatusCommand(cmd)
case *ovsStatsStatusCmd:
ovs.processStatsStatusCommand(cmd)
case *ovsStateChange:
ovs.processStateChangeCommand(cmd)
case *ovsStatsUpdateCmd:
ovs.processStatusUpdateCommand(cmd)
case *ovsTraceFrame:
ovs.processTraceFrameCommand(cmd)
case *ovsMaintenanceCmd:
ovs.processMaintenanceCommand(cmd)
case *ovsRestoreCmd:
ovs.processRestoreCommand(cmd)
default:
panic("Unknown Overseer Command")
}
}
func (ovs *overseer) runOverseer() {
statsTimer := time.After(ovs.statsInterval)
DONE:
for {
select {
case cmd, ok := <-ovs.ovsCh:
if !ok {
break DONE
}
ovs.processCommand(cmd)
case cmd := <-ovs.ovsInstanceCh:
ovs.processCommand(cmd)
case <-statsTimer:
if !ovs.ac.conn.isConnected() {
statsTimer = time.After(ovs.statsInterval)
continue
}
cns := getStats(ovs.instancesDir)
ovs.updateAvailableResources(cns)
status := ovs.computeStatus()
ovs.sendStatusCommand(cns, status)
ovs.sendStats(cns, status)
ovs.sendTraceReport()
statsTimer = time.After(ovs.statsInterval)
if glog.V(1) {
glog.Infof("Consumed: Disk %d Mem %d CPUs %d",
ovs.diskSpaceAllocated, ovs.memoryAllocated, ovs.vcpusAllocated)
}
}
}
close(ovs.childDoneCh)
DRAIN:
// Here we have the problem that we have multiple go routines writing to the
// same channel. We cannot therefore use the closure of this channel as
// a signal that all writes are done. Instead we need to use waitgroups.
// But here's the catch. We need to keep reading on the ovsInstanceCh channel
// until the childWg indicates that all instances have exitted, otherwise some
// of them might block trying to write to ovsInstanceCh.
for {
select {
case <-ovs.ovsInstanceCh:
case <-func() chan struct{} {
ch := make(chan struct{})
go func() {
ovs.childWg.Wait()
close(ch)
}()
return ch
}():
break DRAIN
}
}
glog.Info("All instance go routines have exitted")
ovs.parentWg.Done()
glog.Info("Overseer exitting")
}
func startOverseerFull(instancesDir string, wg *sync.WaitGroup, ac *agentClient,
statsInterval time.Duration, di deviceInfo) chan<- interface{} {
instances := make(map[string]*ovsInstanceState)
ovsCh := make(chan interface{})
ovsInstanceCh := make(chan interface{})
toMonitor := make([]chan<- interface{}, 0, 1024)
childDoneCh := make(chan struct{})
childWg := new(sync.WaitGroup)
vcpusAllocated := 0
diskSpaceAllocated := 0
memoryAllocated := 0
_ = filepath.Walk(instancesDir, func(path string, info os.FileInfo, err error) error {
if path == instancesDir {
return nil
}
if !info.IsDir() {
return nil
}
glog.Infof("Reconnecting to existing instance %s", path)
instance := filepath.Base(path)
// BUG(markus): We should garbage collect corrupt instances
cfg, err := loadVMConfig(path)
if err != nil {
glog.Warning("Unable to load state of running instance %s: %v", instance, err)
return nil
}
vcpusAllocated += cfg.Cpus
diskSpaceAllocated += cfg.Disk
memoryAllocated += cfg.Mem
target := startInstance(instance, cfg, childWg, childDoneCh, ac, ovsInstanceCh)
instances[instance] = &ovsInstanceState{
cmdCh: target,
running: ovsPending,
diskUsageMB: -1,
CPUUsage: -1,
memoryUsageMB: -1,
maxDiskUsageMB: cfg.Disk,
maxVCPUs: cfg.Cpus,
maxMemoryMB: cfg.Mem,
sshIP: cfg.ConcIP,
sshPort: cfg.SSHPort,
}
toMonitor = append(toMonitor, target)
return filepath.SkipDir
})
_, err := os.Stat(maintenanceFile)
maintenance := err == nil
if maintenance {
glog.Info("Node is in MAINTENANCE mode")
}
ovs := &overseer{
instancesDir: instancesDir,
instances: instances,
ovsCh: ovsCh,
ovsInstanceCh: ovsInstanceCh,
parentWg: wg,
childWg: childWg,
childDoneCh: childDoneCh,
ac: ac,
vcpusAllocated: vcpusAllocated,
diskSpaceAllocated: diskSpaceAllocated,
memoryAllocated: memoryAllocated,
traceFrames: list.New(),
statsInterval: statsInterval,
di: di,
maintenance: maintenance,
}
ovs.parentWg.Add(1)
glog.Info("Starting Overseer")
glog.Infof("Allocated: Disk %d Mem %d CPUs %d",
diskSpaceAllocated, memoryAllocated, vcpusAllocated)
go ovs.runOverseer()
ovs = nil
instances = nil
// I know this looks weird but there is method here. After we launch the overseer go routine
// we can no longer access instances from this go routine otherwise we will have a data race.
// For this reason we make a copy of the instance command channels that can be safely used
// in this go routine. The monitor commands cannot be sent from the overseer as it is not
// allowed to send information to the instance go routines. Doing so would incur the risk of
// deadlock. So we copy. 'A little copying is better than a little dependency', and so forth.
for _, v := range toMonitor {
v <- &insMonitorCmd{}
}
return ovsCh
}
func startOverseer(wg *sync.WaitGroup, ac *agentClient) chan<- interface{} {
return startOverseerFull(instancesDir, wg, ac, time.Second*statsPeriod,
realDeviceInfo{})
}