-
Notifications
You must be signed in to change notification settings - Fork 8
/
workqueue.go
58 lines (44 loc) · 989 Bytes
/
workqueue.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
package config
import (
"fmt"
"time"
"github.com/briandowns/spinner"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
)
var s *spinner.Spinner
func init() {
s = spinner.New(spinner.CharSets[9], 100*time.Millisecond)
}
type ContextResult struct {
ID string
Context *clientcmdapi.Context
Message string
Valid bool
}
func (m *Manager) ValidateAndAddToWorkqueue(id string, context *clientcmdapi.Context) {
valid, message := m.Validate(context)
m.workqueue <- ContextResult{id, context, message, valid}
m.contextedValidated++
if m.contextedValidated == m.totalContexts {
close(m.workqueue)
}
}
func (m *Manager) runWorkqueue() {
for m.processNextWorkItem() {
}
return
}
func (m *Manager) processNextWorkItem() bool {
s.Start()
for n := range m.workqueue {
s.Stop()
fmt.Printf("\nTesting context's '%s' cluster...\n", n.ID)
fmt.Println(n.Message)
if !n.Valid {
m.RemoveContext(n.ID, n.Context)
}
s.Start()
}
s.Stop()
return false
}