github.com/cilium/cilium@v1.16.2/pkg/node/manager/cell.go (about)

     1  // SPDX-License-Identifier: Apache-2.0
     2  // Copyright Authors of Cilium
     3  
     4  package manager
     5  
     6  import (
     7  	"github.com/cilium/hive/cell"
     8  
     9  	"github.com/cilium/cilium/pkg/datapath/iptables/ipset"
    10  	datapath "github.com/cilium/cilium/pkg/datapath/types"
    11  	"github.com/cilium/cilium/pkg/ipcache"
    12  	"github.com/cilium/cilium/pkg/metrics"
    13  	"github.com/cilium/cilium/pkg/node/types"
    14  	"github.com/cilium/cilium/pkg/option"
    15  	"github.com/cilium/cilium/pkg/time"
    16  )
    17  
    18  // Cell provides the NodeManager, which manages information about Cilium nodes
    19  // in the cluster and informs other modules of changes to node configuration.
    20  var Cell = cell.Module(
    21  	"node-manager",
    22  	"Manages the collection of Cilium nodes",
    23  	cell.Provide(newAllNodeManager),
    24  	metrics.Metric(NewNodeMetrics),
    25  )
    26  
    27  // Notifier is the interface the wraps Subscribe and Unsubscribe. An
    28  // implementation of this interface notifies subscribers of nodes being added,
    29  // updated or deleted.
    30  type Notifier interface {
    31  	// Subscribe adds the given NodeHandler to the list of subscribers that are
    32  	// notified of node changes. Upon call to this method, the NodeHandler is
    33  	// being notified of all nodes that are already in the cluster by calling
    34  	// the NodeHandler's NodeAdd callback.
    35  	Subscribe(datapath.NodeHandler)
    36  
    37  	// Unsubscribe removes the given NodeHandler from the list of subscribers.
    38  	Unsubscribe(datapath.NodeHandler)
    39  }
    40  
    41  type NodeManager interface {
    42  	datapath.NodeNeighborEnqueuer
    43  
    44  	Notifier
    45  
    46  	// GetNodes returns a copy of all the nodes as a map from Identity to Node.
    47  	GetNodes() map[types.Identity]types.Node
    48  
    49  	// GetNodeIdentities returns a list of all node identities store in node
    50  	// manager.
    51  	GetNodeIdentities() []types.Identity
    52  
    53  	// NodeUpdated is called when the store detects a change in node
    54  	// information
    55  	NodeUpdated(n types.Node)
    56  
    57  	// NodeDeleted is called when the store detects a deletion of a node
    58  	NodeDeleted(n types.Node)
    59  
    60  	// NodeSync is called when the store completes the initial nodes listing
    61  	NodeSync()
    62  	// MeshNodeSync is called when the store completes the initial nodes listing including meshed nodes
    63  	MeshNodeSync()
    64  
    65  	// ClusterSizeDependantInterval returns a time.Duration that is dependent on
    66  	// the cluster size, i.e. the number of nodes that have been discovered. This
    67  	// can be used to control sync intervals of shared or centralized resources to
    68  	// avoid overloading these resources as the cluster grows.
    69  	ClusterSizeDependantInterval(baseInterval time.Duration) time.Duration
    70  
    71  	// StartNeighborRefresh spawns a controller which refreshes neighbor table
    72  	// by sending arping periodically.
    73  	StartNeighborRefresh(nh datapath.NodeNeighbors)
    74  
    75  	// StartNodeNeighborLinkUpdater spawns a controller that watches a queue
    76  	// for node neighbor link updates.
    77  	StartNodeNeighborLinkUpdater(nh datapath.NodeNeighbors)
    78  }
    79  
    80  func newAllNodeManager(in struct {
    81  	cell.In
    82  	Lifecycle   cell.Lifecycle
    83  	IPCache     *ipcache.IPCache
    84  	IPSetMgr    ipset.Manager
    85  	IPSetFilter IPSetFilterFn `optional:"true"`
    86  	NodeMetrics *nodeMetrics
    87  	Health      cell.Health
    88  }) (NodeManager, error) {
    89  	mngr, err := New(option.Config, in.IPCache, in.IPSetMgr, in.IPSetFilter, in.NodeMetrics, in.Health)
    90  	if err != nil {
    91  		return nil, err
    92  	}
    93  	in.Lifecycle.Append(mngr)
    94  	return mngr, nil
    95  }