-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
cell.go
90 lines (75 loc) · 2.81 KB
/
cell.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
// SPDX-License-Identifier: Apache-2.0
// Copyright Authors of Cilium
package manager
import (
"net"
"github.com/cilium/cilium/pkg/datapath/iptables"
datapath "github.com/cilium/cilium/pkg/datapath/types"
"github.com/cilium/cilium/pkg/hive/cell"
"github.com/cilium/cilium/pkg/ipcache"
"github.com/cilium/cilium/pkg/node/types"
"github.com/cilium/cilium/pkg/option"
"github.com/cilium/cilium/pkg/time"
)
// Cell provides the NodeManager, which manages information about Cilium nodes
// in the cluster and informs other modules of changes to node configuration.
var Cell = cell.Module(
"node-manager",
"Manages the collection of Cilium nodes",
cell.Provide(newAllNodeManager),
cell.ProvidePrivate(func(iptMgr *iptables.Manager) ipsetManager {
return iptMgr
}),
cell.Metric(NewNodeMetrics),
)
// Notifier is the interface the wraps Subscribe and Unsubscribe. An
// implementation of this interface notifies subscribers of nodes being added,
// updated or deleted.
type Notifier interface {
// Subscribe adds the given NodeHandler to the list of subscribers that are
// notified of node changes. Upon call to this method, the NodeHandler is
// being notified of all nodes that are already in the cluster by calling
// the NodeHandler's NodeAdd callback.
Subscribe(datapath.NodeHandler)
// Unsubscribe removes the given NodeHandler from the list of subscribers.
Unsubscribe(datapath.NodeHandler)
}
type NodeManager interface {
Notifier
// GetNodes returns a copy of all the nodes as a map from Identity to Node.
GetNodes() map[types.Identity]types.Node
// GetNodeIdentities returns a list of all node identities store in node
// manager.
GetNodeIdentities() []types.Identity
// NodeUpdated is called when the store detects a change in node
// information
NodeUpdated(n types.Node)
// NodeDeleted is called when the store detects a deletion of a node
NodeDeleted(n types.Node)
// ClusterSizeDependantInterval returns a time.Duration that is dependent on
// the cluster size, i.e. the number of nodes that have been discovered. This
// can be used to control sync intervals of shared or centralized resources to
// avoid overloading these resources as the cluster grows.
ClusterSizeDependantInterval(baseInterval time.Duration) time.Duration
// StartNeighborRefresh spawns a controller which refreshes neighbor table
// by sending arping periodically.
StartNeighborRefresh(nh datapath.NodeNeighbors)
}
type ipsetManager interface {
AddToNodeIpset(nodeIP net.IP)
RemoveFromNodeIpset(nodeIP net.IP)
}
func newAllNodeManager(
lc cell.Lifecycle,
ipCache *ipcache.IPCache,
ipsetMgr ipsetManager,
nodeMetrics *nodeMetrics,
healthScope cell.Scope,
) (NodeManager, error) {
mngr, err := New(option.Config, ipCache, ipsetMgr, nodeMetrics, healthScope)
if err != nil {
return nil, err
}
lc.Append(mngr)
return mngr, nil
}