Skip to content

Commit

Permalink
Moved the Node type from the main "node" package to the sub-package…
Browse files Browse the repository at this point in the history
…, "node/types".

This continues the effort to decouple commonly used code from being Linux specific.
So that the type, itself, may be imported easily by other packages.

Signed-off-by: Nate Sweet <nathanjsweet@pm.me>
  • Loading branch information
nathanjsweet authored and pchaigno committed Apr 21, 2020
1 parent 1598f74 commit e99049f
Show file tree
Hide file tree
Showing 38 changed files with 244 additions and 207 deletions.
2 changes: 1 addition & 1 deletion Documentation/kvstore.rst
Expand Up @@ -34,7 +34,7 @@ Key Value
``cilium/state/nodes/v1/<cluster>/<node>`` node.Node_
============================================================ ====================

.. _node.Node: https://godoc.org/github.com/cilium/cilium/pkg/node#Node
.. _node.Node: https://godoc.org/github.com/cilium/cilium/pkg/node/types#Node

All node keys are attached to a lease owned by the agent of the respective
node.
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -320,7 +320,6 @@ generate-k8s-api:
$(call generate_k8s_api_deepcopy,github.com/cilium/cilium/pkg,"policy:api")
$(call generate_k8s_api_deepcopy,github.com/cilium/cilium,"pkg:loadbalancer")
$(call generate_k8s_api_deepcopy,github.com/cilium/cilium,"pkg:k8s")
$(call generate_k8s_api_deepcopy,github.com/cilium/cilium,"pkg:node")
$(call generate_k8s_api_deepcopy,github.com/cilium/cilium/api,"v1:models")
$(call generate_k8s_api_deepcopy,github.com/cilium/cilium/pkg,"k8s:types")
$(call generate_k8s_api_deepcopy,github.com/cilium/cilium/pkg,"maps:policymap")
Expand All @@ -339,6 +338,7 @@ generate-k8s-api:
$(call generate_k8s_api_deepcopy,github.com/cilium/cilium/pkg,"maps:neighborsmap")
$(call generate_k8s_api_deepcopy,github.com/cilium/cilium/pkg,"maps:fragmap")
$(call generate_k8s_api_deepcopy,github.com/cilium/cilium/pkg,"service:store")
$(call generate_k8s_api_deepcopy,github.com/cilium/cilium/pkg,"node:types")
$(call generate_k8s_api_deepcopy,github.com/cilium/cilium,"pkg:tuple")
$(call generate_k8s_api_deepcopy,github.com/cilium/cilium,"pkg:bpf")

