Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

operator: sync CiliumNodes into etcd instead of k8s nodes #12179

Merged
merged 2 commits into from Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -25,10 +25,6 @@ rules:
- apiGroups:
- ""
resources:
# to automatically read from k8s and import the node's pod CIDR to cilium's
# etcd so all nodes know how to reach another pod running in in a different
# node.
- nodes
# to perform the translation of a CNP that contains `ToGroup` to its endpoints
- services
- endpoints
Expand Down
4 changes: 0 additions & 4 deletions install/kubernetes/experimental-install.yaml
Expand Up @@ -318,10 +318,6 @@ rules:
- apiGroups:
- ""
resources:
# to automatically read from k8s and import the node's pod CIDR to cilium's
# etcd so all nodes know how to reach another pod running in in a different
# node.
- nodes
# to perform the translation of a CNP that contains `ToGroup` to its endpoints
- services
- endpoints
Expand Down
4 changes: 0 additions & 4 deletions install/kubernetes/quick-install.yaml
Expand Up @@ -247,10 +247,6 @@ rules:
- apiGroups:
- ""
resources:
# to automatically read from k8s and import the node's pod CIDR to cilium's
# etcd so all nodes know how to reach another pod running in in a different
# node.
- nodes
# to perform the translation of a CNP that contains `ToGroup` to its endpoints
- services
- endpoints
Expand Down
26 changes: 13 additions & 13 deletions operator/k8s_node.go
Expand Up @@ -30,13 +30,13 @@ import (
v2 "github.com/cilium/cilium/pkg/k8s/client/clientset/versioned/typed/cilium.io/v2"
"github.com/cilium/cilium/pkg/k8s/informer"
slim_corev1 "github.com/cilium/cilium/pkg/k8s/slim/k8s/apis/core/v1"
v1 "github.com/cilium/cilium/pkg/k8s/slim/k8s/apis/meta/v1"
"github.com/cilium/cilium/pkg/k8s/utils"
k8sversion "github.com/cilium/cilium/pkg/k8s/version"
"github.com/cilium/cilium/pkg/kvstore/store"
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"

core_v1 "k8s.io/api/core/v1"
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -58,36 +58,36 @@ func runNodeWatcher(nodeManager *allocator.NodeEventHandler) error {
}

k8sNodeStore, nodeController := informer.NewInformer(
cache.NewListWatchFromClient(k8s.WatcherCli().CoreV1().RESTClient(),
"nodes", core_v1.NamespaceAll, fields.Everything()),
cache.NewListWatchFromClient(k8s.CiliumClient().CiliumV2().RESTClient(),
"ciliumnodes", v1.NamespaceAll, fields.Everything()),
&slim_corev1.Node{},
0,
cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
if n := k8s.ObjToV1Node(obj); n != nil {
nodeNew := k8s.ParseNode(n, source.Kubernetes)
ciliumNodeStore.UpdateKeySync(context.TODO(), nodeNew)
if ciliumNode := k8s.ObjToCiliumNode(obj); ciliumNode != nil {
nodeNew := nodeTypes.ParseCiliumNode(ciliumNode)
ciliumNodeStore.UpdateKeySync(context.TODO(), &nodeNew)
}
},
UpdateFunc: func(oldObj, newObj interface{}) {
if oldNode := k8s.ObjToV1Node(oldObj); oldNode != nil {
if newNode := k8s.ObjToV1Node(newObj); newNode != nil {
if oldNode := k8s.ObjToCiliumNode(oldObj); oldNode != nil {
if newNode := k8s.ObjToCiliumNode(newObj); newNode != nil {
if oldNode.DeepEqual(newNode) {
return
}

newNode := k8s.ParseNode(newNode, source.Kubernetes)
ciliumNodeStore.UpdateKeySync(context.TODO(), newNode)
nodeNew := nodeTypes.ParseCiliumNode(newNode)
ciliumNodeStore.UpdateKeySync(context.TODO(), &nodeNew)
}
}
},
DeleteFunc: func(obj interface{}) {
n := k8s.ObjToV1Node(obj)
n := k8s.ObjToCiliumNode(obj)
if n == nil {
return
}
deletedNode := k8s.ParseNode(n, source.Kubernetes)
ciliumNodeStore.DeleteLocalKey(context.TODO(), deletedNode)
deletedNode := nodeTypes.ParseCiliumNode(n)
ciliumNodeStore.DeleteLocalKey(context.TODO(), &deletedNode)
deleteCiliumNode(nodeManager, n.Name)
},
},
Expand Down
6 changes: 5 additions & 1 deletion pkg/nodediscovery/nodediscovery.go
Expand Up @@ -42,6 +42,7 @@ import (
"github.com/cilium/cilium/pkg/source"
cnitypes "github.com/cilium/cilium/plugins/cilium-cni/types"

"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand Down Expand Up @@ -163,7 +164,10 @@ func (n *NodeDiscovery) StartDiscovery(nodeName string) {
n.Manager.NodeUpdated(n.LocalNode)

go func() {
log.Info("Adding local node to cluster")
log.WithFields(
logrus.Fields{
logfields.Node: n.LocalNode,
}).Info("Adding local node to cluster")
for {
if err := n.Registrar.RegisterNode(&n.LocalNode, n.Manager); err != nil {
log.WithError(err).Error("Unable to initialize local node. Retrying...")
Expand Down