From 326ee0be69492ec5819bca48d872f11a12b25387 Mon Sep 17 00:00:00 2001 From: n-Arno Date: Thu, 19 Sep 2024 17:27:49 +0200 Subject: [PATCH] source node: Skip unschedulable nodes --- docs/sources/nodes.md | 3 +++ source/node.go | 5 +++++ source/node_test.go | 11 +++++++++++ 3 files changed, 19 insertions(+) diff --git a/docs/sources/nodes.md b/docs/sources/nodes.md index 0db1c99c7..ca88b44f5 100644 --- a/docs/sources/nodes.md +++ b/docs/sources/nodes.md @@ -7,6 +7,9 @@ The node source adds an `A` record per each node `externalIP` (if not found, any It also adds an `AAAA` record per each node IPv6 `internalIP`. The TTL of the records can be set with the `external-dns.alpha.kubernetes.io/ttl` node annotation. +Nodes marked as **Unschedulable** as per [core/v1/NodeSpec](https://pkg.go.dev/k8s.io/api@v0.31.1/core/v1#NodeSpec) are excluded. +This avoid exposing Unhealthy, NotReady or SchedulingDisabled (cordon) nodes. + ## Manifest (for cluster without RBAC enabled) ``` diff --git a/source/node.go b/source/node.go index 81e40755d..c35b3883e 100644 --- a/source/node.go +++ b/source/node.go @@ -102,6 +102,11 @@ func (ns *nodeSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, erro continue } + if node.Spec.Unschedulable { + log.Debugf("Skipping node %s because it is unschedulable", node.Name) + continue + } + log.Debugf("creating endpoint for node %s", node.Name) ttl := getTTLFromAnnotations(node.Annotations, fmt.Sprintf("node/%s", node.Name)) diff --git a/source/node_test.go b/source/node_test.go index 9ce4591df..bf047bae8 100644 --- a/source/node_test.go +++ b/source/node_test.go @@ -101,6 +101,7 @@ func testNodeSourceEndpoints(t *testing.T) { nodeAddresses []v1.NodeAddress labels map[string]string annotations map[string]string + unschedulable bool // default to false expected []*endpoint.Endpoint expectError bool }{ @@ -321,6 +322,13 @@ func testNodeSourceEndpoints(t *testing.T) { {RecordType: "A", DNSName: "node1", Targets: endpoint.Targets{"1.2.3.4"}, RecordTTL: endpoint.TTL(10)}, }, }, + { + title: "unschedulable node return nothing", + nodeName: "node1", + nodeAddresses: []v1.NodeAddress{{Type: v1.NodeExternalIP, Address: "1.2.3.4"}}, + unschedulable: true, + expected: []*endpoint.Endpoint{}, + }, } { tc := tc t.Run(tc.title, func(t *testing.T) { @@ -342,6 +350,9 @@ func testNodeSourceEndpoints(t *testing.T) { Labels: tc.labels, Annotations: tc.annotations, }, + Spec: v1.NodeSpec{ + Unschedulable: tc.unschedulable, + }, Status: v1.NodeStatus{ Addresses: tc.nodeAddresses, },