Expand Down
3 changes: 2 additions & 1 deletion cilium-health/launch/endpoint.go
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/cilium/cilium/pkg/mtu"
"github.com/cilium/cilium/pkg/netns"
"github.com/cilium/cilium/pkg/node"
nodeTypes "github.com/cilium/cilium/pkg/node/types"
"github.com/cilium/cilium/pkg/option"
"github.com/cilium/cilium/pkg/pidfile"
"github.com/cilium/cilium/pkg/sysctl"
Expand Down Expand Up @@ -233,7 +234,7 @@ type EndpointAdder interface {
//
// CleanupEndpoint() must be called before calling LaunchAsEndpoint() to ensure
// cleanup of prior cilium-health endpoint instances.
func LaunchAsEndpoint(baseCtx context.Context, owner regeneration.Owner, n *node.Node, mtuConfig mtu.Configuration, epMgr EndpointAdder, proxy endpoint.EndpointProxy, allocator cache.IdentityAllocator) (*Client, error) {
func LaunchAsEndpoint(baseCtx context.Context, owner regeneration.Owner, n *nodeTypes.Node, mtuConfig mtu.Configuration, epMgr EndpointAdder, proxy endpoint.EndpointProxy, allocator cache.IdentityAllocator) (*Client, error) {
var (
cmd = launcher.Launcher{}
info = &models.EndpointChangeRequest{
Expand Down
5 changes: 3 additions & 2 deletions daemon/cmd/daemon.go
Expand Up @@ -67,6 +67,7 @@ import (
"github.com/cilium/cilium/pkg/node"
nodemanager "github.com/cilium/cilium/pkg/node/manager"
nodeStore "github.com/cilium/cilium/pkg/node/store"
nodeTypes "github.com/cilium/cilium/pkg/node/types"
"github.com/cilium/cilium/pkg/nodediscovery"
"github.com/cilium/cilium/pkg/option"
"github.com/cilium/cilium/pkg/policy"
Expand Down Expand Up @@ -470,7 +471,7 @@ func NewDaemon(ctx context.Context, dp datapath.Datapath) (*Daemon, *endpointRes
logfields.V6CiliumHostIP: node.GetIPv6Router(),
}).Info("Annotating k8s node")

err := k8s.Client().AnnotateNode(node.GetName(),
err := k8s.Client().AnnotateNode(nodeTypes.GetName(),
encryptKeyID,
node.GetIPv4AllocRange(), node.GetIPv6AllocRange(),
d.nodeDiscovery.LocalNode.IPv4HealthIP, d.nodeDiscovery.LocalNode.IPv6HealthIP,
Expand All @@ -483,7 +484,7 @@ func NewDaemon(ctx context.Context, dp datapath.Datapath) (*Daemon, *endpointRes
log.Debug("Annotate k8s node is disabled.")
}

d.nodeDiscovery.StartDiscovery(node.GetName())
d.nodeDiscovery.StartDiscovery(nodeTypes.GetName())

// Trigger refresh and update custom resource in the apiserver with all restored endpoints.
// Trigger after nodeDiscovery.StartDiscovery to avoid custom resource update conflict.
Expand Down
3 changes: 2 additions & 1 deletion daemon/cmd/daemon_main.go
Expand Up @@ -56,6 +56,7 @@ import (
"github.com/cilium/cilium/pkg/metrics"
monitorAPI "github.com/cilium/cilium/pkg/monitor/api"
"github.com/cilium/cilium/pkg/node"
nodeTypes "github.com/cilium/cilium/pkg/node/types"
"github.com/cilium/cilium/pkg/option"
"github.com/cilium/cilium/pkg/pidfile"
"github.com/cilium/cilium/pkg/policy"
Expand Down Expand Up @@ -1321,7 +1322,7 @@ func runDaemon() {

if k8s.IsEnabled() {
bootstrapStats.k8sInit.Start()
k8s.Client().MarkNodeReady(node.GetName())
k8s.Client().MarkNodeReady(nodeTypes.GetName())
bootstrapStats.k8sInit.End(true)
}

Expand Down
3 changes: 2 additions & 1 deletion daemon/cmd/ipam.go
Expand Up @@ -29,6 +29,7 @@ import (
"github.com/cilium/cilium/pkg/ipam"
"github.com/cilium/cilium/pkg/logging/logfields"
"github.com/cilium/cilium/pkg/node"
nodeTypes "github.com/cilium/cilium/pkg/node/types"
"github.com/cilium/cilium/pkg/option"

"github.com/go-openapi/runtime/middleware"
Expand Down Expand Up @@ -263,7 +264,7 @@ func (d *Daemon) allocateIPs() error {
log.Info("Addressing information:")
log.Infof(" Cluster-Name: %s", option.Config.ClusterName)
log.Infof(" Cluster-ID: %d", option.Config.ClusterID)
log.Infof(" Local node-name: %s", node.GetName())
log.Infof(" Local node-name: %s", nodeTypes.GetName())
log.Infof(" Node-IPv6: %s", node.GetIPv6())

if option.Config.EnableIPv6 {
Expand Down
10 changes: 5 additions & 5 deletions daemon/cmd/status.go
Expand Up @@ -29,7 +29,7 @@ import (
k8smetrics "github.com/cilium/cilium/pkg/k8s/metrics"
"github.com/cilium/cilium/pkg/kvstore"
"github.com/cilium/cilium/pkg/lock"
"github.com/cilium/cilium/pkg/node"
nodeTypes "github.com/cilium/cilium/pkg/node/types"
"github.com/cilium/cilium/pkg/option"
"github.com/cilium/cilium/pkg/rand"
"github.com/cilium/cilium/pkg/status"
Expand Down Expand Up @@ -217,22 +217,22 @@ type clusterNodesClient struct {
*models.ClusterNodeStatus
}

func (c *clusterNodesClient) NodeAdd(newNode node.Node) error {
func (c *clusterNodesClient) NodeAdd(newNode nodeTypes.Node) error {
c.Lock()
c.NodesAdded = append(c.NodesAdded, newNode.GetModel())
c.Unlock()
return nil
}

func (c *clusterNodesClient) NodeUpdate(oldNode, newNode node.Node) error {
func (c *clusterNodesClient) NodeUpdate(oldNode, newNode nodeTypes.Node) error {
c.Lock()
c.NodesAdded = append(c.NodesAdded, newNode.GetModel())
c.NodesRemoved = append(c.NodesRemoved, oldNode.GetModel())
c.Unlock()
return nil
}

func (c *clusterNodesClient) NodeDelete(node node.Node) error {
func (c *clusterNodesClient) NodeDelete(node nodeTypes.Node) error {
c.Lock()
// If the node was added/updated and removed before the clusterNodesClient
// was aware of it then we can safely remove it from the list of added
Expand All @@ -252,7 +252,7 @@ func (c *clusterNodesClient) NodeDelete(node node.Node) error {
return nil
}

func (c *clusterNodesClient) NodeValidateImplementation(node node.Node) error {
func (c *clusterNodesClient) NodeValidateImplementation(node nodeTypes.Node) error {
// no-op
return nil
}
Expand Down
13 changes: 6 additions & 7 deletions operator/k8s_node.go
Expand Up @@ -25,17 +25,16 @@ import (
"github.com/cilium/cilium/pkg/ipam"
"github.com/cilium/cilium/pkg/k8s"
cilium_v2 "github.com/cilium/cilium/pkg/k8s/apis/cilium.io/v2"
"github.com/cilium/cilium/pkg/k8s/client/clientset/versioned/typed/cilium.io/v2"
v2 "github.com/cilium/cilium/pkg/k8s/client/clientset/versioned/typed/cilium.io/v2"
"github.com/cilium/cilium/pkg/k8s/informer"
"github.com/cilium/cilium/pkg/k8s/utils"
k8sversion "github.com/cilium/cilium/pkg/k8s/version"
"github.com/cilium/cilium/pkg/kvstore/store"
"github.com/cilium/cilium/pkg/node"
nodeStore "github.com/cilium/cilium/pkg/node/store"
nodeTypes "github.com/cilium/cilium/pkg/node/types"
"github.com/cilium/cilium/pkg/option"
"github.com/cilium/cilium/pkg/source"

"k8s.io/api/core/v1"
core_v1 "k8s.io/api/core/v1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/fields"
Expand All @@ -57,8 +56,8 @@ func runNodeWatcher(nodeManager *ipam.NodeManager) error {

k8sNodeStore, nodeController := informer.NewInformer(
cache.NewListWatchFromClient(k8s.Client().CoreV1().RESTClient(),
"nodes", v1.NamespaceAll, fields.Everything()),
&v1.Node{},
"nodes", core_v1.NamespaceAll, fields.Everything()),
&core_v1.Node{},
0,
cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
Expand Down Expand Up @@ -130,7 +129,7 @@ func runNodeWatcher(nodeManager *ipam.NodeManager) error {
kvStoreNodes := ciliumNodeStore.SharedKeysMap()
for _, k8sNode := range listOfK8sNodes {
// The remaining kvStoreNodes are leftovers
kvStoreNodeName := node.GetKeyNodeName(option.Config.ClusterName, k8sNode)
kvStoreNodeName := nodeTypes.GetKeyNodeName(option.Config.ClusterName, k8sNode)
delete(kvStoreNodes, kvStoreNodeName)
}

Expand Down Expand Up @@ -214,7 +213,7 @@ func runCNPNodeStatusGC(name string, clusterwide bool, ciliumNodeStore *store.Sh
needsUpdate := false
nodesToDelete := map[string]cilium_v2.Timestamp{}
for n, status := range cnp.Status.Nodes {
kvStoreNodeName := node.GetKeyNodeName(option.Config.ClusterName, n)
kvStoreNodeName := nodeTypes.GetKeyNodeName(option.Config.ClusterName, n)
if _, exists := kvStoreNodes[kvStoreNodeName]; !exists {
// To avoid concurrency issues where a is
// created and adds its CNP Status before the operator
Expand Down
8 changes: 4 additions & 4 deletions pkg/datapath/fake/datapath_test.go
Expand Up @@ -20,7 +20,7 @@ import (
"testing"

"github.com/cilium/cilium/pkg/datapath"
"github.com/cilium/cilium/pkg/node"
nodeTypes "github.com/cilium/cilium/pkg/node/types"

"gopkg.in/check.v1"
)
Expand All @@ -37,9 +37,9 @@ func (s *fakeTestSuite) TestNewDatapath(c *check.C) {
dp := NewDatapath()
c.Assert(dp, check.Not(check.IsNil))

c.Assert(dp.Node().NodeAdd(node.Node{}), check.IsNil)
c.Assert(dp.Node().NodeUpdate(node.Node{}, node.Node{}), check.IsNil)
c.Assert(dp.Node().NodeDelete(node.Node{}), check.IsNil)
c.Assert(dp.Node().NodeAdd(nodeTypes.Node{}), check.IsNil)
c.Assert(dp.Node().NodeUpdate(nodeTypes.Node{}, nodeTypes.Node{}), check.IsNil)
c.Assert(dp.Node().NodeDelete(nodeTypes.Node{}), check.IsNil)
c.Assert(dp.Node().NodeConfigurationChanged(datapath.LocalNodeConfiguration{}), check.IsNil)

c.Assert(dp.LocalNodeAddressing().IPv6().Router(), check.Not(check.IsNil))
Expand Down
10 changes: 5 additions & 5 deletions pkg/datapath/fake/node.go
Expand Up @@ -16,7 +16,7 @@ package fake

import (
"github.com/cilium/cilium/pkg/datapath"
"github.com/cilium/cilium/pkg/node"
nodeTypes "github.com/cilium/cilium/pkg/node/types"
)

type fakeNodeHandler struct{}
Expand All @@ -26,19 +26,19 @@ func NewNodeHandler() datapath.NodeHandler {
return &fakeNodeHandler{}
}

func (n *fakeNodeHandler) NodeAdd(newNode node.Node) error {
func (n *fakeNodeHandler) NodeAdd(newNode nodeTypes.Node) error {
return nil
}

func (n *fakeNodeHandler) NodeUpdate(oldNode, newNode node.Node) error {
func (n *fakeNodeHandler) NodeUpdate(oldNode, newNode nodeTypes.Node) error {
return nil
}

func (n *fakeNodeHandler) NodeDelete(node node.Node) error {
func (n *fakeNodeHandler) NodeDelete(node nodeTypes.Node) error {
return nil
}

func (n *fakeNodeHandler) NodeValidateImplementation(node node.Node) error {
func (n *fakeNodeHandler) NodeValidateImplementation(node nodeTypes.Node) error {
return nil
}

Expand Down
32 changes: 16 additions & 16 deletions pkg/datapath/linux/node.go
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/cilium/cilium/pkg/lock"
"github.com/cilium/cilium/pkg/logging/logfields"
"github.com/cilium/cilium/pkg/maps/tunnel"
"github.com/cilium/cilium/pkg/node"
nodeTypes "github.com/cilium/cilium/pkg/node/types"
"github.com/cilium/cilium/pkg/option"

"github.com/cilium/arping"
Expand All @@ -47,9 +47,9 @@ type linuxNodeHandler struct {
nodeConfig datapath.LocalNodeConfiguration
nodeAddressing datapath.NodeAddressing
datapathConfig DatapathConfiguration
nodes map[node.Identity]*node.Node
nodes map[nodeTypes.Identity]*nodeTypes.Node
enableNeighDiscovery bool
neighByNode map[node.Identity]*netlink.Neigh
neighByNode map[nodeTypes.Identity]*netlink.Neigh
}

// NewNodeHandler returns a new node handler to handle node events and
Expand All @@ -58,8 +58,8 @@ func NewNodeHandler(datapathConfig DatapathConfiguration, nodeAddressing datapat
return &linuxNodeHandler{
nodeAddressing: nodeAddressing,
datapathConfig: datapathConfig,
nodes: map[node.Identity]*node.Node{},
neighByNode: map[node.Identity]*netlink.Neigh{},
nodes: map[nodeTypes.Identity]*nodeTypes.Node{},
neighByNode: map[nodeTypes.Identity]*netlink.Neigh{},
}
}

Expand Down Expand Up @@ -399,7 +399,7 @@ func (n *linuxNodeHandler) updateOrRemoveNodeRoutes(old, new []*cidr.CIDR) {
}
}

func (n *linuxNodeHandler) NodeAdd(newNode node.Node) error {
func (n *linuxNodeHandler) NodeAdd(newNode nodeTypes.Node) error {
n.mutex.Lock()
defer n.mutex.Unlock()

Expand All @@ -412,7 +412,7 @@ func (n *linuxNodeHandler) NodeAdd(newNode node.Node) error {
return nil
}

func (n *linuxNodeHandler) NodeUpdate(oldNode, newNode node.Node) error {
func (n *linuxNodeHandler) NodeUpdate(oldNode, newNode nodeTypes.Node) error {
n.mutex.Lock()
defer n.mutex.Unlock()

Expand Down Expand Up @@ -470,7 +470,7 @@ func (n *linuxNodeHandler) enableSubnetIPsec(v4CIDR, v6CIDR []*net.IPNet) {
}
}

func (n *linuxNodeHandler) encryptNode(newNode *node.Node) {
func (n *linuxNodeHandler) encryptNode(newNode *nodeTypes.Node) {
var spi uint8
var err error

Expand Down Expand Up @@ -558,7 +558,7 @@ func neighborLog(spec, iface string, err error, ip *net.IP, hwAddr *net.Hardware
}
}

func (n *linuxNodeHandler) insertNeighbor(newNode *node.Node, ifaceName string) {
func (n *linuxNodeHandler) insertNeighbor(newNode *nodeTypes.Node, ifaceName string) {
if newNode.IsLocal() {
return
}
Expand Down Expand Up @@ -603,7 +603,7 @@ func (n *linuxNodeHandler) insertNeighbor(newNode *node.Node, ifaceName string)
}
}

func (n *linuxNodeHandler) deleteNeighbor(oldNode *node.Node) {
func (n *linuxNodeHandler) deleteNeighbor(oldNode *nodeTypes.Node) {
neigh, ok := n.neighByNode[oldNode.Identity()]
if !ok {
return
Expand All @@ -618,7 +618,7 @@ func (n *linuxNodeHandler) deleteNeighbor(oldNode *node.Node) {
}
}

func (n *linuxNodeHandler) enableIPsec(newNode *node.Node) {
func (n *linuxNodeHandler) enableIPsec(newNode *nodeTypes.Node) {
var spi uint8
var err error

Expand Down Expand Up @@ -675,7 +675,7 @@ func (n *linuxNodeHandler) subnetEncryption() bool {
return len(n.nodeConfig.IPv4PodSubnets) > 0 || len(n.nodeConfig.IPv6PodSubnets) > 0
}

func (n *linuxNodeHandler) nodeUpdate(oldNode, newNode *node.Node, firstAddition bool) error {
func (n *linuxNodeHandler) nodeUpdate(oldNode, newNode *nodeTypes.Node, firstAddition bool) error {
var (
oldIP4Cidr, oldIP6Cidr *cidr.CIDR
oldIP4, oldIP6 net.IP
Expand Down Expand Up @@ -759,7 +759,7 @@ func (n *linuxNodeHandler) nodeUpdate(oldNode, newNode *node.Node, firstAddition
return nil
}

func (n *linuxNodeHandler) NodeDelete(oldNode node.Node) error {
func (n *linuxNodeHandler) NodeDelete(oldNode nodeTypes.Node) error {
n.mutex.Lock()
defer n.mutex.Unlock()

Expand All @@ -775,7 +775,7 @@ func (n *linuxNodeHandler) NodeDelete(oldNode node.Node) error {
return nil
}

func (n *linuxNodeHandler) nodeDelete(oldNode *node.Node) error {
func (n *linuxNodeHandler) nodeDelete(oldNode *nodeTypes.Node) error {
if oldNode.IsLocal() {
return nil
}
Expand Down Expand Up @@ -1060,7 +1060,7 @@ func (n *linuxNodeHandler) replaceNodeIPSecInRoute(ip *net.IPNet) {
}
}

func (n *linuxNodeHandler) deleteIPsec(oldNode *node.Node) {
func (n *linuxNodeHandler) deleteIPsec(oldNode *nodeTypes.Node) {
if n.nodeConfig.EnableIPv4 && oldNode.IPv4AllocCIDR != nil {
ciliumInternalIPv4 := oldNode.GetCiliumInternalIP(false)
old4Net := &net.IPNet{IP: ciliumInternalIPv4, Mask: oldNode.IPv4AllocCIDR.Mask}
Expand Down Expand Up @@ -1141,7 +1141,7 @@ func (n *linuxNodeHandler) NodeConfigurationChanged(newConfig datapath.LocalNode

// NodeValidateImplementation is called to validate the implementation of the
// node in the datapath
func (n *linuxNodeHandler) NodeValidateImplementation(nodeToValidate node.Node) error {
func (n *linuxNodeHandler) NodeValidateImplementation(nodeToValidate nodeTypes.Node) error {
return n.nodeUpdate(nil, &nodeToValidate, false)
}

Expand Down

0 comments on commit e99049f

Please sign in to comment.