mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-10-30 18:20:59 +01:00
Merge pull request #3294 from rikatz/deal-with-nil-endpoint
Fix null pointer on generateTxtRecord
This commit is contained in:
commit
7b7b84dce2
@ -191,19 +191,26 @@ func (im *TXTRegistry) generateTXTRecord(r *endpoint.Endpoint) []*endpoint.Endpo
|
|||||||
if r.RecordType == endpoint.RecordTypeTXT {
|
if r.RecordType == endpoint.RecordTypeTXT {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
endpoints := make([]*endpoint.Endpoint, 0)
|
||||||
|
|
||||||
// old TXT record format
|
// old TXT record format
|
||||||
txt := endpoint.NewEndpoint(im.mapper.toTXTName(r.DNSName), endpoint.RecordTypeTXT, r.Labels.Serialize(true)).WithSetIdentifier(r.SetIdentifier)
|
txt := endpoint.NewEndpoint(im.mapper.toTXTName(r.DNSName), endpoint.RecordTypeTXT, r.Labels.Serialize(true))
|
||||||
txt.ProviderSpecific = r.ProviderSpecific
|
if txt != nil {
|
||||||
|
txt.WithSetIdentifier(r.SetIdentifier)
|
||||||
|
txt.ProviderSpecific = r.ProviderSpecific
|
||||||
|
endpoints = append(endpoints, txt)
|
||||||
|
}
|
||||||
|
|
||||||
// new TXT record format (containing record type)
|
// new TXT record format (containing record type)
|
||||||
txtNew := endpoint.NewEndpoint(im.mapper.toNewTXTName(r.DNSName, r.RecordType), endpoint.RecordTypeTXT, r.Labels.Serialize(true))
|
txtNew := endpoint.NewEndpoint(im.mapper.toNewTXTName(r.DNSName, r.RecordType), endpoint.RecordTypeTXT, r.Labels.Serialize(true))
|
||||||
if txtNew != nil {
|
if txtNew != nil {
|
||||||
txtNew.WithSetIdentifier(r.SetIdentifier)
|
txtNew.WithSetIdentifier(r.SetIdentifier)
|
||||||
txtNew.ProviderSpecific = r.ProviderSpecific
|
txtNew.ProviderSpecific = r.ProviderSpecific
|
||||||
} else {
|
endpoints = append(endpoints, txtNew)
|
||||||
return []*endpoint.Endpoint{txt}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return []*endpoint.Endpoint{txt, txtNew}
|
return endpoints
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyChanges updates dns provider with the changes
|
// ApplyChanges updates dns provider with the changes
|
||||||
|
|||||||
@ -1169,6 +1169,23 @@ func TestGenerateTXT(t *testing.T) {
|
|||||||
assert.Equal(t, expectedTXT, gotTXT)
|
assert.Equal(t, expectedTXT, gotTXT)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFailGenerateTXT(t *testing.T) {
|
||||||
|
|
||||||
|
cnameRecord := &endpoint.Endpoint{
|
||||||
|
DNSName: "foo-some-really-big-name-not-supported-and-will-fail-000000000000000000.test-zone.example.org",
|
||||||
|
Targets: endpoint.Targets{"new-foo.loadbalancer.com"},
|
||||||
|
RecordType: endpoint.RecordTypeCNAME,
|
||||||
|
Labels: map[string]string{},
|
||||||
|
}
|
||||||
|
// A bad DNS name returns empty expected TXT
|
||||||
|
expectedTXT := []*endpoint.Endpoint{}
|
||||||
|
p := inmemory.NewInMemoryProvider()
|
||||||
|
p.CreateZone(testZone)
|
||||||
|
r, _ := NewTXTRegistry(p, "", "", "owner", time.Hour, "", []string{})
|
||||||
|
gotTXT := r.generateTXTRecord(cnameRecord)
|
||||||
|
assert.Equal(t, expectedTXT, gotTXT)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
||||||
helper methods
|
helper methods
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user