mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-08-06 01:26:59 +02:00
honor ttlAnnotationKey for node endpoints
This commit is contained in:
parent
fee7046e72
commit
b6ec8557ae
@ -58,7 +58,7 @@ func NewNodeSource(kubeClient kubernetes.Interface, annotationFilter, fqdnTempla
|
||||
}
|
||||
}
|
||||
|
||||
// Use shared informers to listen for add/update/delete of services/pods/nodes in the specified namespace.
|
||||
// Use shared informers to listen for add/update/delete of nodes.
|
||||
// Set resync period to 0, to prevent processing when nothing has changed
|
||||
informerFactory := kubeinformers.NewSharedInformerFactoryWithOptions(kubeClient, 0)
|
||||
nodeInformer := informerFactory.Core().V1().Nodes()
|
||||
@ -117,9 +117,15 @@ func (ns *nodeSource) Endpoints() ([]*endpoint.Endpoint, error) {
|
||||
|
||||
log.Debugf("creating endpoint for node %s", node.Name)
|
||||
|
||||
ttl, err := getTTLFromAnnotations(node.Annotations)
|
||||
if err != nil {
|
||||
log.Warn(err)
|
||||
}
|
||||
|
||||
// create new endpoint with the information we already have
|
||||
ep := &endpoint.Endpoint{
|
||||
RecordType: "A", // hardcoded DNS record type
|
||||
RecordTTL: ttl,
|
||||
}
|
||||
|
||||
if ns.fqdnTemplate != nil {
|
||||
|
@ -248,6 +248,49 @@ func testNodeSourceEndpoints(t *testing.T) {
|
||||
[]*endpoint.Endpoint{},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"ttl not annotated should have RecordTTL.IsConfigured set to false",
|
||||
"",
|
||||
"",
|
||||
"node1",
|
||||
[]v1.NodeAddress{{v1.NodeExternalIP, "1.2.3.4"}},
|
||||
map[string]string{},
|
||||
map[string]string{},
|
||||
[]*endpoint.Endpoint{
|
||||
{RecordType: "A", DNSName: "node1", Targets: endpoint.Targets{"1.2.3.4"}, RecordTTL: endpoint.TTL(0)},
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"ttl annotated but invalid should have RecordTTL.IsConfigured set to false",
|
||||
"",
|
||||
"",
|
||||
"node1",
|
||||
[]v1.NodeAddress{{v1.NodeExternalIP, "1.2.3.4"}},
|
||||
map[string]string{},
|
||||
map[string]string{
|
||||
ttlAnnotationKey: "foo",
|
||||
},
|
||||
[]*endpoint.Endpoint{
|
||||
{RecordType: "A", DNSName: "node1", Targets: endpoint.Targets{"1.2.3.4"}, RecordTTL: endpoint.TTL(0)},
|
||||
},
|
||||
false,
|
||||
},
|
||||
{
|
||||
"ttl annotated and is valid should set Record.TTL",
|
||||
"",
|
||||
"",
|
||||
"node1",
|
||||
[]v1.NodeAddress{{v1.NodeExternalIP, "1.2.3.4"}},
|
||||
map[string]string{},
|
||||
map[string]string{
|
||||
ttlAnnotationKey: "10",
|
||||
},
|
||||
[]*endpoint.Endpoint{
|
||||
{RecordType: "A", DNSName: "node1", Targets: endpoint.Targets{"1.2.3.4"}, RecordTTL: endpoint.TTL(10)},
|
||||
},
|
||||
false,
|
||||
},
|
||||
} {
|
||||
t.Run(tc.title, func(t *testing.T) {
|
||||
// Create a Kubernetes testing client
|
||||
|
Loading…
Reference in New Issue
Block a user