mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2026-04-19 06:51:26 +02:00
* feat(metrics): add source wrapper metrics for invalid and deduplicated endpoints Add GaugeVecMetric.Reset() to clear stale label combinations between cycles. Introduce invalidEndpoints and deduplicatedEndpoints gauge vectors in the source wrappers package, partitioned by record_type and source_type. The dedup source wrapper now tracks rejected (invalid) and de-duplicated endpoints per collection cycle. Update the metrics documentation and bump the known metrics count. Signed-off-by: Seena Fallah <seenafallah@gmail.com> * feat(source): add PTR source wrapper for automatic reverse DNS Implement ptrSource, a source wrapper that generates PTR endpoints from A/AAAA records. The wrapper supports: - Global default via WithCreatePTR (maps to --create-ptr flag) - Per-endpoint override via record-type provider-specific property - Grouping multiple hostnames sharing an IP into a single PTR endpoint - Skipping wildcard DNS names Add WithPTRSupported and WithCreatePTR options to the wrapper Config and wire the PTR wrapper into the WrapSources chain when PTR is in managed-record-types. Signed-off-by: Seena Fallah <seenafallah@gmail.com> * feat(config): add --create-ptr flag and deprecate --rfc2136-create-ptr Add the generic --create-ptr boolean flag to Config, enabling automatic PTR record creation for any provider. Add IsPTRSupported() helper that checks whether PTR is included in --managed-record-types. Add validation: --create-ptr (or legacy --rfc2136-create-ptr) now requires PTR in --managed-record-types, preventing misconfiguration. Mark --rfc2136-create-ptr as deprecated in the flag description. Signed-off-by: Seena Fallah <seenafallah@gmail.com> * refactor(rfc2136): remove inline PTR logic in favor of PTR source wrapper Remove the createPTR field, AddReverseRecord, RemoveReverseRecord, and GenerateReverseRecord methods from the rfc2136 provider. PTR record generation is now handled generically by the PTR source wrapper before records reach the provider. Update the PTR creation test to supply pre-generated PTR endpoints (simulating what the source wrapper produces) instead of relying on the provider to create them internally. Signed-off-by: Seena Fallah <seenafallah@gmail.com> * feat(controller): wire PTR source wrapper into buildSource Pass the top-level Config to buildSource so it can read IsPTRSupported() and the CreatePTR / RFC2136CreatePTR flags. When PTR is in managed-record-types, the PTR source wrapper is installed in the wrapper chain with the combined create-ptr default. Signed-off-by: Seena Fallah <seenafallah@gmail.com> * chore(pdns): remove stale comment and fix whitespace Remove an outdated comment about a single-target-per-tuple assumption that no longer applies. Signed-off-by: Seena Fallah <seenafallah@gmail.com> * docs: add PTR records documentation and update existing guides Add docs/advanced/ptr-records.md covering the --create-ptr flag, per-resource annotation overrides, prerequisites, and usage examples. Update: - annotations.md: document record-type annotation - flags.md: add --create-ptr, mark --rfc2136-create-ptr as deprecated - tutorials/rfc2136.md: point to generic --create-ptr flag - contributing/source-wrappers.md: add PTR wrapper to the chain - mkdocs.yml: add PTR Records navigation entry Signed-off-by: Seena Fallah <seenafallah@gmail.com> * feat(rfc2136)!: remove rfc2136-create-ptr in favor of create-ptr Signed-off-by: Seena Fallah <seenafallah@gmail.com> --------- Signed-off-by: Seena Fallah <seenafallah@gmail.com>
86 lines
2.4 KiB
Go
86 lines
2.4 KiB
Go
/*
|
|
Copyright 2017 The Kubernetes Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package wrappers
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"sigs.k8s.io/external-dns/endpoint"
|
|
"sigs.k8s.io/external-dns/source"
|
|
)
|
|
|
|
// dedupSource is a Source that removes duplicate endpoints from its wrapped source.
|
|
type dedupSource struct {
|
|
source source.Source
|
|
}
|
|
|
|
// NewDedupSource creates a new dedupSource wrapping the provided Source.
|
|
func NewDedupSource(source source.Source) source.Source {
|
|
return &dedupSource{source: source}
|
|
}
|
|
|
|
// Endpoints collects endpoints from its wrapped source and returns them without duplicates.
|
|
func (ms *dedupSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error) {
|
|
log.Debug("dedupSource: collecting endpoints and removing duplicates")
|
|
resetMetrics()
|
|
result := make([]*endpoint.Endpoint, 0)
|
|
collected := make(map[string]struct{})
|
|
|
|
endpoints, err := ms.source.Endpoints(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
for _, ep := range endpoints {
|
|
if ep == nil {
|
|
continue
|
|
}
|
|
|
|
// validate endpoint before normalization
|
|
if ok := ep.CheckEndpoint(); !ok {
|
|
log.Warnf("Skipping endpoint [%s:%s] due to invalid configuration [%s:%s]", ep.SetIdentifier, ep.DNSName, ep.RecordType, strings.Join(ep.Targets, ","))
|
|
invalidEndpoints.AddWithLabels(1, ep.RecordType, endpointSource(ep))
|
|
continue
|
|
}
|
|
|
|
if len(ep.Targets) > 1 {
|
|
ep.Targets = endpoint.NewTargets(ep.Targets...)
|
|
}
|
|
|
|
identifier := strings.Join([]string{ep.RecordType, ep.DNSName, ep.SetIdentifier, ep.Targets.String()}, "/")
|
|
|
|
if _, ok := collected[identifier]; ok {
|
|
log.Debugf("Removing duplicate endpoint %s", ep)
|
|
deduplicatedEndpoints.AddWithLabels(1, ep.RecordType, endpointSource(ep))
|
|
continue
|
|
}
|
|
|
|
collected[identifier] = struct{}{}
|
|
result = append(result, ep)
|
|
}
|
|
|
|
return result, nil
|
|
}
|
|
|
|
func (ms *dedupSource) AddEventHandler(ctx context.Context, handler func()) {
|
|
log.Debug("dedupSource: adding event handler")
|
|
ms.source.AddEventHandler(ctx, handler)
|
|
}
|