respect controller annotation for node source

This commit is contained in:
Reinier Schoof 2019-10-01 11:39:09 +02:00
parent 16194ca9cf
commit 4325d7368b
2 changed files with 36 additions and 0 deletions

View File

@ -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

View File

@ -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