diff --git a/provider/cloudflare/cloudflare_test.go b/provider/cloudflare/cloudflare_test.go index d9b6de2eaf..7f06c7fa60 100644 --- a/provider/cloudflare/cloudflare_test.go +++ b/provider/cloudflare/cloudflare_test.go @@ -42,13 +42,6 @@ import ( "sigs.k8s.io/external-dns/source/annotations" ) -// TestMain initializes annotation keys before running tests. -// This is needed because init() was removed from annotations package. -func TestMain(m *testing.M) { - annotations.SetAnnotationPrefix("external-dns.alpha.kubernetes.io/") - m.Run() -} - // newCloudflareError creates a cloudflare.Error suitable for testing. // The v5 SDK's Error type panics when .Error() is called with nil Request/Response fields, // so this helper initializes them properly. diff --git a/source/annotations/annotations.go b/source/annotations/annotations.go index ebe4ba548c..5248c69bf4 100644 --- a/source/annotations/annotations.go +++ b/source/annotations/annotations.go @@ -31,41 +31,41 @@ var ( AnnotationKeyPrefix = DefaultAnnotationPrefix // CloudflareProxiedKey The annotation used for determining if traffic will go through Cloudflare - CloudflareProxiedKey string - CloudflareCustomHostnameKey string - CloudflareRegionKey string - CloudflareRecordCommentKey string - CloudflareTagsKey string + CloudflareProxiedKey = AnnotationKeyPrefix + "cloudflare-proxied" + CloudflareCustomHostnameKey = AnnotationKeyPrefix + "cloudflare-custom-hostname" + CloudflareRegionKey = AnnotationKeyPrefix + "cloudflare-region-key" + CloudflareRecordCommentKey = AnnotationKeyPrefix + "cloudflare-record-comment" + CloudflareTagsKey = AnnotationKeyPrefix + "cloudflare-tags" - AWSPrefix string - CoreDNSPrefix string - SCWPrefix string - WebhookPrefix string - CloudflarePrefix string + AWSPrefix = AnnotationKeyPrefix + "aws-" + CoreDNSPrefix = AnnotationKeyPrefix + "coredns-" + SCWPrefix = AnnotationKeyPrefix + "scw-" + WebhookPrefix = AnnotationKeyPrefix + "webhook-" + CloudflarePrefix = AnnotationKeyPrefix + "cloudflare-" - TtlKey string - SetIdentifierKey string - AliasKey string - TargetKey string + TtlKey = AnnotationKeyPrefix + "ttl" + SetIdentifierKey = AnnotationKeyPrefix + "set-identifier" + AliasKey = AnnotationKeyPrefix + "alias" + TargetKey = AnnotationKeyPrefix + "target" // ControllerKey The annotation used for figuring out which controller is responsible - ControllerKey string + ControllerKey = AnnotationKeyPrefix + "controller" // HostnameKey The annotation used for defining the desired hostname - HostnameKey string + HostnameKey = AnnotationKeyPrefix + "hostname" // AccessKey The annotation used for specifying whether the public or private interface address is used - AccessKey string + AccessKey = AnnotationKeyPrefix + "access" // EndpointsTypeKey The annotation used for specifying the type of endpoints to use for headless services - EndpointsTypeKey string + EndpointsTypeKey = AnnotationKeyPrefix + "endpoints-type" // Ingress the annotation used to determine if the gateway is implemented by an Ingress object - Ingress string + Ingress = AnnotationKeyPrefix + "ingress" // IngressHostnameSourceKey The annotation used to determine the source of hostnames for ingresses. This is an optional field - all // available hostname sources are used if not specified. - IngressHostnameSourceKey string + IngressHostnameSourceKey = AnnotationKeyPrefix + "ingress-hostname-source" // ControllerValue The value of the controller annotation so that we feel responsible ControllerValue = "dns-controller" // InternalHostnameKey The annotation used for defining the desired hostname - InternalHostnameKey string + InternalHostnameKey = AnnotationKeyPrefix + "internal-hostname" // The annotation used for defining the desired hostname source for gateways - GatewayHostnameSourceKey string + GatewayHostnameSourceKey = AnnotationKeyPrefix + "gateway-hostname-source" ) // SetAnnotationPrefix sets a custom annotation prefix and rebuilds all annotation keys. diff --git a/source/annotations/annotations_test.go b/source/annotations/annotations_test.go index 79fde9f1d7..def2506fe7 100644 --- a/source/annotations/annotations_test.go +++ b/source/annotations/annotations_test.go @@ -23,9 +23,7 @@ import ( ) func TestSetAnnotationPrefix(t *testing.T) { - // Save original values - originalPrefix := AnnotationKeyPrefix - defer SetAnnotationPrefix(originalPrefix) + t.Cleanup(func() { SetAnnotationPrefix(DefaultAnnotationPrefix) }) // Test custom prefix customPrefix := "custom.io/" @@ -59,17 +57,17 @@ func TestSetAnnotationPrefix(t *testing.T) { } 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) + t.Cleanup(func() { SetAnnotationPrefix(DefaultAnnotationPrefix) }) + SetAnnotationPrefix(DefaultAnnotationPrefix) + assert.Equal(t, DefaultAnnotationPrefix, AnnotationKeyPrefix) + assert.Equal(t, DefaultAnnotationPrefix+"hostname", HostnameKey) + assert.Equal(t, DefaultAnnotationPrefix+"internal-hostname", InternalHostnameKey) + assert.Equal(t, DefaultAnnotationPrefix+"ttl", TtlKey) + assert.Equal(t, DefaultAnnotationPrefix+"controller", ControllerKey) } func TestSetAnnotationPrefixMultipleTimes(t *testing.T) { - // Save original values - originalPrefix := AnnotationKeyPrefix - defer SetAnnotationPrefix(originalPrefix) + t.Cleanup(func() { SetAnnotationPrefix(DefaultAnnotationPrefix) }) // Set first custom prefix SetAnnotationPrefix("first.io/") @@ -82,7 +80,7 @@ func TestSetAnnotationPrefixMultipleTimes(t *testing.T) { 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) + SetAnnotationPrefix(DefaultAnnotationPrefix) + assert.Equal(t, DefaultAnnotationPrefix, AnnotationKeyPrefix) + assert.Equal(t, DefaultAnnotationPrefix+"hostname", HostnameKey) } diff --git a/source/annotations/processors_test.go b/source/annotations/processors_test.go index 1333000247..89c02ec03f 100644 --- a/source/annotations/processors_test.go +++ b/source/annotations/processors_test.go @@ -366,8 +366,6 @@ func TestInternalHostnamesFromAnnotations(t *testing.T) { } func TestIsControllerMismatch(t *testing.T) { - SetAnnotationPrefix(DefaultAnnotationPrefix) - tests := []struct { name string annotations map[string]string diff --git a/source/service_test.go b/source/service_test.go index 18886ebc18..e6666dd376 100644 --- a/source/service_test.go +++ b/source/service_test.go @@ -45,13 +45,6 @@ import ( "sigs.k8s.io/external-dns/source/informers" ) -// TestMain initializes annotation keys before running tests. -// This is needed because init() was removed from annotations package. -func TestMain(m *testing.M) { - annotations.SetAnnotationPrefix("external-dns.alpha.kubernetes.io/") - m.Run() -} - type ServiceSuite struct { suite.Suite sc Source