From 4325d7368bc9eaf69cebc062eff594c16981a098 Mon Sep 17 00:00:00 2001 From: Reinier Schoof Date: Tue, 1 Oct 2019 11:39:09 +0200 Subject: [PATCH] respect controller annotation for node source --- source/node.go | 8 ++++++++ source/node_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/source/node.go b/source/node.go index ff3df47aa..3b844b9fc 100644 --- a/source/node.go +++ b/source/node.go @@ -107,6 +107,14 @@ func (ns *nodeSource) Endpoints() ([]*endpoint.Endpoint, error) { // create endpoints for all nodes for _, node := range nodes { + // Check controller annotation to see if we are responsible. + controller, ok := node.Annotations[controllerAnnotationKey] + if ok && controller != controllerAnnotationValue { + log.Debugf("Skipping node %s because controller value does not match, found: %s, required: %s", + node.Name, controller, controllerAnnotationValue) + continue + } + log.Debugf("creating endpoint for node %s", node.Name) // create new endpoint with the information we already have diff --git a/source/node_test.go b/source/node_test.go index f20bd4b45..e40ae5d9e 100644 --- a/source/node_test.go +++ b/source/node_test.go @@ -207,6 +207,34 @@ func testNodeSourceEndpoints(t *testing.T) { []*endpoint.Endpoint{}, false, }, + { + "our controller type is dns-controller", + "", + "", + "node1", + []v1.NodeAddress{{v1.NodeExternalIP, "1.2.3.4"}}, + map[string]string{}, + map[string]string{ + controllerAnnotationKey: controllerAnnotationValue, + }, + []*endpoint.Endpoint{ + {RecordType: "A", DNSName: "node1", Targets: endpoint.Targets{"1.2.3.4"}}, + }, + false, + }, + { + "different controller types are ignored", + "", + "", + "node1", + []v1.NodeAddress{{v1.NodeExternalIP, "1.2.3.4"}}, + map[string]string{}, + map[string]string{ + controllerAnnotationKey: "not-dns-controller", + }, + []*endpoint.Endpoint{}, + false, + }, } { t.Run(tc.title, func(t *testing.T) { // Create a Kubernetes testing client