mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2026-05-05 14:46:10 +02:00
Added "external-dns/resource=..." field to CRDs usefull to solve conflits
Added warning when CR has a target with a "." in the end, which would make external-dns contantly add and remove the record Signed-off-by: João Marçal <joao.marcal12@gmail.com>
This commit is contained in:
parent
b97b8e1dec
commit
6bf1c2bcb5
@ -110,6 +110,7 @@ func NewCRDSource(crdClient rest.Interface, namespace, kind string, scheme *runt
|
||||
// Endpoints returns endpoint objects.
|
||||
func (cs *crdSource) Endpoints() ([]*endpoint.Endpoint, error) {
|
||||
endpoints := []*endpoint.Endpoint{}
|
||||
crdEndpoints := []*endpoint.Endpoint{}
|
||||
|
||||
result, err := cs.List(&metav1.ListOptions{})
|
||||
if err != nil {
|
||||
@ -118,14 +119,35 @@ func (cs *crdSource) Endpoints() ([]*endpoint.Endpoint, error) {
|
||||
|
||||
for _, dnsEndpoint := range result.Items {
|
||||
// Make sure that all endpoints have targets for A or CNAME type
|
||||
for _, endpoint := range dnsEndpoint.Spec.Endpoints {
|
||||
if (endpoint.RecordType == "CNAME" || endpoint.RecordType == "A") && len(endpoint.Targets) < 1 {
|
||||
log.Warnf("Endpoint %s with DNSName %s has an empty list of targets", dnsEndpoint.ObjectMeta.Name, endpoint.DNSName)
|
||||
crdEndpoints = []*endpoint.Endpoint{}
|
||||
for _, ep := range dnsEndpoint.Spec.Endpoints {
|
||||
if (ep.RecordType == "CNAME" || ep.RecordType == "A") && len(ep.Targets) < 1 {
|
||||
log.Warnf("Endpoint %s with DNSName %s has an empty list of targets", dnsEndpoint.ObjectMeta.Name, ep.DNSName)
|
||||
continue
|
||||
}
|
||||
endpoints = append(endpoints, endpoint)
|
||||
|
||||
illegalTarget := false
|
||||
for _, target := range ep.Targets{
|
||||
if strings.HasSuffix(target, "."){
|
||||
illegalTarget = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if illegalTarget{
|
||||
log.Warnf("Endpoint %s with DNSName %s has Target illegal target. The subdomain must consist of lower case alphanumeric characters, '-' or '.', and must start and end with an alphanumeric character (e.g. 'example.com')", dnsEndpoint.ObjectMeta.Name, ep.DNSName)
|
||||
continue
|
||||
}
|
||||
|
||||
if ep.Labels == nil{
|
||||
ep.Labels = endpoint.NewLabels()
|
||||
}
|
||||
|
||||
crdEndpoints = append(crdEndpoints, ep)
|
||||
}
|
||||
|
||||
cs.setResourceLabel(&dnsEndpoint, crdEndpoints)
|
||||
endpoints = append(endpoints, crdEndpoints...)
|
||||
|
||||
if dnsEndpoint.Status.ObservedGeneration == dnsEndpoint.Generation {
|
||||
continue
|
||||
}
|
||||
@ -141,6 +163,12 @@ func (cs *crdSource) Endpoints() ([]*endpoint.Endpoint, error) {
|
||||
return endpoints, nil
|
||||
}
|
||||
|
||||
func (cs *crdSource) setResourceLabel(crd *endpoint.DNSEndpoint, endpoints []*endpoint.Endpoint) {
|
||||
for _, ep := range endpoints {
|
||||
ep.Labels[endpoint.ResourceLabelKey] = fmt.Sprintf("crd/%s/%s", crd.ObjectMeta.Namespace, crd.ObjectMeta.Name)
|
||||
}
|
||||
}
|
||||
|
||||
func (cs *crdSource) List(opts *metav1.ListOptions) (result *endpoint.DNSEndpointList, err error) {
|
||||
result = &endpoint.DNSEndpointList{}
|
||||
err = cs.crdClient.Get().
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user