honor ttlAnnotationKey for node endpoints

This commit is contained in:
Reinier Schoof 2019-10-24 17:02:29 +02:00
parent fee7046e72
commit b6ec8557ae
2 changed files with 50 additions and 1 deletions

View File

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

View File

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