-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
host.go
73 lines (58 loc) · 2.01 KB
/
host.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
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium
package endpointmanager
import (
v1 "k8s.io/api/core/v1"
"github.com/cilium/cilium/pkg/endpoint"
"github.com/cilium/cilium/pkg/labels"
"github.com/cilium/cilium/pkg/lock"
"github.com/cilium/cilium/pkg/node"
)
// GetHostEndpoint returns the host endpoint.
func (mgr *EndpointManager) GetHostEndpoint() *endpoint.Endpoint {
mgr.mutex.RLock()
defer mgr.mutex.RUnlock()
for _, ep := range mgr.endpoints {
if ep.IsHost() {
return ep
}
}
return nil
}
// HostEndpointExists returns true if the host endpoint exists.
func (mgr *EndpointManager) HostEndpointExists() bool {
return mgr.GetHostEndpoint() != nil
}
// OnAddNode implements the EndpointManager's logic for reacting to new nodes
// from K8s. It is currently not implemented as the EndpointManager has not
// need for it. This adheres to the subscriber.NodeHandler interface.
func (mgr *EndpointManager) OnAddNode(node *v1.Node,
swg *lock.StoppableWaitGroup) error {
return nil
}
// OnUpdateNode implements the EndpointManager's logic for reacting to updated
// nodes in K8s. It is currently not implemented as the EndpointManager has not
// need for it. This adheres to the subscriber.NodeHandler interface.
func (mgr *EndpointManager) OnUpdateNode(oldNode, newNode *v1.Node,
swg *lock.StoppableWaitGroup) error {
oldNodeLabels := oldNode.GetLabels()
newNodeLabels := newNode.GetLabels()
nodeEP := mgr.GetHostEndpoint()
if nodeEP == nil {
log.Error("Host endpoint not found")
return nil
}
node.SetLabels(newNodeLabels)
err := nodeEP.UpdateLabelsFrom(oldNodeLabels, newNodeLabels, labels.LabelSourceK8s)
if err != nil {
return err
}
return nil
}
// OnDeleteNode implements the EndpointManager's logic for reacting to node
// deletions from K8s. It is currently not implemented as the EndpointManager
// has not need for it. This adheres to the subscriber.NodeHandler interface.
func (mgr *EndpointManager) OnDeleteNode(node *v1.Node,
swg *lock.StoppableWaitGroup) error {
return nil
}