forked from st3v/go-plugins
/
utils.go
67 lines (59 loc) · 1.08 KB
/
utils.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
package mock
import (
"github.com/micro/go-plugins/registry/kubernetes/client"
"github.com/micro/go-plugins/registry/kubernetes/client/watch"
)
type mockWatcher struct {
results chan watch.Event
stop chan bool
}
// Changes returns the results channel
func (w *mockWatcher) ResultChan() <-chan watch.Event {
return w.results
}
// Stop closes any channels
func (w *mockWatcher) Stop() {
select {
case <-w.stop:
return
default:
close(w.stop)
close(w.results)
}
}
func updateMetadata(a, b *client.Meta) {
if a == nil || b == nil {
return
}
if b.Labels != nil {
for lk, lv := range b.Labels {
labels := a.Labels
if lv == nil {
delete(labels, lk)
continue
}
labels[lk] = lv
}
}
if b.Annotations != nil {
for ak, av := range b.Annotations {
ann := a.Annotations
if av == nil {
delete(ann, ak)
continue
}
ann[ak] = av
}
}
}
func labelFilterMatch(a map[string]*string, b map[string]string) bool {
match := true
for lk, lv := range b {
ml, ok := a[lk]
if !ok || *ml != lv {
match = false
break
}
}
return match
}