mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2026-02-28 21:41:01 +01:00
* feat(annotations): add custom annotation prefix support for split horizon DNS Add --annotation-prefix flag to allow customizing the annotation prefix used by external-dns. This enables split horizon DNS scenarios where multiple instances process different sets of annotations from the same Kubernetes resources. Changes: - Add AnnotationPrefix field to Config with validation - Convert annotation constants to variables that can be reconfigured - Add SetAnnotationPrefix() function to rebuild annotation keys - Integrate annotation prefix setting in controller startup - Update Helm chart with annotationPrefix value - Add comprehensive split horizon DNS documentation - Update FAQ with annotation prefix examples This maintains full backward compatibility - the default prefix remains "external-dns.alpha.kubernetes.io/". Co-Authored-By: Claude <noreply@anthropic.com> * docs(advanced): fix markdown formatting in split-horizon guide Add blank lines before code blocks to improve markdown rendering and comply with markdownlint rules. Co-Authored-By: Claude <noreply@anthropic.com> * docs(advanced): fix markdown formatting in split-horizon guide Co-Authored-By: Claude <noreply@anthropic.com> * docs(charts): regenerate Helm chart documentation Co-Authored-By: Claude <noreply@anthropic.com> * test: add AnnotationPrefix field to test configs Add missing AnnotationPrefix field to minimalConfig and overriddenConfig test configurations to match the new default value set in NewConfig(). Co-Authored-By: Claude <noreply@anthropic.com> * test(charts): update error pattern in json-schema test Update expected error message pattern to match current Helm validation output format. Co-Authored-By: Claude <noreply@anthropic.com> * refactor(annotations): remove init() for explicit initialization - Remove init() function from annotations package - Add explicit SetAnnotationPrefix() call in controller/execute.go - Remove annotation key aliases from source/source.go - Replace all alias usages with annotations.* references (348 changes in 28 files) - Add TestMain to existing test files (service_test.go, cloudflare_test.go) This change makes annotation initialization explicit and predictable, avoiding hidden global state initialization at import time. Co-Authored-By: Claude <noreply@anthropic.com> * docs: update changelog and mkdocs to include annotationPrefix and split horizon DNS Signed-off-by: Aleksei Sviridkin <f@lex.la> * docs(split-horizon): fix linting Signed-off-by: Aleksei Sviridkin <f@lex.la> * refactor(annotations): replace hardcoded annotation prefix with constant Replace all hardcoded "external-dns.alpha.kubernetes.io/" strings with annotations.DefaultAnnotationPrefix constant to establish a single source of truth. Changes: - Add DefaultAnnotationPrefix constant in source/annotations/annotations.go - Replace hardcoded string in controller/execute.go with constant reference - Replace hardcoded strings in pkg/apis/externaldns/types.go (2 occurrences) - Add helm unit tests for annotationPrefix value This eliminates string duplication and makes future changes easier. Co-Authored-By: Claude <noreply@anthropic.com> --------- Signed-off-by: Aleksei Sviridkin <f@lex.la> Co-authored-by: Claude <noreply@anthropic.com>
89 lines
3.4 KiB
Go
89 lines
3.4 KiB
Go
/*
|
|
Copyright 2025 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 annotations
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestSetAnnotationPrefix(t *testing.T) {
|
|
// Save original values
|
|
originalPrefix := AnnotationKeyPrefix
|
|
defer SetAnnotationPrefix(originalPrefix)
|
|
|
|
// Test custom prefix
|
|
customPrefix := "custom.io/"
|
|
SetAnnotationPrefix(customPrefix)
|
|
|
|
assert.Equal(t, customPrefix, AnnotationKeyPrefix)
|
|
assert.Equal(t, "custom.io/hostname", HostnameKey)
|
|
assert.Equal(t, "custom.io/internal-hostname", InternalHostnameKey)
|
|
assert.Equal(t, "custom.io/ttl", TtlKey)
|
|
assert.Equal(t, "custom.io/target", TargetKey)
|
|
assert.Equal(t, "custom.io/controller", ControllerKey)
|
|
assert.Equal(t, "custom.io/cloudflare-proxied", CloudflareProxiedKey)
|
|
assert.Equal(t, "custom.io/cloudflare-custom-hostname", CloudflareCustomHostnameKey)
|
|
assert.Equal(t, "custom.io/cloudflare-region-key", CloudflareRegionKey)
|
|
assert.Equal(t, "custom.io/cloudflare-record-comment", CloudflareRecordCommentKey)
|
|
assert.Equal(t, "custom.io/cloudflare-tags", CloudflareTagsKey)
|
|
assert.Equal(t, "custom.io/aws-", AWSPrefix)
|
|
assert.Equal(t, "custom.io/coredns-", CoreDNSPrefix)
|
|
assert.Equal(t, "custom.io/scw-", SCWPrefix)
|
|
assert.Equal(t, "custom.io/webhook-", WebhookPrefix)
|
|
assert.Equal(t, "custom.io/cloudflare-", CloudflarePrefix)
|
|
assert.Equal(t, "custom.io/set-identifier", SetIdentifierKey)
|
|
assert.Equal(t, "custom.io/alias", AliasKey)
|
|
assert.Equal(t, "custom.io/access", AccessKey)
|
|
assert.Equal(t, "custom.io/endpoints-type", EndpointsTypeKey)
|
|
assert.Equal(t, "custom.io/ingress", Ingress)
|
|
assert.Equal(t, "custom.io/ingress-hostname-source", IngressHostnameSourceKey)
|
|
|
|
// ControllerValue should remain constant
|
|
assert.Equal(t, "dns-controller", ControllerValue)
|
|
}
|
|
|
|
func TestDefaultAnnotationPrefix(t *testing.T) {
|
|
assert.Equal(t, "external-dns.alpha.kubernetes.io/", AnnotationKeyPrefix)
|
|
assert.Equal(t, "external-dns.alpha.kubernetes.io/hostname", HostnameKey)
|
|
assert.Equal(t, "external-dns.alpha.kubernetes.io/internal-hostname", InternalHostnameKey)
|
|
assert.Equal(t, "external-dns.alpha.kubernetes.io/ttl", TtlKey)
|
|
assert.Equal(t, "external-dns.alpha.kubernetes.io/controller", ControllerKey)
|
|
}
|
|
|
|
func TestSetAnnotationPrefixMultipleTimes(t *testing.T) {
|
|
// Save original values
|
|
originalPrefix := AnnotationKeyPrefix
|
|
defer SetAnnotationPrefix(originalPrefix)
|
|
|
|
// Set first custom prefix
|
|
SetAnnotationPrefix("first.io/")
|
|
assert.Equal(t, "first.io/", AnnotationKeyPrefix)
|
|
assert.Equal(t, "first.io/hostname", HostnameKey)
|
|
|
|
// Set second custom prefix
|
|
SetAnnotationPrefix("second.io/")
|
|
assert.Equal(t, "second.io/", AnnotationKeyPrefix)
|
|
assert.Equal(t, "second.io/hostname", HostnameKey)
|
|
|
|
// Restore to default
|
|
SetAnnotationPrefix("external-dns.alpha.kubernetes.io/")
|
|
assert.Equal(t, "external-dns.alpha.kubernetes.io/", AnnotationKeyPrefix)
|
|
assert.Equal(t, "external-dns.alpha.kubernetes.io/hostname", HostnameKey)
|
|
}
|