source node: Skip unschedulable nodes

This commit is contained in:
n-Arno 2024-09-19 17:27:49 +02:00 committed by Arnaud ALCABAS
parent b336c524d0
commit 326ee0be69
3 changed files with 19 additions and 0 deletions

View File

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

View File

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

View File

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