Skip to content

Commit

Permalink
As per PR request, added Unit test and doc
Browse files Browse the repository at this point in the history
  • Loading branch information
n-Arno authored and Arnaud ALCABAS committed Sep 19, 2024
1 parent 1290922 commit fcfa271
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions docs/sources/nodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]/core/v1#NodeSpec) are excluded.
This avoid exposing Unhealthy, NotReady or SchedulingDisabled (cordon) nodes.

## Manifest (for cluster without RBAC enabled)

```
Expand Down
11 changes: 11 additions & 0 deletions source/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}{
Expand Down Expand Up @@ -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) {
Expand All @@ -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,
},
Expand Down

0 comments on commit fcfa271

Please sign in to comment.