File tree Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Expand file tree Collapse file tree 1 file changed +20
-1
lines changed Original file line number Diff line number Diff line change 1
1
package k8s
2
2
3
- import v1 "k8s.io/api/core/v1"
3
+ import (
4
+ "sync"
5
+
6
+ v1 "k8s.io/api/core/v1"
7
+ )
4
8
5
9
// NodeInfo provides an abstraction on top of node to pods mappings
6
10
// replaces scheduler cache.NodeInfo that was removed from public in an older version of kubernetes
7
11
// Maintains the same interface
12
+ // NodeInfo this thread safe
8
13
type NodeInfo struct {
14
+ lock sync.RWMutex
15
+
9
16
node * v1.Node
10
17
pods []* v1.Pod
11
18
}
@@ -17,20 +24,32 @@ func NewNodeInfo() *NodeInfo {
17
24
18
25
// AddPod adds a pod to the list of pods for this node
19
26
func (i * NodeInfo ) AddPod (pod * v1.Pod ) {
27
+ i .lock .Lock ()
28
+ defer i .lock .Unlock ()
29
+
20
30
i .pods = append (i .pods , pod )
21
31
}
22
32
23
33
// Pods returns the list of pods for this node
24
34
func (i * NodeInfo ) Pods () []* v1.Pod {
35
+ i .lock .RLock ()
36
+ defer i .lock .RUnlock ()
37
+
25
38
return i .pods
26
39
}
27
40
28
41
// SetNode sets the current node that the pods belong to
29
42
func (i * NodeInfo ) SetNode (node * v1.Node ) {
43
+ i .lock .Lock ()
44
+ defer i .lock .Unlock ()
45
+
30
46
i .node = node
31
47
}
32
48
33
49
// Node returns the current node for these pods
34
50
func (i * NodeInfo ) Node () * v1.Node {
51
+ i .lock .RLock ()
52
+ defer i .lock .RUnlock ()
53
+
35
54
return i .node
36
55
}
You can’t perform that action at this time.
0 commit comments