diff --git a/charts/external-dns/CHANGELOG.md b/charts/external-dns/CHANGELOG.md index 879565eb30..309452b022 100644 --- a/charts/external-dns/CHANGELOG.md +++ b/charts/external-dns/CHANGELOG.md @@ -18,6 +18,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [UNRELEASED] +### Added + +- Add option to set `annotationPrefix` ([#5889](https://github.com/kubernetes-sigs/external-dns/pull/5889)) _@lexfrei_ + ## [v1.19.0] - 2025-09-08 ### Added diff --git a/charts/external-dns/README.md b/charts/external-dns/README.md index c147cc7bee..5afc26cb43 100644 --- a/charts/external-dns/README.md +++ b/charts/external-dns/README.md @@ -95,6 +95,7 @@ If `namespaced` is set to `true`, please ensure that `sources` my only contains |-----|------|---------|-------------| | affinity | object | `{}` | Affinity settings for `Pod` [scheduling](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/). If an explicit label selector is not provided for pod affinity or pod anti-affinity one will be created from the pod selector labels. | | annotationFilter | string | `nil` | Filter resources queried for endpoints by annotation selector. | +| annotationPrefix | string | `nil` | Annotation prefix for external-dns annotations (useful for split horizon DNS with multiple instances). | | automountServiceAccountToken | bool | `true` | Set this to `false` to [opt out of API credential automounting](https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/#opt-out-of-api-credential-automounting) for the `Pod`. | | commonLabels | object | `{}` | Labels to add to all chart resources. | | deploymentAnnotations | object | `{}` | Annotations to add to the `Deployment`. | diff --git a/charts/external-dns/templates/deployment.yaml b/charts/external-dns/templates/deployment.yaml index 70f231fb4a..1d0496d3c1 100644 --- a/charts/external-dns/templates/deployment.yaml +++ b/charts/external-dns/templates/deployment.yaml @@ -126,6 +126,9 @@ spec: {{- if .Values.annotationFilter }} - --annotation-filter={{ .Values.annotationFilter }} {{- end }} + {{- if .Values.annotationPrefix }} + - --annotation-prefix={{ .Values.annotationPrefix }} + {{- end }} {{- range .Values.managedRecordTypes }} - --managed-record-types={{ . }} {{- end }} diff --git a/charts/external-dns/tests/deployment-flags_test.yaml b/charts/external-dns/tests/deployment-flags_test.yaml index 5b86502f80..5ea1115304 100644 --- a/charts/external-dns/tests/deployment-flags_test.yaml +++ b/charts/external-dns/tests/deployment-flags_test.yaml @@ -164,3 +164,41 @@ tests: asserts: - failedTemplate: errorMessage: "'txtPrefix' and 'txtSuffix' are mutually exclusive" + + - it: should configure custom annotation prefix + set: + annotationPrefix: "custom.io/" + asserts: + - contains: + path: spec.template.spec.containers[?(@.name == "external-dns")].args + content: "--annotation-prefix=custom.io/" + + - it: should not include annotation-prefix flag when not set + set: + annotationPrefix: null + asserts: + - notContains: + path: spec.template.spec.containers[?(@.name == "external-dns")].args + content: "--annotation-prefix" + + - it: should configure annotation prefix with other flags + set: + annotationPrefix: "internal.company.io/" + provider: + name: cloudflare + sources: + - service + - ingress + asserts: + - contains: + path: spec.template.spec.containers[?(@.name == "external-dns")].args + content: "--annotation-prefix=internal.company.io/" + - contains: + path: spec.template.spec.containers[?(@.name == "external-dns")].args + content: "--provider=cloudflare" + - contains: + path: spec.template.spec.containers[?(@.name == "external-dns")].args + content: "--source=service" + - contains: + path: spec.template.spec.containers[?(@.name == "external-dns")].args + content: "--source=ingress" diff --git a/charts/external-dns/tests/json-schema_test.yaml b/charts/external-dns/tests/json-schema_test.yaml index 68b9b6ba3d..85e29e5404 100644 --- a/charts/external-dns/tests/json-schema_test.yaml +++ b/charts/external-dns/tests/json-schema_test.yaml @@ -30,7 +30,7 @@ tests: enabled: "abrakadabra" asserts: - failedTemplate: - errorPattern: "Invalid type. Expected: [boolean,null], given: string" + errorPattern: "got string, want null or boolean" - it: should fail if provider is null set: diff --git a/charts/external-dns/values.schema.json b/charts/external-dns/values.schema.json index 22bfef2ab5..ca698c0db0 100644 --- a/charts/external-dns/values.schema.json +++ b/charts/external-dns/values.schema.json @@ -13,6 +13,13 @@ "null" ] }, + "annotationPrefix": { + "description": "Annotation prefix for external-dns annotations (useful for split horizon DNS with multiple instances).", + "type": [ + "string", + "null" + ] + }, "automountServiceAccountToken": { "description": "Set this to `false` to [opt out of API credential automounting](https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/#opt-out-of-api-credential-automounting) for the `Pod`.", "type": "boolean" diff --git a/charts/external-dns/values.yaml b/charts/external-dns/values.yaml index 9b9292c512..5c5f9fe364 100644 --- a/charts/external-dns/values.yaml +++ b/charts/external-dns/values.yaml @@ -240,6 +240,9 @@ labelFilter: # @schema type: [string,null]; default: null # -- Filter resources queried for endpoints by annotation selector. annotationFilter: # @schema type: [string,null]; default: null +# -- Annotation prefix for external-dns annotations (useful for split horizon DNS with multiple instances). +annotationPrefix: # @schema type: [string,null]; default: null + # -- Record types to manage (default: A, AAAA, CNAME) managedRecordTypes: [] # @schema type: [array, null]; item: string; uniqueItems: true diff --git a/controller/execute.go b/controller/execute.go index bb7ebc5440..8f9f2b6539 100644 --- a/controller/execute.go +++ b/controller/execute.go @@ -69,6 +69,7 @@ import ( webhookapi "sigs.k8s.io/external-dns/provider/webhook/api" "sigs.k8s.io/external-dns/registry" "sigs.k8s.io/external-dns/source" + "sigs.k8s.io/external-dns/source/annotations" "sigs.k8s.io/external-dns/source/wrappers" ) @@ -82,6 +83,12 @@ func Execute() { log.Fatalf("config validation failed: %v", err) } + // Set annotation prefix (required since init() was removed) + annotations.SetAnnotationPrefix(cfg.AnnotationPrefix) + if cfg.AnnotationPrefix != annotations.DefaultAnnotationPrefix { + log.Infof("Using custom annotation prefix: %s", cfg.AnnotationPrefix) + } + configureLogger(cfg) if cfg.DryRun { diff --git a/docs/advanced/split-horizon.md b/docs/advanced/split-horizon.md new file mode 100644 index 0000000000..4bc296cec8 --- /dev/null +++ b/docs/advanced/split-horizon.md @@ -0,0 +1,274 @@ +# Split Horizon DNS + +Split horizon DNS allows you to serve different DNS responses based on the client's location - internal clients receive private IPs while external clients receive public IPs. External-DNS supports split horizon DNS by running multiple instances with different annotation prefixes. + +## Overview + +By default, all external-dns instances use the same annotation prefix: `external-dns.alpha.kubernetes.io/`. This means all instances process the same annotations. To enable split horizon DNS, you can configure each instance to use a different annotation prefix via the `--annotation-prefix` flag. + +## Use Cases + +- **Internal/External separation**: Internal DNS points to private IPs (ClusterIP), external DNS points to public Load Balancer IPs +- **Multiple DNS providers**: Route different services to different DNS providers (e.g., internal to CoreDNS, external to Route53) +- **Geographic split**: Different DNS records for different regions + +## Configuration + +### Basic Split Horizon Setup + +**Internal DNS Instance:** + +```bash +external-dns \ + --annotation-prefix=internal.company.io/ \ + --source=service \ + --source=ingress \ + --provider=aws \ + --aws-zone-type=private \ + --domain-filter=internal.company.com \ + --txt-owner-id=internal-dns +``` + +**External DNS Instance:** + +```bash +external-dns \ + --annotation-prefix=external-dns.alpha.kubernetes.io/ \ # default, can be omitted + --source=service \ + --source=ingress \ + --provider=aws \ + --aws-zone-type=public \ + --domain-filter=company.com \ + --txt-owner-id=external-dns +``` + +### Service with Both Annotations + +```yaml +apiVersion: v1 +kind: Service +metadata: + name: myapp + annotations: + # Internal DNS reads this + internal.company.io/hostname: myapp.internal.company.com + internal.company.io/ttl: "300" + internal.company.io/target: 10.0.1.50 # Private IP + + # External DNS reads this + external-dns.alpha.kubernetes.io/hostname: myapp.company.com + external-dns.alpha.kubernetes.io/ttl: "60" + # No target = uses LoadBalancer IP automatically +spec: + type: LoadBalancer + clusterIP: 10.0.1.50 + ports: + - port: 80 + targetPort: 8080 + selector: + app: myapp +``` + +**Result:** + +- **Internal DNS** (Route53 Private Zone `internal.company.com`): `myapp.internal.company.com → 10.0.1.50` +- **External DNS** (Route53 Public Zone `company.com`): `myapp.company.com → 203.0.113.10` (LoadBalancer IP) + +### Helm Chart Configuration + +You can use the Helm chart to deploy multiple instances: + +**values-internal.yaml:** + +```yaml +annotationPrefix: "internal.company.io/" + +provider: + name: aws + +aws: + zoneType: private + +domainFilters: + - internal.company.com + +txtOwnerId: internal-dns + +sources: + - service + - ingress +``` + +**values-external.yaml:** + +```yaml +# annotationPrefix defaults to "external-dns.alpha.kubernetes.io/" +# can be omitted or set explicitly: +# annotationPrefix: "external-dns.alpha.kubernetes.io/" + +provider: + name: aws + +aws: + zoneType: public + +domainFilters: + - company.com + +txtOwnerId: external-dns + +sources: + - service + - ingress +``` + +**Deploy:** + +```bash +# Internal instance +helm install external-dns-internal external-dns/external-dns \ + --namespace external-dns-internal \ + --create-namespace \ + --values values-internal.yaml + +# External instance +helm install external-dns-external external-dns/external-dns \ + --namespace external-dns-external \ + --create-namespace \ + --values values-external.yaml +``` + +## Advanced Examples + +### Three-Way Split (Internal / DMZ / External) + +```yaml +apiVersion: v1 +kind: Service +metadata: + name: api + annotations: + # Internal (private network only) + internal.company.io/hostname: api.internal.company.com + internal.company.io/ttl: "300" + + # DMZ (accessible from office network) + dmz.company.io/hostname: api.dmz.company.com + dmz.company.io/ttl: "120" + + # External (public internet) + external-dns.alpha.kubernetes.io/hostname: api.company.com + external-dns.alpha.kubernetes.io/ttl: "60" + external-dns.alpha.kubernetes.io/cloudflare-proxied: "true" +spec: + type: LoadBalancer + # ... +``` + +**Deploy three instances:** + +```bash +# Internal +--annotation-prefix=internal.company.io/ --provider=aws --aws-zone-type=private + +# DMZ +--annotation-prefix=dmz.company.io/ --provider=aws --aws-zone-type=private + +# External +--annotation-prefix=external-dns.alpha.kubernetes.io/ --provider=cloudflare +``` + +### Different Providers Per Instance + +```yaml +apiVersion: v1 +kind: Service +metadata: + name: webapp + annotations: + # Route53 for AWS internal + aws.company.io/hostname: webapp.aws.company.com + aws.company.io/aws-alias: "true" + + # Cloudflare for public + cf.company.io/hostname: webapp.company.com + cf.company.io/cloudflare-proxied: "true" +spec: + type: LoadBalancer + # ... +``` + +**Deploy:** + +```bash +# AWS instance +--annotation-prefix=aws.company.io/ --provider=aws + +# Cloudflare instance +--annotation-prefix=cf.company.io/ --provider=cloudflare +``` + +## Important Notes + +1. **Annotation prefix must end with `/`** - The validation will fail if the prefix doesn't end with a forward slash. +2. **Backward compatibility** - If you don't specify `--annotation-prefix`, the default `external-dns.alpha.kubernetes.io/` is used, maintaining full backward compatibility. +3. **All annotations use the same prefix** - When you set a custom prefix, ALL external-dns annotations (hostname, ttl, target, cloudflare-proxied, etc.) must use that prefix. +4. **TXT ownership records** - Each instance should have a unique `--txt-owner-id` to avoid conflicts in ownership tracking. +5. **Provider-specific annotations** - Provider-specific annotations (like `cloudflare-proxied`, `aws-alias`) also use the custom prefix: + +```yaml +custom.io/hostname: example.com +custom.io/cloudflare-proxied: "true" # NOT external-dns.alpha.kubernetes.io/cloudflare-proxied +``` + +## Troubleshooting + +### Both instances processing the same resources + +**Problem:** Both internal and external instances are creating records for the same service. + +**Solution:** Make sure you're using different annotation prefixes and that your services have the correct annotations: + +```yaml +# ✅ Correct - different prefixes +internal.company.io/hostname: internal.example.com +external-dns.alpha.kubernetes.io/hostname: example.com + +# ❌ Wrong - same prefix +external-dns.alpha.kubernetes.io/hostname: internal.example.com +external-dns.alpha.kubernetes.io/hostname: example.com # Second one overwrites first +``` + +### Validation error: "annotation-prefix must end with '/'" + +**Problem:** The annotation prefix doesn't end with a forward slash. + +**Solution:** Always end your custom prefix with `/`: + +```bash +# ✅ Correct +--annotation-prefix=custom.io/ + +# ❌ Wrong +--annotation-prefix=custom.io +``` + +### Provider-specific annotations not working + +**Problem:** Cloudflare/AWS-specific annotations are not being applied. + +**Solution:** Provider-specific annotations must use the same prefix as the hostname: + +```yaml +# If using custom prefix +custom.io/hostname: example.com +custom.io/cloudflare-proxied: "true" +custom.io/ttl: "60" +``` + +## See Also + +- [Configuration Precedence](configuration-precedence.md) - Understanding how external-dns processes configuration +- [FAQ](../faq.md) - Frequently asked questions +- [AWS Provider](../tutorials/aws.md) - AWS Route53 configuration +- [Cloudflare Provider](../tutorials/cloudflare.md) - Cloudflare configuration diff --git a/docs/faq.md b/docs/faq.md index 090938caf4..1cf92f6543 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -269,6 +269,31 @@ In larger clusters with many resources which change frequently this can cause pe If only some resources need to be managed by an instance of external-dns then label filtering can be used instead of ingress class filtering (or legacy annotation filtering). This means that only those resources which match the selector specified in `--label-filter` will be passed to the controller. +**Split horizon DNS with custom annotation prefixes** + +For more advanced split horizon scenarios, you can use the `--annotation-prefix` flag to configure different instances to read different sets of annotations from the same resources. This is useful when you want a single Service or Ingress to create records in multiple DNS zones (e.g., internal and external). + +For example: + +```bash +# Internal DNS instance +--annotation-prefix=internal.company.io/ --provider=aws --aws-zone-type=private + +# External DNS instance +--annotation-prefix=external-dns.alpha.kubernetes.io/ --provider=aws --aws-zone-type=public +``` + +Then annotate your resources with both prefixes: + +```yaml +metadata: + annotations: + internal.company.io/hostname: app.internal.company.com + external-dns.alpha.kubernetes.io/hostname: app.company.com +``` + +See the [Split Horizon DNS guide](advanced/split-horizon.md) for detailed examples and configuration. + ## How do I specify that I want the DNS record to point to either the Node's public or private IP when it has both? If your Nodes have both public and private IP addresses, you might want to write DNS records with one or the other. diff --git a/docs/flags.md b/docs/flags.md index f03026c99f..5c41ca7497 100644 --- a/docs/flags.md +++ b/docs/flags.md @@ -19,6 +19,7 @@ | `--skipper-routegroup-groupversion="zalando.org/v1"` | The resource version for skipper routegroup | | `--[no-]always-publish-not-ready-addresses` | Always publish also not ready addresses for headless services (optional) | | `--annotation-filter=""` | Filter resources queried for endpoints by annotation, using label selector semantics | +| `--annotation-prefix="external-dns.alpha.kubernetes.io/"` | Annotation prefix for external-dns annotations (default: external-dns.alpha.kubernetes.io/) | | `--[no-]combine-fqdn-annotation` | Combine FQDN template and Annotations instead of overwriting (default: false) | | `--compatibility=` | Process annotation semantics from legacy implementations (optional, options: mate, molecule, kops-dns-controller) | | `--connector-source-server="localhost:8080"` | The server to connect for connector source, valid only when using connector source | diff --git a/mkdocs.yml b/mkdocs.yml index ba43d28930..38966a665f 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -38,6 +38,7 @@ nav: - TTL: docs/advanced/ttl.md - Decisions: docs/proposal/0*.md - Configuration Precedence: docs/advanced/configuration-precedence.md + - Split Horizon DNS: docs/advanced/split-horizon.md - Contributing: - Kubernetes Contributions: CONTRIBUTING.md - Release: docs/release.md diff --git a/pkg/apis/externaldns/types.go b/pkg/apis/externaldns/types.go index c2fff68b3f..37dd5d87ec 100644 --- a/pkg/apis/externaldns/types.go +++ b/pkg/apis/externaldns/types.go @@ -27,6 +27,7 @@ import ( "k8s.io/apimachinery/pkg/labels" "sigs.k8s.io/external-dns/endpoint" + "sigs.k8s.io/external-dns/source/annotations" "github.com/alecthomas/kingpin/v2" "github.com/sirupsen/logrus" @@ -48,6 +49,7 @@ type Config struct { Sources []string Namespace string AnnotationFilter string + AnnotationPrefix string LabelFilter string IngressClassNames []string FQDNTemplate string @@ -229,6 +231,7 @@ var defaultConfig = &Config{ AkamaiServiceConsumerDomain: "", AlibabaCloudConfigFile: "/etc/kubernetes/alibaba-cloud.json", AnnotationFilter: "", + AnnotationPrefix: annotations.DefaultAnnotationPrefix, APIServerURL: "", AWSAPIRetries: 3, AWSAssumeRole: "", @@ -449,7 +452,8 @@ var allowedSources = []string{ // NewConfig returns new Config object func NewConfig() *Config { return &Config{ - AWSSDCreateTag: map[string]string{}, + AnnotationPrefix: annotations.DefaultAnnotationPrefix, + AWSSDCreateTag: map[string]string{}, } } @@ -609,6 +613,7 @@ func bindFlags(b FlagBinder, cfg *Config) { // Flags related to processing source b.BoolVar("always-publish-not-ready-addresses", "Always publish also not ready addresses for headless services (optional)", false, &cfg.AlwaysPublishNotReadyAddresses) b.StringVar("annotation-filter", "Filter resources queried for endpoints by annotation, using label selector semantics", defaultConfig.AnnotationFilter, &cfg.AnnotationFilter) + b.StringVar("annotation-prefix", "Annotation prefix for external-dns annotations (default: external-dns.alpha.kubernetes.io/)", defaultConfig.AnnotationPrefix, &cfg.AnnotationPrefix) b.BoolVar("combine-fqdn-annotation", "Combine FQDN template and Annotations instead of overwriting (default: false)", false, &cfg.CombineFQDNAndAnnotation) b.EnumVar("compatibility", "Process annotation semantics from legacy implementations (optional, options: mate, molecule, kops-dns-controller)", defaultConfig.Compatibility, &cfg.Compatibility, "", "mate", "molecule", "kops-dns-controller") b.StringVar("connector-source-server", "The server to connect for connector source, valid only when using connector source", defaultConfig.ConnectorSourceServer, &cfg.ConnectorSourceServer) diff --git a/pkg/apis/externaldns/types_test.go b/pkg/apis/externaldns/types_test.go index 5a6d7f96c2..c27da01f92 100644 --- a/pkg/apis/externaldns/types_test.go +++ b/pkg/apis/externaldns/types_test.go @@ -43,6 +43,7 @@ var ( SkipperRouteGroupVersion: "zalando.org/v1", Sources: []string{"service"}, Namespace: "", + AnnotationPrefix: "external-dns.alpha.kubernetes.io/", FQDNTemplate: "", Compatibility: "", Provider: "google", @@ -145,6 +146,7 @@ var ( SkipperRouteGroupVersion: "zalando.org/v2", Sources: []string{"service", "ingress", "connector"}, Namespace: "namespace", + AnnotationPrefix: "external-dns.alpha.kubernetes.io/", IgnoreHostnameAnnotation: true, IgnoreNonHostNetworkPods: true, IgnoreIngressTLSSpec: true, diff --git a/pkg/apis/externaldns/validation/validation.go b/pkg/apis/externaldns/validation/validation.go index df8edccc1b..0aed0c75b0 100644 --- a/pkg/apis/externaldns/validation/validation.go +++ b/pkg/apis/externaldns/validation/validation.go @@ -19,6 +19,7 @@ package validation import ( "errors" "fmt" + "strings" "k8s.io/apimachinery/pkg/labels" @@ -49,6 +50,14 @@ func ValidateConfig(cfg *externaldns.Config) error { if err != nil { return errors.New("--label-filter does not specify a valid label selector") } + + if cfg.AnnotationPrefix == "" { + return errors.New("--annotation-prefix cannot be empty") + } + if !strings.HasSuffix(cfg.AnnotationPrefix, "/") { + return errors.New("--annotation-prefix must end with '/'") + } + return nil } diff --git a/pkg/apis/externaldns/validation/validation_test.go b/pkg/apis/externaldns/validation/validation_test.go index 480220e682..afa8d9a157 100644 --- a/pkg/apis/externaldns/validation/validation_test.go +++ b/pkg/apis/externaldns/validation/validation_test.go @@ -72,6 +72,22 @@ func TestValidateFlags(t *testing.T) { cfg = newValidConfig(t) cfg.LabelFilter = "#invalid-selector" require.Error(t, ValidateConfig(cfg)) + + cfg = newValidConfig(t) + cfg.AnnotationPrefix = "" + require.Error(t, ValidateConfig(cfg)) + + cfg = newValidConfig(t) + cfg.AnnotationPrefix = "custom.io" + require.Error(t, ValidateConfig(cfg)) + + cfg = newValidConfig(t) + cfg.AnnotationPrefix = "custom.io/" + require.NoError(t, ValidateConfig(cfg)) + + cfg = newValidConfig(t) + cfg.AnnotationPrefix = "external-dns.alpha.kubernetes.io/" + require.NoError(t, ValidateConfig(cfg)) } func newValidConfig(t *testing.T) *externaldns.Config { @@ -143,6 +159,7 @@ func TestValidateBadRfc2136GssTsigConfig(t *testing.T) { LogFormat: "json", Sources: []string{"test-source"}, Provider: "rfc2136", + AnnotationPrefix: "external-dns.alpha.kubernetes.io/", RFC2136GSSTSIG: true, RFC2136KerberosRealm: "test-realm", RFC2136KerberosUsername: "test-user", @@ -154,6 +171,7 @@ func TestValidateBadRfc2136GssTsigConfig(t *testing.T) { LogFormat: "json", Sources: []string{"test-source"}, Provider: "rfc2136", + AnnotationPrefix: "external-dns.alpha.kubernetes.io/", RFC2136GSSTSIG: true, RFC2136KerberosRealm: "test-realm", RFC2136KerberosUsername: "", @@ -165,6 +183,7 @@ func TestValidateBadRfc2136GssTsigConfig(t *testing.T) { LogFormat: "json", Sources: []string{"test-source"}, Provider: "rfc2136", + AnnotationPrefix: "external-dns.alpha.kubernetes.io/", RFC2136GSSTSIG: true, RFC2136Insecure: true, RFC2136KerberosRealm: "test-realm", @@ -177,6 +196,7 @@ func TestValidateBadRfc2136GssTsigConfig(t *testing.T) { LogFormat: "json", Sources: []string{"test-source"}, Provider: "rfc2136", + AnnotationPrefix: "external-dns.alpha.kubernetes.io/", RFC2136GSSTSIG: true, RFC2136KerberosRealm: "", RFC2136KerberosUsername: "test-user", @@ -188,6 +208,7 @@ func TestValidateBadRfc2136GssTsigConfig(t *testing.T) { LogFormat: "json", Sources: []string{"test-source"}, Provider: "rfc2136", + AnnotationPrefix: "external-dns.alpha.kubernetes.io/", RFC2136GSSTSIG: true, RFC2136KerberosRealm: "", RFC2136KerberosUsername: "", @@ -199,6 +220,7 @@ func TestValidateBadRfc2136GssTsigConfig(t *testing.T) { LogFormat: "json", Sources: []string{"test-source"}, Provider: "rfc2136", + AnnotationPrefix: "external-dns.alpha.kubernetes.io/", RFC2136GSSTSIG: true, RFC2136Insecure: true, RFC2136KerberosRealm: "", @@ -211,6 +233,7 @@ func TestValidateBadRfc2136GssTsigConfig(t *testing.T) { LogFormat: "json", Sources: []string{"test-source"}, Provider: "rfc2136", + AnnotationPrefix: "external-dns.alpha.kubernetes.io/", RFC2136GSSTSIG: true, RFC2136KerberosRealm: "", RFC2136KerberosUsername: "test-user", @@ -233,6 +256,7 @@ func TestValidateGoodRfc2136GssTsigConfig(t *testing.T) { LogFormat: "json", Sources: []string{"test-source"}, Provider: "rfc2136", + AnnotationPrefix: "external-dns.alpha.kubernetes.io/", RFC2136GSSTSIG: true, RFC2136Insecure: false, RFC2136KerberosRealm: "test-realm", @@ -256,6 +280,7 @@ func TestValidateBadAkamaiConfig(t *testing.T) { LogFormat: "json", Sources: []string{"test-source"}, Provider: "akamai", + AnnotationPrefix: "external-dns.alpha.kubernetes.io/", AkamaiClientToken: "test-token", AkamaiClientSecret: "test-secret", AkamaiAccessToken: "test-access-token", @@ -266,6 +291,7 @@ func TestValidateBadAkamaiConfig(t *testing.T) { LogFormat: "json", Sources: []string{"test-source"}, Provider: "akamai", + AnnotationPrefix: "external-dns.alpha.kubernetes.io/", AkamaiServiceConsumerDomain: "test-domain", AkamaiClientSecret: "test-secret", AkamaiAccessToken: "test-access-token", @@ -276,6 +302,7 @@ func TestValidateBadAkamaiConfig(t *testing.T) { LogFormat: "json", Sources: []string{"test-source"}, Provider: "akamai", + AnnotationPrefix: "external-dns.alpha.kubernetes.io/", AkamaiServiceConsumerDomain: "test-domain", AkamaiClientToken: "test-token", AkamaiAccessToken: "test-access-token", @@ -286,6 +313,7 @@ func TestValidateBadAkamaiConfig(t *testing.T) { LogFormat: "json", Sources: []string{"test-source"}, Provider: "akamai", + AnnotationPrefix: "external-dns.alpha.kubernetes.io/", AkamaiServiceConsumerDomain: "test-domain", AkamaiClientToken: "test-token", AkamaiClientSecret: "test-secret", @@ -306,6 +334,7 @@ func TestValidateGoodAkamaiConfig(t *testing.T) { LogFormat: "json", Sources: []string{"test-source"}, Provider: "akamai", + AnnotationPrefix: "external-dns.alpha.kubernetes.io/", AkamaiServiceConsumerDomain: "test-domain", AkamaiClientToken: "test-token", AkamaiClientSecret: "test-secret", @@ -313,9 +342,10 @@ func TestValidateGoodAkamaiConfig(t *testing.T) { AkamaiEdgercPath: "/path/to/edgerc", }, { - LogFormat: "json", - Sources: []string{"test-source"}, - Provider: "akamai", + LogFormat: "json", + Sources: []string{"test-source"}, + Provider: "akamai", + AnnotationPrefix: "external-dns.alpha.kubernetes.io/", // All Akamai fields can be empty if AkamaiEdgercPath is not specified }, } @@ -332,6 +362,7 @@ func TestValidateBadAzureConfig(t *testing.T) { cfg.LogFormat = "json" cfg.Sources = []string{"test-source"} cfg.Provider = "azure" + cfg.AnnotationPrefix = "external-dns.alpha.kubernetes.io/" // AzureConfigFile is empty err := ValidateConfig(cfg) @@ -345,6 +376,7 @@ func TestValidateGoodAzureConfig(t *testing.T) { cfg.LogFormat = "json" cfg.Sources = []string{"test-source"} cfg.Provider = "azure" + cfg.AnnotationPrefix = "external-dns.alpha.kubernetes.io/" cfg.AzureConfigFile = "/path/to/azure.json" err := ValidateConfig(cfg) diff --git a/provider/cloudflare/cloudflare_test.go b/provider/cloudflare/cloudflare_test.go index 46b0294842..d11f8a5bce 100644 --- a/provider/cloudflare/cloudflare_test.go +++ b/provider/cloudflare/cloudflare_test.go @@ -43,6 +43,13 @@ 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() +} + type MockAction struct { Name string ZoneId string diff --git a/source/ambassador_host.go b/source/ambassador_host.go index 6b1da81957..bb072371d9 100644 --- a/source/ambassador_host.go +++ b/source/ambassador_host.go @@ -55,7 +55,7 @@ var ambHostGVR = schemeGroupVersion.WithResource("hosts") // ambassadorHostSource is an implementation of Source for Ambassador Host objects. // The IngressRoute implementation uses the spec.virtualHost.fqdn value for the hostname. -// Use targetAnnotationKey to explicitly set Endpoint. +// Use annotations.TargetKey to explicitly set Endpoint. type ambassadorHostSource struct { dynamicKubeClient dynamic.Interface kubeClient kubernetes.Interface diff --git a/source/ambassador_host_test.go b/source/ambassador_host_test.go index 561bc1e02a..1f9e84664a 100644 --- a/source/ambassador_host_test.go +++ b/source/ambassador_host_test.go @@ -179,8 +179,8 @@ func TestAmbassadorHostSource(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "basic-host", Annotations: map[string]string{ - ambHostAnnotation: hostAnnotation, - targetAnnotationKey: "3.3.3.3", + ambHostAnnotation: hostAnnotation, + annotations.TargetKey: "3.3.3.3", }, }, Spec: &ambassador.HostSpec{ @@ -213,8 +213,8 @@ func TestAmbassadorHostSource(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "basic-host", Annotations: map[string]string{ - ambHostAnnotation: hostAnnotation, - ttlAnnotationKey: "180", + ambHostAnnotation: hostAnnotation, + annotations.TtlKey: "180", }, }, Spec: &ambassador.HostSpec{ diff --git a/source/annotations/annotations.go b/source/annotations/annotations.go index 87d60241d7..73f916f232 100644 --- a/source/annotations/annotations.go +++ b/source/annotations/annotations.go @@ -18,45 +18,84 @@ import ( ) const ( + // DefaultAnnotationPrefix is the default annotation prefix used by external-dns + DefaultAnnotationPrefix = "external-dns.alpha.kubernetes.io/" + + ttlMinimum = 1 + ttlMaximum = math.MaxInt32 +) + +var ( // AnnotationKeyPrefix is set on all annotations consumed by external-dns (outside of user templates) - // to provide easy filtering. - AnnotationKeyPrefix = "external-dns.alpha.kubernetes.io/" + // to provide easy filtering. Can be customized via SetAnnotationPrefix. + AnnotationKeyPrefix = DefaultAnnotationPrefix // CloudflareProxiedKey The annotation used for determining if traffic will go through Cloudflare - CloudflareProxiedKey = AnnotationKeyPrefix + "cloudflare-proxied" - CloudflareCustomHostnameKey = AnnotationKeyPrefix + "cloudflare-custom-hostname" - CloudflareRegionKey = AnnotationKeyPrefix + "cloudflare-region-key" - CloudflareRecordCommentKey = AnnotationKeyPrefix + "cloudflare-record-comment" - CloudflareTagsKey = AnnotationKeyPrefix + "cloudflare-tags" - - AWSPrefix = AnnotationKeyPrefix + "aws-" - CoreDNSPrefix = AnnotationKeyPrefix + "coredns-" - SCWPrefix = AnnotationKeyPrefix + "scw-" - WebhookPrefix = AnnotationKeyPrefix + "webhook-" - CloudflarePrefix = AnnotationKeyPrefix + "cloudflare-" + CloudflareProxiedKey string + CloudflareCustomHostnameKey string + CloudflareRegionKey string + CloudflareRecordCommentKey string + CloudflareTagsKey string - TtlKey = AnnotationKeyPrefix + "ttl" - ttlMinimum = 1 - ttlMaximum = math.MaxInt32 + AWSPrefix string + CoreDNSPrefix string + SCWPrefix string + WebhookPrefix string + CloudflarePrefix string - SetIdentifierKey = AnnotationKeyPrefix + "set-identifier" - AliasKey = AnnotationKeyPrefix + "alias" - TargetKey = AnnotationKeyPrefix + "target" + TtlKey string + SetIdentifierKey string + AliasKey string + TargetKey string // ControllerKey The annotation used for figuring out which controller is responsible - ControllerKey = AnnotationKeyPrefix + "controller" + ControllerKey string // HostnameKey The annotation used for defining the desired hostname - HostnameKey = AnnotationKeyPrefix + "hostname" + HostnameKey string // AccessKey The annotation used for specifying whether the public or private interface address is used - AccessKey = AnnotationKeyPrefix + "access" + AccessKey string // EndpointsTypeKey The annotation used for specifying the type of endpoints to use for headless services - EndpointsTypeKey = AnnotationKeyPrefix + "endpoints-type" + EndpointsTypeKey string // Ingress the annotation used to determine if the gateway is implemented by an Ingress object - Ingress = AnnotationKeyPrefix + "ingress" + Ingress string // 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 = AnnotationKeyPrefix + "ingress-hostname-source" + IngressHostnameSourceKey string // 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 = AnnotationKeyPrefix + "internal-hostname" + InternalHostnameKey string ) + +// SetAnnotationPrefix sets a custom annotation prefix and rebuilds all annotation keys. +// This must be called before any sources are initialized. +// The prefix must end with '/'. +func SetAnnotationPrefix(prefix string) { + AnnotationKeyPrefix = prefix + + // Cloudflare annotations + CloudflareProxiedKey = AnnotationKeyPrefix + "cloudflare-proxied" + CloudflareCustomHostnameKey = AnnotationKeyPrefix + "cloudflare-custom-hostname" + CloudflareRegionKey = AnnotationKeyPrefix + "cloudflare-region-key" + CloudflareRecordCommentKey = AnnotationKeyPrefix + "cloudflare-record-comment" + CloudflareTagsKey = AnnotationKeyPrefix + "cloudflare-tags" + + // Provider prefixes + AWSPrefix = AnnotationKeyPrefix + "aws-" + CoreDNSPrefix = AnnotationKeyPrefix + "coredns-" + SCWPrefix = AnnotationKeyPrefix + "scw-" + WebhookPrefix = AnnotationKeyPrefix + "webhook-" + CloudflarePrefix = AnnotationKeyPrefix + "cloudflare-" + + // Core annotations + TtlKey = AnnotationKeyPrefix + "ttl" + SetIdentifierKey = AnnotationKeyPrefix + "set-identifier" + AliasKey = AnnotationKeyPrefix + "alias" + TargetKey = AnnotationKeyPrefix + "target" + ControllerKey = AnnotationKeyPrefix + "controller" + HostnameKey = AnnotationKeyPrefix + "hostname" + AccessKey = AnnotationKeyPrefix + "access" + EndpointsTypeKey = AnnotationKeyPrefix + "endpoints-type" + Ingress = AnnotationKeyPrefix + "ingress" + IngressHostnameSourceKey = AnnotationKeyPrefix + "ingress-hostname-source" + InternalHostnameKey = AnnotationKeyPrefix + "internal-hostname" +} diff --git a/source/annotations/annotations_test.go b/source/annotations/annotations_test.go new file mode 100644 index 0000000000..79fde9f1d7 --- /dev/null +++ b/source/annotations/annotations_test.go @@ -0,0 +1,88 @@ +/* +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) +} diff --git a/source/contour_httpproxy.go b/source/contour_httpproxy.go index f530ee0086..901a8c0f66 100644 --- a/source/contour_httpproxy.go +++ b/source/contour_httpproxy.go @@ -40,7 +40,7 @@ import ( // HTTPProxySource is an implementation of Source for ProjectContour HTTPProxy objects. // The HTTPProxy implementation uses the spec.virtualHost.fqdn value for the hostname. -// Use targetAnnotationKey to explicitly set Endpoint. +// Use annotations.TargetKey to explicitly set Endpoint. type httpProxySource struct { dynamicKubeClient dynamic.Interface namespace string @@ -136,10 +136,10 @@ func (sc *httpProxySource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, for _, hp := range httpProxies { // Check controller annotation to see if we are responsible. - controller, ok := hp.Annotations[controllerAnnotationKey] - if ok && controller != controllerAnnotationValue { + controller, ok := hp.Annotations[annotations.ControllerKey] + if ok && controller != annotations.ControllerValue { log.Debugf("Skipping HTTPProxy %s/%s because controller value does not match, found: %s, required: %s", - hp.Namespace, hp.Name, controller, controllerAnnotationValue) + hp.Namespace, hp.Name, controller, annotations.ControllerValue) continue } diff --git a/source/contour_httpproxy_test.go b/source/contour_httpproxy_test.go index d0d42bd9d2..15a45b2ddd 100644 --- a/source/contour_httpproxy_test.go +++ b/source/contour_httpproxy_test.go @@ -33,6 +33,7 @@ import ( "k8s.io/apimachinery/pkg/runtime" "sigs.k8s.io/external-dns/endpoint" + "sigs.k8s.io/external-dns/source/annotations" ) // This is a compile-time validation that httpProxySource is a Source. @@ -553,7 +554,7 @@ func testHTTPProxyEndpoints(t *testing.T) { name: "fake1", namespace: namespace, annotations: map[string]string{ - controllerAnnotationKey: controllerAnnotationValue, + annotations.ControllerKey: annotations.ControllerValue, }, host: "example.org", }, @@ -577,7 +578,7 @@ func testHTTPProxyEndpoints(t *testing.T) { name: "fake1", namespace: namespace, annotations: map[string]string{ - controllerAnnotationKey: "some-other-tool", + annotations.ControllerKey: "some-other-tool", }, host: "example.org", }, @@ -596,7 +597,7 @@ func testHTTPProxyEndpoints(t *testing.T) { name: "fake1", namespace: namespace, annotations: map[string]string{ - controllerAnnotationKey: controllerAnnotationValue, + annotations.ControllerKey: annotations.ControllerValue, }, host: "", }, @@ -626,7 +627,7 @@ func testHTTPProxyEndpoints(t *testing.T) { name: "fake1", namespace: namespace, annotations: map[string]string{ - controllerAnnotationKey: "other-controller", + annotations.ControllerKey: "other-controller", }, host: "", }, @@ -679,7 +680,7 @@ func testHTTPProxyEndpoints(t *testing.T) { name: "fake2", namespace: namespace, annotations: map[string]string{ - targetAnnotationKey: "httpproxy-target.com", + annotations.TargetKey: "httpproxy-target.com", }, host: "example.org", }, @@ -725,7 +726,7 @@ func testHTTPProxyEndpoints(t *testing.T) { name: "fake1", namespace: namespace, annotations: map[string]string{ - targetAnnotationKey: "httpproxy-target.com", + annotations.TargetKey: "httpproxy-target.com", }, host: "example.org", }, @@ -733,7 +734,7 @@ func testHTTPProxyEndpoints(t *testing.T) { name: "fake2", namespace: namespace, annotations: map[string]string{ - targetAnnotationKey: "httpproxy-target.com", + annotations.TargetKey: "httpproxy-target.com", }, host: "example2.org", }, @@ -741,7 +742,7 @@ func testHTTPProxyEndpoints(t *testing.T) { name: "fake3", namespace: namespace, annotations: map[string]string{ - targetAnnotationKey: "1.2.3.4", + annotations.TargetKey: "1.2.3.4", }, host: "example3.org", }, @@ -775,7 +776,7 @@ func testHTTPProxyEndpoints(t *testing.T) { name: "fake1", namespace: namespace, annotations: map[string]string{ - hostnameAnnotationKey: "dns-through-hostname.com", + annotations.HostnameKey: "dns-through-hostname.com", }, host: "example.org", }, @@ -804,7 +805,7 @@ func testHTTPProxyEndpoints(t *testing.T) { name: "fake1", namespace: namespace, annotations: map[string]string{ - hostnameAnnotationKey: "dns-through-hostname.com, another-dns-through-hostname.com", + annotations.HostnameKey: "dns-through-hostname.com, another-dns-through-hostname.com", }, host: "example.org", }, @@ -838,8 +839,8 @@ func testHTTPProxyEndpoints(t *testing.T) { name: "fake1", namespace: namespace, annotations: map[string]string{ - hostnameAnnotationKey: "dns-through-hostname.com", - targetAnnotationKey: "httpproxy-target.com", + annotations.HostnameKey: "dns-through-hostname.com", + annotations.TargetKey: "httpproxy-target.com", }, host: "example.org", }, @@ -868,8 +869,8 @@ func testHTTPProxyEndpoints(t *testing.T) { name: "fake1", namespace: namespace, annotations: map[string]string{ - targetAnnotationKey: "httpproxy-target.com", - ttlAnnotationKey: "6", + annotations.TargetKey: "httpproxy-target.com", + annotations.TtlKey: "6", }, host: "example.org", }, @@ -877,8 +878,8 @@ func testHTTPProxyEndpoints(t *testing.T) { name: "fake2", namespace: namespace, annotations: map[string]string{ - targetAnnotationKey: "httpproxy-target.com", - ttlAnnotationKey: "1", + annotations.TargetKey: "httpproxy-target.com", + annotations.TtlKey: "1", }, host: "example2.org", }, @@ -886,8 +887,8 @@ func testHTTPProxyEndpoints(t *testing.T) { name: "fake3", namespace: namespace, annotations: map[string]string{ - targetAnnotationKey: "httpproxy-target.com", - ttlAnnotationKey: "10s", + annotations.TargetKey: "httpproxy-target.com", + annotations.TtlKey: "10s", }, host: "example3.org", }, @@ -925,7 +926,7 @@ func testHTTPProxyEndpoints(t *testing.T) { name: "fake1", namespace: namespace, annotations: map[string]string{ - targetAnnotationKey: "httpproxy-target.com", + annotations.TargetKey: "httpproxy-target.com", }, host: "", }, @@ -933,7 +934,7 @@ func testHTTPProxyEndpoints(t *testing.T) { name: "fake2", namespace: namespace, annotations: map[string]string{ - targetAnnotationKey: "httpproxy-target.com", + annotations.TargetKey: "httpproxy-target.com", }, host: "", }, @@ -941,7 +942,7 @@ func testHTTPProxyEndpoints(t *testing.T) { name: "fake3", namespace: namespace, annotations: map[string]string{ - targetAnnotationKey: "1.2.3.4", + annotations.TargetKey: "1.2.3.4", }, host: "", }, @@ -977,7 +978,7 @@ func testHTTPProxyEndpoints(t *testing.T) { name: "fake1", namespace: namespace, annotations: map[string]string{ - targetAnnotationKey: "", + annotations.TargetKey: "", }, host: "", }, @@ -997,7 +998,7 @@ func testHTTPProxyEndpoints(t *testing.T) { name: "fake1", namespace: namespace, annotations: map[string]string{ - hostnameAnnotationKey: "ignore.me", + annotations.HostnameKey: "ignore.me", }, host: "example.org", }, @@ -1005,7 +1006,7 @@ func testHTTPProxyEndpoints(t *testing.T) { name: "fake2", namespace: namespace, annotations: map[string]string{ - hostnameAnnotationKey: "ignore.me.too", + annotations.HostnameKey: "ignore.me.too", }, host: "new.org", }, diff --git a/source/f5_transportserver_test.go b/source/f5_transportserver_test.go index c6e154ddb1..4418cefeed 100644 --- a/source/f5_transportserver_test.go +++ b/source/f5_transportserver_test.go @@ -30,6 +30,7 @@ import ( fakeKube "k8s.io/client-go/kubernetes/fake" "sigs.k8s.io/external-dns/endpoint" + "sigs.k8s.io/external-dns/source/annotations" f5 "github.com/F5Networks/k8s-bigip-ctlr/v2/config/apis/cis/v1" ) @@ -57,7 +58,7 @@ func TestF5TransportServerEndpoints(t *testing.T) { Name: "test-vs", Namespace: defaultF5TransportServerNamespace, Annotations: map[string]string{ - targetAnnotationKey: "192.168.1.150", + annotations.TargetKey: "192.168.1.150", }, }, Spec: f5.TransportServerSpec{ diff --git a/source/f5_virtualserver_test.go b/source/f5_virtualserver_test.go index 588f859798..c020d4912f 100644 --- a/source/f5_virtualserver_test.go +++ b/source/f5_virtualserver_test.go @@ -30,6 +30,7 @@ import ( fakeKube "k8s.io/client-go/kubernetes/fake" "sigs.k8s.io/external-dns/endpoint" + "sigs.k8s.io/external-dns/source/annotations" f5 "github.com/F5Networks/k8s-bigip-ctlr/v2/config/apis/cis/v1" ) @@ -57,7 +58,7 @@ func TestF5VirtualServerEndpoints(t *testing.T) { Name: "test-vs", Namespace: defaultF5VirtualServerNamespace, Annotations: map[string]string{ - targetAnnotationKey: "192.168.1.150", + annotations.TargetKey: "192.168.1.150", }, }, Spec: f5.VirtualServerSpec{ @@ -387,7 +388,7 @@ func TestF5VirtualServerEndpoints(t *testing.T) { Name: "test-vs", Namespace: defaultF5VirtualServerNamespace, Annotations: map[string]string{ - targetAnnotationKey: "192.168.1.150", + annotations.TargetKey: "192.168.1.150", }, }, Spec: f5.VirtualServerSpec{ diff --git a/source/gateway.go b/source/gateway.go index 445352838b..95a551f5e0 100644 --- a/source/gateway.go +++ b/source/gateway.go @@ -220,9 +220,9 @@ func (src *gatewayRouteSource) Endpoints(ctx context.Context) ([]*endpoint.Endpo } // Check controller annotation to see if we are responsible. - if v, ok := annots[controllerAnnotationKey]; ok && v != controllerAnnotationValue { + if v, ok := annots[annotations.ControllerKey]; ok && v != annotations.ControllerValue { log.Debugf("Skipping %s %s/%s because controller value does not match, found: %s, required: %s", - src.rtKind, meta.Namespace, meta.Name, v, controllerAnnotationValue) + src.rtKind, meta.Namespace, meta.Name, v, annotations.ControllerValue) continue } diff --git a/source/gateway_grpcroute_test.go b/source/gateway_grpcroute_test.go index a794c3796b..6e58e78d80 100644 --- a/source/gateway_grpcroute_test.go +++ b/source/gateway_grpcroute_test.go @@ -25,6 +25,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" kubefake "k8s.io/client-go/kubernetes/fake" "sigs.k8s.io/external-dns/endpoint" + "sigs.k8s.io/external-dns/source/annotations" v1 "sigs.k8s.io/gateway-api/apis/v1" v1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1" gatewayfake "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned/fake" @@ -69,7 +70,7 @@ func TestGatewayGRPCRouteSourceEndpoints(t *testing.T) { Name: "api", Namespace: "default", Annotations: map[string]string{ - hostnameAnnotationKey: "api-annotation.foobar.internal", + annotations.HostnameKey: "api-annotation.foobar.internal", }, }, Spec: v1.GRPCRouteSpec{ diff --git a/source/gateway_httproute_test.go b/source/gateway_httproute_test.go index 2edbf89654..031ae93cf7 100644 --- a/source/gateway_httproute_test.go +++ b/source/gateway_httproute_test.go @@ -513,7 +513,7 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { Name: "api", Namespace: "default", Annotations: map[string]string{ - controllerAnnotationKey: "something-else", + annotations.ControllerKey: "something-else", }, }, Spec: v1.HTTPRouteSpec{ @@ -884,7 +884,7 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { Name: "without-hostame", Namespace: "default", Annotations: map[string]string{ - hostnameAnnotationKey: "annotation.without-hostname.internal", + annotations.HostnameKey: "annotation.without-hostname.internal", }, }, Spec: v1.HTTPRouteSpec{ @@ -902,7 +902,7 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { Name: "with-hostame", Namespace: "default", Annotations: map[string]string{ - hostnameAnnotationKey: "annotation.with-hostname.internal", + annotations.HostnameKey: "annotation.with-hostname.internal", }, }, Spec: v1.HTTPRouteSpec{ @@ -940,7 +940,7 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { Name: "with-hostame", Namespace: "default", Annotations: map[string]string{ - hostnameAnnotationKey: "annotation.with-hostname.internal", + annotations.HostnameKey: "annotation.with-hostname.internal", }, }, Spec: v1.HTTPRouteSpec{ @@ -1050,7 +1050,7 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "valid-ttl", Namespace: "default", - Annotations: map[string]string{ttlAnnotationKey: "15s"}, + Annotations: map[string]string{annotations.TtlKey: "15s"}, }, Spec: v1.HTTPRouteSpec{ Hostnames: hostnames("valid-ttl.internal"), @@ -1066,7 +1066,7 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "invalid-ttl", Namespace: "default", - Annotations: map[string]string{ttlAnnotationKey: "abc"}, + Annotations: map[string]string{annotations.TtlKey: "abc"}, }, Spec: v1.HTTPRouteSpec{ Hostnames: hostnames("invalid-ttl.internal"), @@ -1101,7 +1101,7 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { Namespace: "default", Annotations: map[string]string{ annotations.SetIdentifierKey: "test-set-identifier", - aliasAnnotationKey: "true", + annotations.AliasKey: "true", }, }, Spec: v1.HTTPRouteSpec{ @@ -1332,7 +1332,7 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { Name: "overriden-gateway", Namespace: "gateway-namespace", Annotations: map[string]string{ - targetAnnotationKey: "4.3.2.1", + annotations.TargetKey: "4.3.2.1", }, }, Spec: v1.GatewaySpec{ @@ -1374,7 +1374,7 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) { Name: "overriden-gateway", Namespace: "gateway-namespace", Annotations: map[string]string{ - targetAnnotationKey: "4.3.2.1", + annotations.TargetKey: "4.3.2.1", }, }, Spec: v1.GatewaySpec{ diff --git a/source/gateway_tcproute_test.go b/source/gateway_tcproute_test.go index 417ac788ba..f4d5aa69aa 100644 --- a/source/gateway_tcproute_test.go +++ b/source/gateway_tcproute_test.go @@ -25,6 +25,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" kubefake "k8s.io/client-go/kubernetes/fake" "sigs.k8s.io/external-dns/endpoint" + "sigs.k8s.io/external-dns/source/annotations" v1 "sigs.k8s.io/gateway-api/apis/v1" "sigs.k8s.io/gateway-api/apis/v1alpha2" v1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1" @@ -70,7 +71,7 @@ func TestGatewayTCPRouteSourceEndpoints(t *testing.T) { Name: "api", Namespace: "default", Annotations: map[string]string{ - hostnameAnnotationKey: "api-annotation.foobar.internal", + annotations.HostnameKey: "api-annotation.foobar.internal", }, }, Spec: v1alpha2.TCPRouteSpec{ diff --git a/source/gateway_tlsroute_test.go b/source/gateway_tlsroute_test.go index 238b62598f..5a9df28db1 100644 --- a/source/gateway_tlsroute_test.go +++ b/source/gateway_tlsroute_test.go @@ -25,6 +25,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" kubefake "k8s.io/client-go/kubernetes/fake" "sigs.k8s.io/external-dns/endpoint" + "sigs.k8s.io/external-dns/source/annotations" v1 "sigs.k8s.io/gateway-api/apis/v1" "sigs.k8s.io/gateway-api/apis/v1alpha2" v1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1" @@ -70,7 +71,7 @@ func TestGatewayTLSRouteSourceEndpoints(t *testing.T) { Name: "api", Namespace: "default", Annotations: map[string]string{ - hostnameAnnotationKey: "api-annotation.foobar.internal", + annotations.HostnameKey: "api-annotation.foobar.internal", }, }, Spec: v1alpha2.TLSRouteSpec{ diff --git a/source/gateway_udproute_test.go b/source/gateway_udproute_test.go index 161de45f46..fa10108bd9 100644 --- a/source/gateway_udproute_test.go +++ b/source/gateway_udproute_test.go @@ -25,6 +25,7 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" kubefake "k8s.io/client-go/kubernetes/fake" "sigs.k8s.io/external-dns/endpoint" + "sigs.k8s.io/external-dns/source/annotations" v1 "sigs.k8s.io/gateway-api/apis/v1" "sigs.k8s.io/gateway-api/apis/v1alpha2" v1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1" @@ -70,7 +71,7 @@ func TestGatewayUDPRouteSourceEndpoints(t *testing.T) { Name: "api", Namespace: "default", Annotations: map[string]string{ - hostnameAnnotationKey: "api-annotation.foobar.internal", + annotations.HostnameKey: "api-annotation.foobar.internal", }, }, Spec: v1alpha2.UDPRouteSpec{ diff --git a/source/ingress.go b/source/ingress.go index e79d50f161..59bb5870e1 100644 --- a/source/ingress.go +++ b/source/ingress.go @@ -49,7 +49,7 @@ const ( // ingressSource is an implementation of Source for Kubernetes ingress objects. // Ingress implementation will use the spec.rules.host value for the hostname -// Use targetAnnotationKey to explicitly set Endpoint. (useful if the ingress +// Use annotations.TargetKey to explicitly set Endpoint. (useful if the ingress // controller does not update, or to override with alternative endpoint) type ingressSource struct { client kubernetes.Interface @@ -145,9 +145,9 @@ func (sc *ingressSource) Endpoints(_ context.Context) ([]*endpoint.Endpoint, err for _, ing := range ingresses { // Check the controller annotation to see if we are responsible. - if controller, ok := ing.Annotations[controllerAnnotationKey]; ok && controller != controllerAnnotationValue { + if controller, ok := ing.Annotations[annotations.ControllerKey]; ok && controller != annotations.ControllerValue { log.Debugf("Skipping ingress %s/%s because controller value does not match, found: %s, required: %s", - ing.Namespace, ing.Name, controller, controllerAnnotationValue) + ing.Namespace, ing.Name, controller, annotations.ControllerValue) continue } @@ -318,7 +318,7 @@ func endpointsFromIngress(ing *networkv1.Ingress, ignoreHostnameAnnotation bool, } // Determine which hostnames to consider in our final list - hostnameSourceAnnotation, hostnameSourceAnnotationExists := ing.Annotations[ingressHostnameSourceKey] + hostnameSourceAnnotation, hostnameSourceAnnotationExists := ing.Annotations[annotations.IngressHostnameSourceKey] if !hostnameSourceAnnotationExists { return append(definedHostsEndpoints, annotationEndpoints...) } diff --git a/source/ingress_test.go b/source/ingress_test.go index 6452383e20..ebe55a8fe3 100644 --- a/source/ingress_test.go +++ b/source/ingress_test.go @@ -29,6 +29,7 @@ import ( "k8s.io/client-go/kubernetes/fake" "sigs.k8s.io/external-dns/endpoint" + "sigs.k8s.io/external-dns/source/annotations" ) // Validates that ingressSource is a Source @@ -276,7 +277,7 @@ func testEndpointsFromIngressHostnameSourceAnnotation(t *testing.T) { title: "No ingress-hostname-source annotation, one rule.host, one annotation host", ingress: fakeIngress{ dnsnames: []string{"foo.bar"}, - annotations: map[string]string{hostnameAnnotationKey: "foo.baz"}, + annotations: map[string]string{annotations.HostnameKey: "foo.baz"}, hostnames: []string{"lb.com"}, }, expected: []*endpoint.Endpoint{ @@ -310,7 +311,7 @@ func testEndpointsFromIngressHostnameSourceAnnotation(t *testing.T) { title: "No ingress-hostname-source annotation, one rule.host, one annotation host", ingress: fakeIngress{ dnsnames: []string{"foo.bar"}, - annotations: map[string]string{hostnameAnnotationKey: "foo.baz"}, + annotations: map[string]string{annotations.HostnameKey: "foo.baz"}, hostnames: []string{"lb.com"}, }, expected: []*endpoint.Endpoint{ @@ -330,7 +331,7 @@ func testEndpointsFromIngressHostnameSourceAnnotation(t *testing.T) { title: "Ingress-hostname-source=defined-hosts-only, one rule.host, one annotation host", ingress: fakeIngress{ dnsnames: []string{"foo.bar"}, - annotations: map[string]string{hostnameAnnotationKey: "foo.baz", ingressHostnameSourceKey: "defined-hosts-only"}, + annotations: map[string]string{annotations.HostnameKey: "foo.baz", annotations.IngressHostnameSourceKey: "defined-hosts-only"}, hostnames: []string{"lb.com"}, }, expected: []*endpoint.Endpoint{ @@ -345,7 +346,7 @@ func testEndpointsFromIngressHostnameSourceAnnotation(t *testing.T) { title: "Ingress-hostname-source=annotation-only, one rule.host, one annotation host", ingress: fakeIngress{ dnsnames: []string{"foo.bar"}, - annotations: map[string]string{hostnameAnnotationKey: "foo.baz", ingressHostnameSourceKey: "annotation-only"}, + annotations: map[string]string{annotations.HostnameKey: "foo.baz", annotations.IngressHostnameSourceKey: "annotation-only"}, hostnames: []string{"lb.com"}, }, expected: []*endpoint.Endpoint{ @@ -641,7 +642,7 @@ func testIngressEndpoints(t *testing.T) { name: "fake1", namespace: namespace, annotations: map[string]string{ - controllerAnnotationKey: controllerAnnotationValue, + annotations.ControllerKey: annotations.ControllerValue, }, dnsnames: []string{"example.org"}, ips: []string{"8.8.8.8"}, @@ -663,7 +664,7 @@ func testIngressEndpoints(t *testing.T) { name: "fake1", namespace: namespace, annotations: map[string]string{ - controllerAnnotationKey: "some-other-tool", + annotations.ControllerKey: "some-other-tool", }, dnsnames: []string{"example.org"}, ips: []string{"8.8.8.8"}, @@ -679,7 +680,7 @@ func testIngressEndpoints(t *testing.T) { name: "fake1", namespace: namespace, annotations: map[string]string{ - controllerAnnotationKey: controllerAnnotationValue, + annotations.ControllerKey: annotations.ControllerValue, }, dnsnames: []string{}, ips: []string{"8.8.8.8"}, @@ -708,7 +709,7 @@ func testIngressEndpoints(t *testing.T) { name: "fake1", namespace: namespace, annotations: map[string]string{ - controllerAnnotationKey: "other-controller", + annotations.ControllerKey: "other-controller", }, dnsnames: []string{}, ips: []string{"8.8.8.8"}, @@ -758,7 +759,7 @@ func testIngressEndpoints(t *testing.T) { name: "fake2", namespace: namespace, annotations: map[string]string{ - targetAnnotationKey: "ingress-target.com", + annotations.TargetKey: "ingress-target.com", }, dnsnames: []string{"example.org"}, ips: []string{}, @@ -802,7 +803,7 @@ func testIngressEndpoints(t *testing.T) { name: "fake1", namespace: namespace, annotations: map[string]string{ - targetAnnotationKey: "ingress-target.com", + annotations.TargetKey: "ingress-target.com", }, dnsnames: []string{"example.org"}, ips: []string{}, @@ -811,7 +812,7 @@ func testIngressEndpoints(t *testing.T) { name: "fake2", namespace: namespace, annotations: map[string]string{ - targetAnnotationKey: "ingress-target.com", + annotations.TargetKey: "ingress-target.com", }, dnsnames: []string{"example2.org"}, ips: []string{"8.8.8.8"}, @@ -820,7 +821,7 @@ func testIngressEndpoints(t *testing.T) { name: "fake3", namespace: namespace, annotations: map[string]string{ - targetAnnotationKey: "1.2.3.4", + annotations.TargetKey: "1.2.3.4", }, dnsnames: []string{"example3.org"}, ips: []string{}, @@ -929,7 +930,7 @@ func testIngressEndpoints(t *testing.T) { name: "fake1", namespace: namespace, annotations: map[string]string{ - hostnameAnnotationKey: "dns-through-hostname.com", + annotations.HostnameKey: "dns-through-hostname.com", }, dnsnames: []string{"example.org"}, ips: []string{"1.2.3.4"}, @@ -956,7 +957,7 @@ func testIngressEndpoints(t *testing.T) { name: "fake1", namespace: namespace, annotations: map[string]string{ - hostnameAnnotationKey: "dns-through-hostname.com, another-dns-through-hostname.com", + annotations.HostnameKey: "dns-through-hostname.com, another-dns-through-hostname.com", }, dnsnames: []string{"example.org"}, ips: []string{"1.2.3.4"}, @@ -988,8 +989,8 @@ func testIngressEndpoints(t *testing.T) { name: "fake1", namespace: namespace, annotations: map[string]string{ - hostnameAnnotationKey: "dns-through-hostname.com", - targetAnnotationKey: "ingress-target.com", + annotations.HostnameKey: "dns-through-hostname.com", + annotations.TargetKey: "ingress-target.com", }, dnsnames: []string{"example.org"}, ips: []string{}, @@ -1016,8 +1017,8 @@ func testIngressEndpoints(t *testing.T) { name: "fake1", namespace: namespace, annotations: map[string]string{ - targetAnnotationKey: "ingress-target.com", - ttlAnnotationKey: "6", + annotations.TargetKey: "ingress-target.com", + annotations.TtlKey: "6", }, dnsnames: []string{"example.org"}, ips: []string{}, @@ -1026,8 +1027,8 @@ func testIngressEndpoints(t *testing.T) { name: "fake2", namespace: namespace, annotations: map[string]string{ - targetAnnotationKey: "ingress-target.com", - ttlAnnotationKey: "1", + annotations.TargetKey: "ingress-target.com", + annotations.TtlKey: "1", }, dnsnames: []string{"example2.org"}, ips: []string{"8.8.8.8"}, @@ -1036,8 +1037,8 @@ func testIngressEndpoints(t *testing.T) { name: "fake3", namespace: namespace, annotations: map[string]string{ - targetAnnotationKey: "ingress-target.com", - ttlAnnotationKey: "10s", + annotations.TargetKey: "ingress-target.com", + annotations.TtlKey: "10s", }, dnsnames: []string{"example3.org"}, ips: []string{"8.8.4.4"}, @@ -1072,8 +1073,8 @@ func testIngressEndpoints(t *testing.T) { name: "fake1", namespace: namespace, annotations: map[string]string{ - targetAnnotationKey: "ingress-target.com", - aliasAnnotationKey: "true", + annotations.TargetKey: "ingress-target.com", + annotations.AliasKey: "true", }, dnsnames: []string{"example.org"}, ips: []string{}, @@ -1098,8 +1099,8 @@ func testIngressEndpoints(t *testing.T) { name: "fake1", namespace: namespace, annotations: map[string]string{ - targetAnnotationKey: "ingress-target.com", - aliasAnnotationKey: "false", + annotations.TargetKey: "ingress-target.com", + annotations.AliasKey: "false", }, dnsnames: []string{"example.org"}, ips: []string{}, @@ -1121,7 +1122,7 @@ func testIngressEndpoints(t *testing.T) { name: "fake1", namespace: namespace, annotations: map[string]string{ - targetAnnotationKey: "ingress-target.com", + annotations.TargetKey: "ingress-target.com", }, dnsnames: []string{}, ips: []string{}, @@ -1131,7 +1132,7 @@ func testIngressEndpoints(t *testing.T) { name: "fake2", namespace: namespace, annotations: map[string]string{ - targetAnnotationKey: "ingress-target.com", + annotations.TargetKey: "ingress-target.com", }, dnsnames: []string{}, ips: []string{"8.8.8.8"}, @@ -1140,7 +1141,7 @@ func testIngressEndpoints(t *testing.T) { name: "fake3", namespace: namespace, annotations: map[string]string{ - targetAnnotationKey: "1.2.3.4", + annotations.TargetKey: "1.2.3.4", }, dnsnames: []string{}, ips: []string{}, @@ -1174,7 +1175,7 @@ func testIngressEndpoints(t *testing.T) { name: "fake1", namespace: namespace, annotations: map[string]string{ - targetAnnotationKey: "", + annotations.TargetKey: "", }, dnsnames: []string{}, ips: []string{}, @@ -1199,7 +1200,7 @@ func testIngressEndpoints(t *testing.T) { name: "fake2", namespace: namespace, annotations: map[string]string{ - hostnameAnnotationKey: "dns-through-hostname.com", + annotations.HostnameKey: "dns-through-hostname.com", }, dnsnames: []string{"new.org"}, hostnames: []string{"lb.com"}, diff --git a/source/istio_gateway.go b/source/istio_gateway.go index 2f7ae1aff2..cc8dce1834 100644 --- a/source/istio_gateway.go +++ b/source/istio_gateway.go @@ -44,11 +44,12 @@ import ( // IstioGatewayIngressSource is the annotation used to determine if the gateway is implemented by an Ingress object // instead of a standard LoadBalancer service type -const IstioGatewayIngressSource = annotations.Ingress +// Using var instead of const because annotation keys can be customized +var IstioGatewayIngressSource = annotations.Ingress // gatewaySource is an implementation of Source for Istio Gateway objects. // The gateway implementation uses the spec.servers.hosts values for the hostnames. -// Use targetAnnotationKey to explicitly set Endpoint. +// Use annotations.TargetKey to explicitly set Endpoint. type gatewaySource struct { kubeClient kubernetes.Interface istioClient istioclient.Interface @@ -146,10 +147,10 @@ func (sc *gatewaySource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, e for _, gateway := range gateways { // Check controller annotation to see if we are responsible. - controller, ok := gateway.Annotations[controllerAnnotationKey] - if ok && controller != controllerAnnotationValue { + controller, ok := gateway.Annotations[annotations.ControllerKey] + if ok && controller != annotations.ControllerValue { log.Debugf("Skipping gateway %s/%s,%s because controller value does not match, found: %s, required: %s", - gateway.Namespace, gateway.APIVersion, gateway.Name, controller, controllerAnnotationValue) + gateway.Namespace, gateway.APIVersion, gateway.Name, controller, annotations.ControllerValue) continue } diff --git a/source/istio_gateway_test.go b/source/istio_gateway_test.go index 7e4e162e7b..ce12f1cf76 100644 --- a/source/istio_gateway_test.go +++ b/source/istio_gateway_test.go @@ -35,6 +35,7 @@ import ( "k8s.io/apimachinery/pkg/util/intstr" "k8s.io/client-go/kubernetes/fake" "sigs.k8s.io/external-dns/internal/testutils" + "sigs.k8s.io/external-dns/source/annotations" "sigs.k8s.io/external-dns/endpoint" ) @@ -817,7 +818,7 @@ func testGatewayEndpoints(t *testing.T) { name: "fake1", namespace: "", annotations: map[string]string{ - controllerAnnotationKey: controllerAnnotationValue, + annotations.ControllerKey: annotations.ControllerValue, }, dnsnames: [][]string{{"example.org"}}, }, @@ -843,7 +844,7 @@ func testGatewayEndpoints(t *testing.T) { name: "fake1", namespace: "", annotations: map[string]string{ - controllerAnnotationKey: "some-other-tool", + annotations.ControllerKey: "some-other-tool", }, dnsnames: [][]string{{"example.org"}}, }, @@ -864,7 +865,7 @@ func testGatewayEndpoints(t *testing.T) { name: "fake1", namespace: "", annotations: map[string]string{ - controllerAnnotationKey: controllerAnnotationValue, + annotations.ControllerKey: annotations.ControllerValue, }, dnsnames: [][]string{}, }, @@ -896,7 +897,7 @@ func testGatewayEndpoints(t *testing.T) { name: "fake1", namespace: "", annotations: map[string]string{ - controllerAnnotationKey: "other-controller", + annotations.ControllerKey: "other-controller", }, dnsnames: [][]string{}, }, @@ -953,7 +954,7 @@ func testGatewayEndpoints(t *testing.T) { name: "fake2", namespace: "", annotations: map[string]string{ - targetAnnotationKey: "gateway-target.com", + annotations.TargetKey: "gateway-target.com", }, dnsnames: [][]string{{"example.org"}}, }, @@ -1001,7 +1002,7 @@ func testGatewayEndpoints(t *testing.T) { name: "fake1", namespace: "", annotations: map[string]string{ - targetAnnotationKey: "gateway-target.com", + annotations.TargetKey: "gateway-target.com", }, dnsnames: [][]string{{"example.org"}}, }, @@ -1009,7 +1010,7 @@ func testGatewayEndpoints(t *testing.T) { name: "fake2", namespace: "", annotations: map[string]string{ - targetAnnotationKey: "gateway-target.com", + annotations.TargetKey: "gateway-target.com", }, dnsnames: [][]string{{"example2.org"}}, }, @@ -1018,7 +1019,7 @@ func testGatewayEndpoints(t *testing.T) { namespace: "", annotations: map[string]string{ IstioGatewayIngressSource: "not-real/ingress1", - targetAnnotationKey: "1.2.3.4", + annotations.TargetKey: "1.2.3.4", }, dnsnames: [][]string{{"example3.org"}}, }, @@ -1054,7 +1055,7 @@ func testGatewayEndpoints(t *testing.T) { name: "fake1", namespace: "", annotations: map[string]string{ - hostnameAnnotationKey: "dns-through-hostname.com", + annotations.HostnameKey: "dns-through-hostname.com", }, dnsnames: [][]string{{"example.org"}}, }, @@ -1085,7 +1086,7 @@ func testGatewayEndpoints(t *testing.T) { name: "fake1", namespace: "", annotations: map[string]string{ - hostnameAnnotationKey: "dns-through-hostname.com, another-dns-through-hostname.com", + annotations.HostnameKey: "dns-through-hostname.com, another-dns-through-hostname.com", }, dnsnames: [][]string{{"example.org"}}, }, @@ -1121,8 +1122,8 @@ func testGatewayEndpoints(t *testing.T) { name: "fake1", namespace: "", annotations: map[string]string{ - hostnameAnnotationKey: "dns-through-hostname.com", - targetAnnotationKey: "gateway-target.com", + annotations.HostnameKey: "dns-through-hostname.com", + annotations.TargetKey: "gateway-target.com", }, dnsnames: [][]string{{"example.org"}}, }, @@ -1160,8 +1161,8 @@ func testGatewayEndpoints(t *testing.T) { namespace: "", annotations: map[string]string{ IstioGatewayIngressSource: "ingress1", - hostnameAnnotationKey: "dns-through-hostname.com", - targetAnnotationKey: "gateway-target.com", + annotations.HostnameKey: "dns-through-hostname.com", + annotations.TargetKey: "gateway-target.com", }, dnsnames: [][]string{{"example.org"}}, }, @@ -1192,8 +1193,8 @@ func testGatewayEndpoints(t *testing.T) { name: "fake1", namespace: "", annotations: map[string]string{ - targetAnnotationKey: "gateway-target.com", - ttlAnnotationKey: "6", + annotations.TargetKey: "gateway-target.com", + annotations.TtlKey: "6", }, dnsnames: [][]string{{"example.org"}}, }, @@ -1201,8 +1202,8 @@ func testGatewayEndpoints(t *testing.T) { name: "fake2", namespace: "", annotations: map[string]string{ - targetAnnotationKey: "gateway-target.com", - ttlAnnotationKey: "1", + annotations.TargetKey: "gateway-target.com", + annotations.TtlKey: "1", }, dnsnames: [][]string{{"example2.org"}}, }, @@ -1210,8 +1211,8 @@ func testGatewayEndpoints(t *testing.T) { name: "fake3", namespace: "", annotations: map[string]string{ - targetAnnotationKey: "gateway-target.com", - ttlAnnotationKey: "10s", + annotations.TargetKey: "gateway-target.com", + annotations.TtlKey: "10s", }, dnsnames: [][]string{{"example3.org"}}, }, @@ -1251,7 +1252,7 @@ func testGatewayEndpoints(t *testing.T) { name: "fake1", namespace: "", annotations: map[string]string{ - targetAnnotationKey: "gateway-target.com", + annotations.TargetKey: "gateway-target.com", }, dnsnames: [][]string{}, }, @@ -1259,7 +1260,7 @@ func testGatewayEndpoints(t *testing.T) { name: "fake2", namespace: "", annotations: map[string]string{ - targetAnnotationKey: "gateway-target.com", + annotations.TargetKey: "gateway-target.com", }, dnsnames: [][]string{}, }, @@ -1267,7 +1268,7 @@ func testGatewayEndpoints(t *testing.T) { name: "fake3", namespace: "", annotations: map[string]string{ - targetAnnotationKey: "1.2.3.4", + annotations.TargetKey: "1.2.3.4", }, dnsnames: [][]string{}, }, @@ -1305,7 +1306,7 @@ func testGatewayEndpoints(t *testing.T) { name: "fake1", namespace: "", annotations: map[string]string{ - targetAnnotationKey: "", + annotations.TargetKey: "", }, dnsnames: [][]string{}, }, @@ -1356,7 +1357,7 @@ func testGatewayEndpoints(t *testing.T) { name: "fake1", namespace: "", annotations: map[string]string{ - hostnameAnnotationKey: "ignore.me", + annotations.HostnameKey: "ignore.me", }, dnsnames: [][]string{{"example.org"}}, }, @@ -1364,7 +1365,7 @@ func testGatewayEndpoints(t *testing.T) { name: "fake2", namespace: "", annotations: map[string]string{ - hostnameAnnotationKey: "ignore.me.too", + annotations.HostnameKey: "ignore.me.too", }, dnsnames: [][]string{{"new.org"}}, }, @@ -1428,7 +1429,7 @@ func testGatewayEndpoints(t *testing.T) { name: "fake1", namespace: "", annotations: map[string]string{ - hostnameAnnotationKey: "fake1.dns-through-hostname.com", + annotations.HostnameKey: "fake1.dns-through-hostname.com", }, dnsnames: [][]string{{"*"}}, }, @@ -1436,7 +1437,7 @@ func testGatewayEndpoints(t *testing.T) { name: "fake2", namespace: "", annotations: map[string]string{ - hostnameAnnotationKey: "fake2.dns-through-hostname.com", + annotations.HostnameKey: "fake2.dns-through-hostname.com", }, dnsnames: [][]string{{"some-namespace/*"}}, }, diff --git a/source/istio_virtualservice.go b/source/istio_virtualservice.go index f93116903f..ffcdd001be 100644 --- a/source/istio_virtualservice.go +++ b/source/istio_virtualservice.go @@ -49,7 +49,7 @@ const IstioMeshGateway = "mesh" // virtualServiceSource is an implementation of Source for Istio VirtualService objects. // The implementation uses the spec.hosts values for the hostnames. -// Use targetAnnotationKey to explicitly set Endpoint. +// Use annotations.TargetKey to explicitly set Endpoint. type virtualServiceSource struct { kubeClient kubernetes.Interface istioClient istioclient.Interface @@ -150,10 +150,10 @@ func (sc *virtualServiceSource) Endpoints(ctx context.Context) ([]*endpoint.Endp for _, vService := range virtualServices { // Check controller annotation to see if we are responsible. - controller, ok := vService.Annotations[controllerAnnotationKey] - if ok && controller != controllerAnnotationValue { + controller, ok := vService.Annotations[annotations.ControllerKey] + if ok && controller != annotations.ControllerValue { log.Debugf("Skipping VirtualService %s/%s.%s because controller value does not match, found: %s, required: %s", - vService.Namespace, vService.APIVersion, vService.Name, controller, controllerAnnotationValue) + vService.Namespace, vService.APIVersion, vService.Name, controller, annotations.ControllerValue) continue } diff --git a/source/istio_virtualservice_test.go b/source/istio_virtualservice_test.go index 198b87cc30..f7efed5647 100644 --- a/source/istio_virtualservice_test.go +++ b/source/istio_virtualservice_test.go @@ -37,6 +37,7 @@ import ( "k8s.io/client-go/kubernetes/fake" "sigs.k8s.io/external-dns/endpoint" + "sigs.k8s.io/external-dns/source/annotations" ) // This is a compile-time validation that istioVirtualServiceSource is a Source. @@ -1247,7 +1248,7 @@ func testVirtualServiceEndpoints(t *testing.T) { name: "vs1", namespace: namespace, annotations: map[string]string{ - controllerAnnotationKey: controllerAnnotationValue, + annotations.ControllerKey: annotations.ControllerValue, }, gateways: []string{"fake1"}, dnsnames: []string{"example.org"}, @@ -1281,7 +1282,7 @@ func testVirtualServiceEndpoints(t *testing.T) { name: "vs1", namespace: namespace, annotations: map[string]string{ - controllerAnnotationKey: "some-other-tool", + annotations.ControllerKey: "some-other-tool", }, gateways: []string{"fake1"}, dnsnames: []string{"example.org"}, @@ -1371,7 +1372,7 @@ func testVirtualServiceEndpoints(t *testing.T) { name: "fake1", namespace: namespace, annotations: map[string]string{ - targetAnnotationKey: "gateway-target.com", + annotations.TargetKey: "gateway-target.com", }, dnsnames: [][]string{{"*.org", "*.ext-dns.test.com"}}, }, @@ -1424,7 +1425,7 @@ func testVirtualServiceEndpoints(t *testing.T) { namespace: namespace, gateways: []string{"fake1"}, annotations: map[string]string{ - targetAnnotationKey: "virtualservice-target.com", + annotations.TargetKey: "virtualservice-target.com", }, dnsnames: []string{"example.org"}, }, @@ -1433,7 +1434,7 @@ func testVirtualServiceEndpoints(t *testing.T) { namespace: namespace, gateways: []string{"fake1"}, annotations: map[string]string{ - targetAnnotationKey: "virtualservice-target.com", + annotations.TargetKey: "virtualservice-target.com", }, dnsnames: []string{"example2.org"}, }, @@ -1465,7 +1466,7 @@ func testVirtualServiceEndpoints(t *testing.T) { namespace: namespace, dnsnames: [][]string{{"*"}}, annotations: map[string]string{ - targetAnnotationKey: "gateway-target.com", + annotations.TargetKey: "gateway-target.com", }, }, }, @@ -1517,7 +1518,7 @@ func testVirtualServiceEndpoints(t *testing.T) { namespace: namespace, dnsnames: [][]string{{"*"}}, annotations: map[string]string{ - targetAnnotationKey: "gateway-target.com", + annotations.TargetKey: "gateway-target.com", IstioGatewayIngressSource: "ingress1", }, }, @@ -1570,7 +1571,7 @@ func testVirtualServiceEndpoints(t *testing.T) { namespace: namespace, gateways: []string{"fake1"}, annotations: map[string]string{ - hostnameAnnotationKey: "dns-through-hostname.com", + annotations.HostnameKey: "dns-through-hostname.com", }, dnsnames: []string{"example.org"}, }, @@ -1609,7 +1610,7 @@ func testVirtualServiceEndpoints(t *testing.T) { namespace: namespace, gateways: []string{"fake1"}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.bar.com, another-dns-through-hostname.com", + annotations.HostnameKey: "foo.bar.com, another-dns-through-hostname.com", }, dnsnames: []string{"baz.bar.org"}, }, @@ -1643,7 +1644,7 @@ func testVirtualServiceEndpoints(t *testing.T) { namespace: namespace, gateways: []string{"fake1"}, annotations: map[string]string{ - ttlAnnotationKey: "6", + annotations.TtlKey: "6", }, dnsnames: []string{"example.org"}, }, @@ -1652,7 +1653,7 @@ func testVirtualServiceEndpoints(t *testing.T) { namespace: namespace, gateways: []string{"fake1"}, annotations: map[string]string{ - ttlAnnotationKey: "1", + annotations.TtlKey: "1", }, dnsnames: []string{"example2.org"}, }, @@ -1679,7 +1680,7 @@ func testVirtualServiceEndpoints(t *testing.T) { name: "fake1", namespace: namespace, annotations: map[string]string{ - targetAnnotationKey: "gateway-target.com", + annotations.TargetKey: "gateway-target.com", }, dnsnames: [][]string{{"*"}}, }, @@ -1687,7 +1688,7 @@ func testVirtualServiceEndpoints(t *testing.T) { name: "fake2", namespace: namespace, annotations: map[string]string{ - targetAnnotationKey: "gateway-target.com", + annotations.TargetKey: "gateway-target.com", }, dnsnames: [][]string{{"*"}}, }, @@ -1695,7 +1696,7 @@ func testVirtualServiceEndpoints(t *testing.T) { name: "fake3", namespace: namespace, annotations: map[string]string{ - targetAnnotationKey: "1.2.3.4", + annotations.TargetKey: "1.2.3.4", }, dnsnames: [][]string{{"*"}}, }, @@ -1761,7 +1762,7 @@ func testVirtualServiceEndpoints(t *testing.T) { namespace: namespace, gateways: []string{"fake1"}, annotations: map[string]string{ - hostnameAnnotationKey: "ignore.me", + annotations.HostnameKey: "ignore.me", }, dnsnames: []string{"example.org"}, }, @@ -1770,7 +1771,7 @@ func testVirtualServiceEndpoints(t *testing.T) { namespace: namespace, gateways: []string{"fake1"}, annotations: map[string]string{ - hostnameAnnotationKey: "ignore.me.too", + annotations.HostnameKey: "ignore.me.too", }, dnsnames: []string{"new.org"}, }, diff --git a/source/node.go b/source/node.go index 28c879f94c..bc78beaf4a 100644 --- a/source/node.go +++ b/source/node.go @@ -106,9 +106,9 @@ func (ns *nodeSource) Endpoints(_ context.Context) ([]*endpoint.Endpoint, error) // create endpoints for all nodes for _, node := range nodes { // Check the controller annotation to see if we are responsible. - if controller, ok := node.Annotations[controllerAnnotationKey]; ok && controller != controllerAnnotationValue { + if controller, ok := node.Annotations[annotations.ControllerKey]; ok && controller != annotations.ControllerValue { log.Debugf("Skipping node %s because controller value does not match, found: %s, required: %s", - node.Name, controller, controllerAnnotationValue) + node.Name, controller, annotations.ControllerValue) continue } diff --git a/source/node_test.go b/source/node_test.go index b362cdfd86..9c6e0ef216 100644 --- a/source/node_test.go +++ b/source/node_test.go @@ -32,6 +32,7 @@ import ( "k8s.io/client-go/tools/cache" "sigs.k8s.io/external-dns/internal/testutils" + "sigs.k8s.io/external-dns/source/annotations" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -330,7 +331,7 @@ func testNodeSourceEndpoints(t *testing.T) { exposeInternalIPv6: true, nodeAddresses: []v1.NodeAddress{{Type: v1.NodeExternalIP, Address: "1.2.3.4"}}, annotations: map[string]string{ - controllerAnnotationKey: controllerAnnotationValue, + annotations.ControllerKey: annotations.ControllerValue, }, expected: []*endpoint.Endpoint{ {RecordType: "A", DNSName: "node1", Targets: endpoint.Targets{"1.2.3.4"}}, @@ -342,7 +343,7 @@ func testNodeSourceEndpoints(t *testing.T) { exposeInternalIPv6: true, nodeAddresses: []v1.NodeAddress{{Type: v1.NodeExternalIP, Address: "1.2.3.4"}}, annotations: map[string]string{ - controllerAnnotationKey: "not-dns-controller", + annotations.ControllerKey: "not-dns-controller", }, expected: []*endpoint.Endpoint{}, }, @@ -361,7 +362,7 @@ func testNodeSourceEndpoints(t *testing.T) { exposeInternalIPv6: true, nodeAddresses: []v1.NodeAddress{{Type: v1.NodeExternalIP, Address: "1.2.3.4"}}, annotations: map[string]string{ - ttlAnnotationKey: "foo", + annotations.TtlKey: "foo", }, expected: []*endpoint.Endpoint{ {RecordType: "A", DNSName: "node1", Targets: endpoint.Targets{"1.2.3.4"}, RecordTTL: endpoint.TTL(0)}, @@ -373,7 +374,7 @@ func testNodeSourceEndpoints(t *testing.T) { exposeInternalIPv6: true, nodeAddresses: []v1.NodeAddress{{Type: v1.NodeExternalIP, Address: "1.2.3.4"}}, annotations: map[string]string{ - ttlAnnotationKey: "10", + annotations.TtlKey: "10", }, expected: []*endpoint.Endpoint{ {RecordType: "A", DNSName: "node1", Targets: endpoint.Targets{"1.2.3.4"}, RecordTTL: endpoint.TTL(10)}, diff --git a/source/openshift_route.go b/source/openshift_route.go index baa485cd84..f6ce484de7 100644 --- a/source/openshift_route.go +++ b/source/openshift_route.go @@ -41,7 +41,7 @@ import ( // ocpRouteSource is an implementation of Source for OpenShift Route objects. // The Route implementation will use the Route spec.host field for the hostname, // and the Route status' canonicalHostname field as the target. -// The targetAnnotationKey can be used to explicitly set an alternative +// The annotations.TargetKey can be used to explicitly set an alternative // endpoint, if desired. type ocpRouteSource struct { client versioned.Interface @@ -131,10 +131,10 @@ func (ors *ocpRouteSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, for _, ocpRoute := range ocpRoutes { // Check controller annotation to see if we are responsible. - controller, ok := ocpRoute.Annotations[controllerAnnotationKey] - if ok && controller != controllerAnnotationValue { + controller, ok := ocpRoute.Annotations[annotations.ControllerKey] + if ok && controller != annotations.ControllerValue { log.Debugf("Skipping OpenShift Route %s/%s because controller value does not match, found: %s, required: %s", - ocpRoute.Namespace, ocpRoute.Name, controller, controllerAnnotationValue) + ocpRoute.Namespace, ocpRoute.Name, controller, annotations.ControllerValue) continue } diff --git a/source/pod.go b/source/pod.go index b996b358e2..2d0ff5f92d 100644 --- a/source/pod.go +++ b/source/pod.go @@ -187,7 +187,7 @@ func (ps *podSource) addPodEndpointsToEndpointMap(endpointMap map[endpoint.Endpo } func (ps *podSource) addInternalHostnameAnnotationEndpoints(endpointMap map[endpoint.EndpointKey][]string, pod *corev1.Pod, targets []string) { - if domainAnnotation, ok := pod.Annotations[internalHostnameAnnotationKey]; ok { + if domainAnnotation, ok := pod.Annotations[annotations.InternalHostnameKey]; ok { domainList := annotations.SplitHostnameAnnotation(domainAnnotation) for _, domain := range domainList { if len(targets) == 0 { @@ -200,7 +200,7 @@ func (ps *podSource) addInternalHostnameAnnotationEndpoints(endpointMap map[endp } func (ps *podSource) addHostnameAnnotationEndpoints(endpointMap map[endpoint.EndpointKey][]string, pod *corev1.Pod, targets []string) { - if domainAnnotation, ok := pod.Annotations[hostnameAnnotationKey]; ok { + if domainAnnotation, ok := pod.Annotations[annotations.HostnameKey]; ok { domainList := annotations.SplitHostnameAnnotation(domainAnnotation) if len(targets) == 0 { ps.addPodNodeEndpointsToEndpointMap(endpointMap, pod, domainList) diff --git a/source/pod_test.go b/source/pod_test.go index 835f6a2287..c4c8916d8f 100644 --- a/source/pod_test.go +++ b/source/pod_test.go @@ -34,6 +34,7 @@ import ( "sigs.k8s.io/external-dns/endpoint" "sigs.k8s.io/external-dns/internal/testutils" + "sigs.k8s.io/external-dns/source/annotations" "k8s.io/client-go/kubernetes/fake" ) @@ -71,8 +72,8 @@ func TestPodSource(t *testing.T) { Name: "my-pod1", Namespace: "kube-system", Annotations: map[string]string{ - internalHostnameAnnotationKey: "internal.a.foo.example.org", - hostnameAnnotationKey: "a.foo.example.org", + annotations.InternalHostnameKey: "internal.a.foo.example.org", + annotations.HostnameKey: "a.foo.example.org", }, }, Spec: corev1.PodSpec{ @@ -88,8 +89,8 @@ func TestPodSource(t *testing.T) { Name: "my-pod2", Namespace: "kube-system", Annotations: map[string]string{ - internalHostnameAnnotationKey: "internal.a.foo.example.org", - hostnameAnnotationKey: "a.foo.example.org", + annotations.InternalHostnameKey: "internal.a.foo.example.org", + annotations.HostnameKey: "a.foo.example.org", }, }, Spec: corev1.PodSpec{ @@ -169,8 +170,8 @@ func TestPodSource(t *testing.T) { Name: "my-pod1", Namespace: "kube-system", Annotations: map[string]string{ - internalHostnameAnnotationKey: "internal.a.foo.example.org", - hostnameAnnotationKey: "a.foo.example.org", + annotations.InternalHostnameKey: "internal.a.foo.example.org", + annotations.HostnameKey: "a.foo.example.org", }, }, Spec: corev1.PodSpec{ @@ -186,8 +187,8 @@ func TestPodSource(t *testing.T) { Name: "my-pod2", Namespace: "kube-system", Annotations: map[string]string{ - internalHostnameAnnotationKey: "internal.a.foo.example.org", - hostnameAnnotationKey: "a.foo.example.org", + annotations.InternalHostnameKey: "internal.a.foo.example.org", + annotations.HostnameKey: "a.foo.example.org", }, }, Spec: corev1.PodSpec{ @@ -267,9 +268,9 @@ func TestPodSource(t *testing.T) { Name: "my-pod1", Namespace: "kube-system", Annotations: map[string]string{ - internalHostnameAnnotationKey: "internal.a.foo.example.org", - hostnameAnnotationKey: "a.foo.example.org", - targetAnnotationKey: "208.1.2.1", + annotations.InternalHostnameKey: "internal.a.foo.example.org", + annotations.HostnameKey: "a.foo.example.org", + annotations.TargetKey: "208.1.2.1", }, }, Spec: corev1.PodSpec{ @@ -285,9 +286,9 @@ func TestPodSource(t *testing.T) { Name: "my-pod2", Namespace: "kube-system", Annotations: map[string]string{ - internalHostnameAnnotationKey: "internal.a.foo.example.org", - hostnameAnnotationKey: "a.foo.example.org", - targetAnnotationKey: "208.1.2.2", + annotations.InternalHostnameKey: "internal.a.foo.example.org", + annotations.HostnameKey: "a.foo.example.org", + annotations.TargetKey: "208.1.2.2", }, }, Spec: corev1.PodSpec{ @@ -343,8 +344,8 @@ func TestPodSource(t *testing.T) { Name: "my-pod1", Namespace: "kube-system", Annotations: map[string]string{ - hostnameAnnotationKey: "a.foo.example.org", - ttlAnnotationKey: "1h30m", + annotations.HostnameKey: "a.foo.example.org", + annotations.TtlKey: "1h30m", }, }, Spec: corev1.PodSpec{ @@ -360,7 +361,7 @@ func TestPodSource(t *testing.T) { Name: "my-pod2", Namespace: "kube-system", Annotations: map[string]string{ - hostnameAnnotationKey: "b.foo.example.org", + annotations.HostnameKey: "b.foo.example.org", }, }, Spec: corev1.PodSpec{ @@ -391,9 +392,9 @@ func TestPodSource(t *testing.T) { Name: "my-pod1", Namespace: "kube-system", Annotations: map[string]string{ - internalHostnameAnnotationKey: "internal.a.foo.example.org", - hostnameAnnotationKey: "a.foo.example.org", - ttlAnnotationKey: "1s", + annotations.InternalHostnameKey: "internal.a.foo.example.org", + annotations.HostnameKey: "a.foo.example.org", + annotations.TtlKey: "1s", }, }, Spec: corev1.PodSpec{ @@ -409,8 +410,8 @@ func TestPodSource(t *testing.T) { Name: "my-pod2", Namespace: "kube-system", Annotations: map[string]string{ - internalHostnameAnnotationKey: "internal.a.foo.example.org", - hostnameAnnotationKey: "a.foo.example.org", + annotations.InternalHostnameKey: "internal.a.foo.example.org", + annotations.HostnameKey: "a.foo.example.org", }, }, Spec: corev1.PodSpec{ @@ -441,8 +442,8 @@ func TestPodSource(t *testing.T) { Name: "my-pod1", Namespace: "kube-system", Annotations: map[string]string{ - internalHostnameAnnotationKey: "internal.a.foo.example.org", - hostnameAnnotationKey: "a.foo.example.org", + annotations.InternalHostnameKey: "internal.a.foo.example.org", + annotations.HostnameKey: "a.foo.example.org", }, }, Spec: corev1.PodSpec{ @@ -458,9 +459,9 @@ func TestPodSource(t *testing.T) { Name: "my-pod2", Namespace: "default", Annotations: map[string]string{ - internalHostnameAnnotationKey: "internal.a.foo.example.org", - hostnameAnnotationKey: "a.foo.example.org", - ttlAnnotationKey: "1s", + annotations.InternalHostnameKey: "internal.a.foo.example.org", + annotations.HostnameKey: "a.foo.example.org", + annotations.TtlKey: "1s", }, }, Spec: corev1.PodSpec{ @@ -502,7 +503,7 @@ func TestPodSource(t *testing.T) { Name: "my-pod1", Namespace: "kube-system", Annotations: map[string]string{ - internalHostnameAnnotationKey: "internal.a.foo.example.org,internal.b.foo.example.org", + annotations.InternalHostnameKey: "internal.a.foo.example.org,internal.b.foo.example.org", }, }, Spec: corev1.PodSpec{ @@ -533,7 +534,7 @@ func TestPodSource(t *testing.T) { Name: "my-pod1", Namespace: "kube-system", Annotations: map[string]string{ - ttlAnnotationKey: "1m", + annotations.TtlKey: "1m", }, }, Spec: corev1.PodSpec{ @@ -580,9 +581,9 @@ func TestPodSource(t *testing.T) { Name: "my-pod1", Namespace: "kube-system", Annotations: map[string]string{ - internalHostnameAnnotationKey: "internal.a.foo.example.org", - hostnameAnnotationKey: "a.foo.example.org", - targetAnnotationKey: "208.1.2.1", + annotations.InternalHostnameKey: "internal.a.foo.example.org", + annotations.HostnameKey: "a.foo.example.org", + annotations.TargetKey: "208.1.2.1", }, }, Spec: corev1.PodSpec{ @@ -598,9 +599,9 @@ func TestPodSource(t *testing.T) { Name: "my-pod2", Namespace: "kube-system", Annotations: map[string]string{ - internalHostnameAnnotationKey: "internal.a.foo.example.org", - hostnameAnnotationKey: "a.foo.example.org", - targetAnnotationKey: "208.1.2.2", + annotations.InternalHostnameKey: "internal.a.foo.example.org", + annotations.HostnameKey: "a.foo.example.org", + annotations.TargetKey: "208.1.2.2", }, }, Spec: corev1.PodSpec{ @@ -628,7 +629,7 @@ func TestPodSource(t *testing.T) { Name: "my-pod1", Namespace: "kube-system", Annotations: map[string]string{ - hostnameAnnotationKey: "a.foo.example.org", + annotations.HostnameKey: "a.foo.example.org", }, }, Spec: corev1.PodSpec{ @@ -707,8 +708,8 @@ func TestPodSourceLogs(t *testing.T) { Name: fmt.Sprintf("my-pod1-%s", suffix), Namespace: "kube-system", Annotations: map[string]string{ - internalHostnameAnnotationKey: "internal.a.foo.example.org", - hostnameAnnotationKey: "a.foo.example.org", + annotations.InternalHostnameKey: "internal.a.foo.example.org", + annotations.HostnameKey: "a.foo.example.org", }, }, Spec: corev1.PodSpec{ @@ -733,7 +734,7 @@ func TestPodSourceLogs(t *testing.T) { Name: fmt.Sprintf("missing-node-pod-%s", suffix), Namespace: "kube-system", Annotations: map[string]string{ - hostnameAnnotationKey: "a.foo.example.org", + annotations.HostnameKey: "a.foo.example.org", }, }, Spec: corev1.PodSpec{ @@ -760,7 +761,7 @@ func TestPodSourceLogs(t *testing.T) { Name: fmt.Sprintf("valid-pod-%s", suffix), Namespace: "kube-system", Annotations: map[string]string{ - hostnameAnnotationKey: "valid.foo.example.org", + annotations.HostnameKey: "valid.foo.example.org", }, }, Spec: corev1.PodSpec{ @@ -776,7 +777,7 @@ func TestPodSourceLogs(t *testing.T) { Name: fmt.Sprintf("non-hostnet-pod-%s", suffix), Namespace: "kube-system", Annotations: map[string]string{ - hostnameAnnotationKey: "nonhost.foo.example.org", + annotations.HostnameKey: "nonhost.foo.example.org", }, }, Spec: corev1.PodSpec{ @@ -792,7 +793,7 @@ func TestPodSourceLogs(t *testing.T) { Name: fmt.Sprintf("missing-node-pod-%s", suffix), Namespace: "kube-system", Annotations: map[string]string{ - hostnameAnnotationKey: "missing.foo.example.org", + annotations.HostnameKey: "missing.foo.example.org", }, }, Spec: corev1.PodSpec{ @@ -823,7 +824,7 @@ func TestPodSourceLogs(t *testing.T) { Name: fmt.Sprintf("valid-pod-%s", suffix), Namespace: "kube-system", Annotations: map[string]string{ - hostnameAnnotationKey: "valid.foo.example.org", + annotations.HostnameKey: "valid.foo.example.org", }, }, Spec: corev1.PodSpec{ @@ -851,8 +852,8 @@ func TestPodSourceLogs(t *testing.T) { Name: fmt.Sprintf("my-pod1-%s", suffix), Namespace: "kube-system", Annotations: map[string]string{ - internalHostnameAnnotationKey: "internal.a.foo.example.org", - hostnameAnnotationKey: "a.foo.example.org", + annotations.InternalHostnameKey: "internal.a.foo.example.org", + annotations.HostnameKey: "a.foo.example.org", }, }, Spec: corev1.PodSpec{ diff --git a/source/service.go b/source/service.go index e2d3f4cfef..ff4d45302a 100644 --- a/source/service.go +++ b/source/service.go @@ -245,10 +245,10 @@ func (sc *serviceSource) Endpoints(_ context.Context) ([]*endpoint.Endpoint, err for _, svc := range services { // Check controller annotation to see if we are responsible. - controller, ok := svc.Annotations[controllerAnnotationKey] - if ok && controller != controllerAnnotationValue { + controller, ok := svc.Annotations[annotations.ControllerKey] + if ok && controller != annotations.ControllerValue { log.Debugf("Skipping service %s/%s because controller value does not match, found: %s, required: %s", - svc.Namespace, svc.Name, controller, controllerAnnotationValue) + svc.Namespace, svc.Name, controller, annotations.ControllerValue) continue } diff --git a/source/service_test.go b/source/service_test.go index 9c87bd536a..b492cd57e2 100644 --- a/source/service_test.go +++ b/source/service_test.go @@ -44,6 +44,13 @@ 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 @@ -248,7 +255,7 @@ func testServiceSourceEndpoints(t *testing.T) { svcType: v1.ServiceTypeLoadBalancer, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", + annotations.HostnameKey: "foo.example.org.", }, externalIPs: []string{}, lbs: []string{"1.2.3.4"}, @@ -265,7 +272,7 @@ func testServiceSourceEndpoints(t *testing.T) { ignoreHostnameAnnotation: true, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", + annotations.HostnameKey: "foo.example.org.", }, externalIPs: []string{}, lbs: []string{"1.2.3.4"}, @@ -279,7 +286,7 @@ func testServiceSourceEndpoints(t *testing.T) { svcType: v1.ServiceTypeClusterIP, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", + annotations.HostnameKey: "foo.example.org.", }, clusterIP: "1.2.3.4", externalIPs: []string{}, @@ -341,7 +348,7 @@ func testServiceSourceEndpoints(t *testing.T) { combineFQDNAndAnnotation: true, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org., bar.example.org.", + annotations.HostnameKey: "foo.example.org., bar.example.org.", }, externalIPs: []string{}, lbs: []string{"1.2.3.4"}, @@ -363,7 +370,7 @@ func testServiceSourceEndpoints(t *testing.T) { ignoreHostnameAnnotation: true, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org., bar.example.org.", + annotations.HostnameKey: "foo.example.org., bar.example.org.", }, externalIPs: []string{}, lbs: []string{"1.2.3.4"}, @@ -380,7 +387,7 @@ func testServiceSourceEndpoints(t *testing.T) { svcType: v1.ServiceTypeLoadBalancer, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org., bar.example.org.", + annotations.HostnameKey: "foo.example.org., bar.example.org.", }, externalIPs: []string{}, lbs: []string{"1.2.3.4"}, @@ -397,7 +404,7 @@ func testServiceSourceEndpoints(t *testing.T) { svcType: v1.ServiceTypeLoadBalancer, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org, bar.example.org", + annotations.HostnameKey: "foo.example.org, bar.example.org", }, externalIPs: []string{}, lbs: []string{"1.2.3.4"}, @@ -414,7 +421,7 @@ func testServiceSourceEndpoints(t *testing.T) { svcType: v1.ServiceTypeLoadBalancer, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", + annotations.HostnameKey: "foo.example.org.", }, externalIPs: []string{}, lbs: []string{"lb.example.com"}, // Kubernetes omits the trailing dot @@ -430,7 +437,7 @@ func testServiceSourceEndpoints(t *testing.T) { svcType: v1.ServiceTypeLoadBalancer, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", + annotations.HostnameKey: "foo.example.org.", }, externalIPs: []string{}, lbs: []string{"example.com"}, // Use a resolvable hostname for testing. @@ -448,7 +455,7 @@ func testServiceSourceEndpoints(t *testing.T) { svcType: v1.ServiceTypeLoadBalancer, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org", // Trailing dot is omitted + annotations.HostnameKey: "foo.example.org", // Trailing dot is omitted }, externalIPs: []string{}, lbs: []string{"1.2.3.4", "lb.example.com"}, // Kubernetes omits the trailing dot @@ -465,8 +472,8 @@ func testServiceSourceEndpoints(t *testing.T) { svcType: v1.ServiceTypeLoadBalancer, labels: map[string]string{}, annotations: map[string]string{ - controllerAnnotationKey: controllerAnnotationValue, - hostnameAnnotationKey: "foo.example.org.", + annotations.ControllerKey: annotations.ControllerValue, + annotations.HostnameKey: "foo.example.org.", }, externalIPs: []string{}, lbs: []string{"1.2.3.4"}, @@ -483,8 +490,8 @@ func testServiceSourceEndpoints(t *testing.T) { fqdnTemplate: "{{.Name}}.ext-dns.test.com", labels: map[string]string{}, annotations: map[string]string{ - controllerAnnotationKey: "some-other-tool", - hostnameAnnotationKey: "foo.example.org.", + annotations.ControllerKey: "some-other-tool", + annotations.HostnameKey: "foo.example.org.", }, externalIPs: []string{}, lbs: []string{"1.2.3.4"}, @@ -499,7 +506,7 @@ func testServiceSourceEndpoints(t *testing.T) { svcType: v1.ServiceTypeLoadBalancer, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", + annotations.HostnameKey: "foo.example.org.", }, externalIPs: []string{}, lbs: []string{"1.2.3.4"}, @@ -516,7 +523,7 @@ func testServiceSourceEndpoints(t *testing.T) { svcType: v1.ServiceTypeLoadBalancer, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", + annotations.HostnameKey: "foo.example.org.", }, externalIPs: []string{}, lbs: []string{"1.2.3.4"}, @@ -530,7 +537,7 @@ func testServiceSourceEndpoints(t *testing.T) { svcType: v1.ServiceTypeLoadBalancer, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", + annotations.HostnameKey: "foo.example.org.", }, externalIPs: []string{}, lbs: []string{"1.2.3.4"}, @@ -547,7 +554,7 @@ func testServiceSourceEndpoints(t *testing.T) { svcType: v1.ServiceTypeLoadBalancer, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", + annotations.HostnameKey: "foo.example.org.", "service.beta.kubernetes.io/external-traffic": "OnlyLocal", }, externalIPs: []string{}, @@ -565,7 +572,7 @@ func testServiceSourceEndpoints(t *testing.T) { svcType: v1.ServiceTypeLoadBalancer, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", + annotations.HostnameKey: "foo.example.org.", "service.beta.kubernetes.io/external-traffic": "SomethingElse", }, externalIPs: []string{}, @@ -581,7 +588,7 @@ func testServiceSourceEndpoints(t *testing.T) { svcType: v1.ServiceTypeLoadBalancer, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", + annotations.HostnameKey: "foo.example.org.", "service.beta.kubernetes.io/external-traffic": "OnlyLocal", }, externalIPs: []string{}, @@ -598,7 +605,7 @@ func testServiceSourceEndpoints(t *testing.T) { svcType: v1.ServiceTypeLoadBalancer, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", + annotations.HostnameKey: "foo.example.org.", "service.beta.kubernetes.io/external-traffic": "Global", }, externalIPs: []string{}, @@ -616,7 +623,7 @@ func testServiceSourceEndpoints(t *testing.T) { svcType: v1.ServiceTypeLoadBalancer, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", + annotations.HostnameKey: "foo.example.org.", "service.beta.kubernetes.io/external-traffic": "OnlyLocal", }, externalIPs: []string{}, @@ -631,7 +638,7 @@ func testServiceSourceEndpoints(t *testing.T) { svcType: v1.ServiceTypeLoadBalancer, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", + annotations.HostnameKey: "foo.example.org.", }, externalIPs: []string{}, lbs: []string{}, @@ -645,7 +652,7 @@ func testServiceSourceEndpoints(t *testing.T) { svcType: v1.ServiceTypeLoadBalancer, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", + annotations.HostnameKey: "foo.example.org.", }, externalIPs: []string{"10.2.3.4", "11.2.3.4"}, lbs: []string{"1.2.3.4"}, @@ -661,7 +668,7 @@ func testServiceSourceEndpoints(t *testing.T) { svcType: v1.ServiceTypeLoadBalancer, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", + annotations.HostnameKey: "foo.example.org.", }, externalIPs: []string{}, lbs: []string{"1.2.3.4", "8.8.8.8"}, @@ -784,7 +791,7 @@ func testServiceSourceEndpoints(t *testing.T) { fqdnTemplate: "{{.Name}}.bar.example.com", labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", + annotations.HostnameKey: "foo.example.org.", }, externalIPs: []string{}, lbs: []string{"1.2.3.4", "elb.com"}, @@ -833,7 +840,7 @@ func testServiceSourceEndpoints(t *testing.T) { svcType: v1.ServiceTypeLoadBalancer, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", + annotations.HostnameKey: "foo.example.org.", }, externalIPs: []string{}, lbs: []string{"1.2.3.4"}, @@ -849,8 +856,8 @@ func testServiceSourceEndpoints(t *testing.T) { svcType: v1.ServiceTypeLoadBalancer, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", - ttlAnnotationKey: "foo", + annotations.HostnameKey: "foo.example.org.", + annotations.TtlKey: "foo", }, externalIPs: []string{}, lbs: []string{"1.2.3.4"}, @@ -866,8 +873,8 @@ func testServiceSourceEndpoints(t *testing.T) { svcType: v1.ServiceTypeLoadBalancer, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", - ttlAnnotationKey: "10", + annotations.HostnameKey: "foo.example.org.", + annotations.TtlKey: "10", }, externalIPs: []string{}, lbs: []string{"1.2.3.4"}, @@ -883,8 +890,8 @@ func testServiceSourceEndpoints(t *testing.T) { svcType: v1.ServiceTypeLoadBalancer, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", - ttlAnnotationKey: "1m", + annotations.HostnameKey: "foo.example.org.", + annotations.TtlKey: "1m", }, externalIPs: []string{}, lbs: []string{"1.2.3.4"}, @@ -900,8 +907,8 @@ func testServiceSourceEndpoints(t *testing.T) { svcType: v1.ServiceTypeLoadBalancer, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", - ttlAnnotationKey: "-10", + annotations.HostnameKey: "foo.example.org.", + annotations.TtlKey: "-10", }, externalIPs: []string{}, lbs: []string{"1.2.3.4"}, @@ -917,7 +924,7 @@ func testServiceSourceEndpoints(t *testing.T) { svcType: v1.ServiceTypeLoadBalancer, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", + annotations.HostnameKey: "foo.example.org.", }, externalIPs: []string{}, lbs: []string{"1.2.3.4"}, @@ -933,7 +940,7 @@ func testServiceSourceEndpoints(t *testing.T) { svcType: v1.ServiceTypeNodePort, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", + annotations.HostnameKey: "foo.example.org.", }, lbs: []string{"1.2.3.4"}, serviceTypesFilter: []string{string(v1.ServiceTypeLoadBalancer)}, @@ -946,8 +953,8 @@ func testServiceSourceEndpoints(t *testing.T) { svcType: v1.ServiceTypeClusterIP, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", - internalHostnameAnnotationKey: "foo.internal.example.org.", + annotations.HostnameKey: "foo.example.org.", + annotations.InternalHostnameKey: "foo.internal.example.org.", }, clusterIP: "1.1.1.1", externalIPs: []string{}, @@ -964,7 +971,7 @@ func testServiceSourceEndpoints(t *testing.T) { svcType: v1.ServiceTypeLoadBalancer, labels: map[string]string{}, annotations: map[string]string{ - internalHostnameAnnotationKey: "foo.internal.example.org.", + annotations.InternalHostnameKey: "foo.internal.example.org.", }, clusterIP: "1.1.1.1", externalIPs: []string{}, @@ -981,8 +988,8 @@ func testServiceSourceEndpoints(t *testing.T) { svcType: v1.ServiceTypeLoadBalancer, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", - internalHostnameAnnotationKey: "foo.internal.example.org.", + annotations.HostnameKey: "foo.example.org.", + annotations.InternalHostnameKey: "foo.internal.example.org.", }, clusterIP: "1.1.1.1", externalIPs: []string{}, @@ -1024,7 +1031,7 @@ func testServiceSourceEndpoints(t *testing.T) { lbs: []string{"1.2.3.4"}, serviceTypesFilter: []string{}, serviceLabelSelector: "app=web-external", - annotations: map[string]string{hostnameAnnotationKey: "annotation.bar.example.com"}, + annotations: map[string]string{annotations.HostnameKey: "annotation.bar.example.com"}, expected: []*endpoint.Endpoint{ {DNSName: "annotation.bar.example.com", RecordType: endpoint.RecordTypeA, Targets: endpoint.Targets{"1.2.3.4"}}, }, @@ -1058,7 +1065,7 @@ func testServiceSourceEndpoints(t *testing.T) { lbs: []string{"1.2.3.4"}, serviceTypesFilter: []string{}, serviceLabelSelector: "app=web-external", - annotations: map[string]string{hostnameAnnotationKey: "annotation.bar.example.com"}, + annotations: map[string]string{annotations.HostnameKey: "annotation.bar.example.com"}, expected: []*endpoint.Endpoint{}, }, { @@ -1071,7 +1078,7 @@ func testServiceSourceEndpoints(t *testing.T) { externalIPs: []string{}, lbs: []string{"1.1.1.1", "2001:db8::1"}, serviceTypesFilter: []string{}, - annotations: map[string]string{hostnameAnnotationKey: "foobar.example.org"}, + annotations: map[string]string{annotations.HostnameKey: "foobar.example.org"}, expected: []*endpoint.Endpoint{ {DNSName: "foobar.example.org", RecordType: endpoint.RecordTypeA, Targets: endpoint.Targets{"1.1.1.1"}}, {DNSName: "foobar.example.org", RecordType: endpoint.RecordTypeAAAA, Targets: endpoint.Targets{"2001:db8::1"}}, @@ -1087,7 +1094,7 @@ func testServiceSourceEndpoints(t *testing.T) { externalIPs: []string{}, lbs: []string{"2001:db8::2"}, serviceTypesFilter: []string{}, - annotations: map[string]string{hostnameAnnotationKey: "foobar-v6.example.org"}, + annotations: map[string]string{annotations.HostnameKey: "foobar-v6.example.org"}, expected: []*endpoint.Endpoint{ {DNSName: "foobar-v6.example.org", RecordType: endpoint.RecordTypeAAAA, Targets: endpoint.Targets{"2001:db8::2"}}, }, @@ -1211,7 +1218,7 @@ func testMultipleServicesEndpoints(t *testing.T) { map[string]string{}, "", map[string]map[string]string{ - "1.2.3.4": {hostnameAnnotationKey: "foo.example.org"}, + "1.2.3.4": {annotations.HostnameKey: "foo.example.org"}, }, []string{}, []*endpoint.Endpoint{ @@ -1233,9 +1240,9 @@ func testMultipleServicesEndpoints(t *testing.T) { map[string]string{}, "", map[string]map[string]string{ - "1.2.3.4": {hostnameAnnotationKey: "foo.example.org"}, - "1.2.3.5": {hostnameAnnotationKey: "foo.example.org"}, - "1.2.3.6": {hostnameAnnotationKey: "foo.example.org"}, + "1.2.3.4": {annotations.HostnameKey: "foo.example.org"}, + "1.2.3.5": {annotations.HostnameKey: "foo.example.org"}, + "1.2.3.6": {annotations.HostnameKey: "foo.example.org"}, }, []string{}, []*endpoint.Endpoint{ @@ -1257,13 +1264,13 @@ func testMultipleServicesEndpoints(t *testing.T) { map[string]string{}, "", map[string]map[string]string{ - "1.2.3.5": {hostnameAnnotationKey: "foo.example.org"}, - "10.1.1.3": {hostnameAnnotationKey: "bar.example.org"}, - "10.1.1.1": {hostnameAnnotationKey: "bar.example.org"}, - "1.2.3.4": {hostnameAnnotationKey: "foo.example.org"}, - "10.1.1.2": {hostnameAnnotationKey: "bar.example.org"}, - "20.1.1.1": {hostnameAnnotationKey: "foobar.example.org"}, - "1.2.3.6": {hostnameAnnotationKey: "foo.example.org"}, + "1.2.3.5": {annotations.HostnameKey: "foo.example.org"}, + "10.1.1.3": {annotations.HostnameKey: "bar.example.org"}, + "10.1.1.1": {annotations.HostnameKey: "bar.example.org"}, + "1.2.3.4": {annotations.HostnameKey: "foo.example.org"}, + "10.1.1.2": {annotations.HostnameKey: "bar.example.org"}, + "20.1.1.1": {annotations.HostnameKey: "foobar.example.org"}, + "1.2.3.6": {annotations.HostnameKey: "foo.example.org"}, }, []string{}, []*endpoint.Endpoint{ @@ -1287,8 +1294,8 @@ func testMultipleServicesEndpoints(t *testing.T) { map[string]string{}, "", map[string]map[string]string{ - "1.2.3.5": {hostnameAnnotationKey: "foo.example.org", annotations.SetIdentifierKey: "a"}, - "10.1.1.3": {hostnameAnnotationKey: "foo.example.org", annotations.SetIdentifierKey: "b"}, + "1.2.3.5": {annotations.HostnameKey: "foo.example.org", annotations.SetIdentifierKey: "a"}, + "10.1.1.3": {annotations.HostnameKey: "foo.example.org", annotations.SetIdentifierKey: "b"}, }, []string{}, []*endpoint.Endpoint{ @@ -1311,8 +1318,8 @@ func testMultipleServicesEndpoints(t *testing.T) { map[string]string{}, "", map[string]map[string]string{ - "a.elb.com": {hostnameAnnotationKey: "foo.example.org"}, - "b.elb.com": {hostnameAnnotationKey: "foo.example.org"}, + "a.elb.com": {annotations.HostnameKey: "foo.example.org"}, + "b.elb.com": {annotations.HostnameKey: "foo.example.org"}, }, []string{}, []*endpoint.Endpoint{ @@ -1430,7 +1437,7 @@ func TestClusterIpServices(t *testing.T) { svcName: "foo", svcType: v1.ServiceTypeClusterIP, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", + annotations.HostnameKey: "foo.example.org.", }, clusterIP: "1.2.3.4", expected: []*endpoint.Endpoint{ @@ -1443,8 +1450,8 @@ func TestClusterIpServices(t *testing.T) { svcName: "foo", svcType: v1.ServiceTypeClusterIP, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", - targetAnnotationKey: "4.3.2.1", + annotations.HostnameKey: "foo.example.org.", + annotations.TargetKey: "4.3.2.1", }, clusterIP: "1.2.3.4", expected: []*endpoint.Endpoint{ @@ -1457,8 +1464,8 @@ func TestClusterIpServices(t *testing.T) { svcName: "foo", svcType: v1.ServiceTypeClusterIP, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", - targetAnnotationKey: "bar.example.org.", + annotations.HostnameKey: "foo.example.org.", + annotations.TargetKey: "bar.example.org.", }, clusterIP: "1.2.3.4", expected: []*endpoint.Endpoint{ @@ -1471,8 +1478,8 @@ func TestClusterIpServices(t *testing.T) { svcName: "foo", svcType: v1.ServiceTypeClusterIP, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", - targetAnnotationKey: "2001:DB8::1", + annotations.HostnameKey: "foo.example.org.", + annotations.TargetKey: "2001:DB8::1", }, clusterIP: "1.2.3.4", expected: []*endpoint.Endpoint{ @@ -1485,8 +1492,8 @@ func TestClusterIpServices(t *testing.T) { svcName: "foo", svcType: v1.ServiceTypeClusterIP, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", - targetAnnotationKey: "bar.example.org.,baz.example.org.", + annotations.HostnameKey: "foo.example.org.", + annotations.TargetKey: "bar.example.org.,baz.example.org.", }, clusterIP: "1.2.3.4", expected: []*endpoint.Endpoint{ @@ -1499,8 +1506,8 @@ func TestClusterIpServices(t *testing.T) { svcName: "foo", svcType: v1.ServiceTypeClusterIP, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", - targetAnnotationKey: "bar.example.org.,baz.example.org.,2001:DB8::1", + annotations.HostnameKey: "foo.example.org.", + annotations.TargetKey: "bar.example.org.,baz.example.org.,2001:DB8::1", }, clusterIP: "1.2.3.4", expected: []*endpoint.Endpoint{ @@ -1515,7 +1522,7 @@ func TestClusterIpServices(t *testing.T) { svcType: v1.ServiceTypeClusterIP, ignoreHostnameAnnotation: true, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", + annotations.HostnameKey: "foo.example.org.", }, clusterIP: "1.2.3.4", expected: []*endpoint.Endpoint{}, @@ -1527,8 +1534,8 @@ func TestClusterIpServices(t *testing.T) { svcType: v1.ServiceTypeClusterIP, ignoreHostnameAnnotation: true, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", - targetAnnotationKey: "bar.example.org.", + annotations.HostnameKey: "foo.example.org.", + annotations.TargetKey: "bar.example.org.", }, clusterIP: "1.2.3.4", expected: []*endpoint.Endpoint{}, @@ -1539,8 +1546,8 @@ func TestClusterIpServices(t *testing.T) { svcName: "foo", svcType: v1.ServiceTypeClusterIP, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", - targetAnnotationKey: "bar.example.org.", + annotations.HostnameKey: "foo.example.org.", + annotations.TargetKey: "bar.example.org.", }, clusterIP: "1.2.3.4", expected: []*endpoint.Endpoint{ @@ -1572,8 +1579,8 @@ func TestClusterIpServices(t *testing.T) { svcName: "foo", svcType: v1.ServiceTypeClusterIP, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", - targetAnnotationKey: "bar.example.org.", + annotations.HostnameKey: "foo.example.org.", + annotations.TargetKey: "bar.example.org.", }, clusterIP: v1.ClusterIPNone, expected: []*endpoint.Endpoint{ @@ -1600,7 +1607,7 @@ func TestClusterIpServices(t *testing.T) { svcType: v1.ServiceTypeClusterIP, fqdnTemplate: "{{.Name}}.bar.example.com", labels: map[string]string{"app": "web-internal"}, - annotations: map[string]string{targetAnnotationKey: "bar.example.com."}, + annotations: map[string]string{annotations.TargetKey: "bar.example.com."}, clusterIP: "4.5.6.7", expected: []*endpoint.Endpoint{ {DNSName: "foo.bar.example.com", RecordType: endpoint.RecordTypeCNAME, Targets: endpoint.Targets{"bar.example.com"}}, @@ -1624,7 +1631,7 @@ func TestClusterIpServices(t *testing.T) { svcName: "foo", svcType: v1.ServiceTypeClusterIP, annotations: map[string]string{ - hostnameAnnotationKey: "this-is-an-exceedingly-long-label-that-external-dns-should-reject.example.org.", + annotations.HostnameKey: "this-is-an-exceedingly-long-label-that-external-dns-should-reject.example.org.", }, clusterIP: "1.2.3.4", expected: []*endpoint.Endpoint{}, @@ -1731,7 +1738,7 @@ func TestServiceSourceNodePortServices(t *testing.T) { svcType: v1.ServiceTypeNodePort, svcTrafficPolicy: v1.ServiceExternalTrafficPolicyTypeCluster, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", + annotations.HostnameKey: "foo.example.org.", }, expected: []*endpoint.Endpoint{ {DNSName: "_foo._tcp.foo.example.org", Targets: endpoint.Targets{"0 50 30192 foo.example.org"}, RecordType: endpoint.RecordTypeSRV}, @@ -1772,7 +1779,7 @@ func TestServiceSourceNodePortServices(t *testing.T) { svcTrafficPolicy: v1.ServiceExternalTrafficPolicyTypeCluster, ignoreHostnameAnnotation: true, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", + annotations.HostnameKey: "foo.example.org.", }, nodes: []*v1.Node{{ ObjectMeta: metav1.ObjectMeta{ @@ -1846,7 +1853,7 @@ func TestServiceSourceNodePortServices(t *testing.T) { svcType: v1.ServiceTypeNodePort, svcTrafficPolicy: v1.ServiceExternalTrafficPolicyTypeCluster, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", + annotations.HostnameKey: "foo.example.org.", }, expected: []*endpoint.Endpoint{ {DNSName: "_foo._tcp.foo.example.org", Targets: endpoint.Targets{"0 50 30192 foo.example.org"}, RecordType: endpoint.RecordTypeSRV}, @@ -1882,7 +1889,7 @@ func TestServiceSourceNodePortServices(t *testing.T) { svcType: v1.ServiceTypeNodePort, svcTrafficPolicy: v1.ServiceExternalTrafficPolicyTypeLocal, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", + annotations.HostnameKey: "foo.example.org.", }, expected: []*endpoint.Endpoint{ {DNSName: "_foo._tcp.foo.example.org", Targets: endpoint.Targets{"0 50 30192 foo.example.org"}, RecordType: endpoint.RecordTypeSRV}, @@ -1928,7 +1935,7 @@ func TestServiceSourceNodePortServices(t *testing.T) { svcTrafficPolicy: v1.ServiceExternalTrafficPolicyTypeLocal, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", + annotations.HostnameKey: "foo.example.org.", }, expected: []*endpoint.Endpoint{ {DNSName: "_foo._tcp.foo.example.org", Targets: endpoint.Targets{"0 50 30192 foo.example.org"}, RecordType: endpoint.RecordTypeSRV}, @@ -1977,7 +1984,7 @@ func TestServiceSourceNodePortServices(t *testing.T) { svcTrafficPolicy: v1.ServiceExternalTrafficPolicyTypeLocal, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", + annotations.HostnameKey: "foo.example.org.", }, expected: []*endpoint.Endpoint{ {DNSName: "_foo._tcp.foo.example.org", Targets: endpoint.Targets{"0 50 30192 foo.example.org"}, RecordType: endpoint.RecordTypeSRV}, @@ -2021,7 +2028,7 @@ func TestServiceSourceNodePortServices(t *testing.T) { svcTrafficPolicy: v1.ServiceExternalTrafficPolicyTypeLocal, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", + annotations.HostnameKey: "foo.example.org.", }, expected: []*endpoint.Endpoint{ {DNSName: "_foo._tcp.foo.example.org", Targets: endpoint.Targets{"0 50 30192 foo.example.org"}, RecordType: endpoint.RecordTypeSRV}, @@ -2076,8 +2083,8 @@ func TestServiceSourceNodePortServices(t *testing.T) { svcTrafficPolicy: v1.ServiceExternalTrafficPolicyTypeCluster, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", - accessAnnotationKey: "private", + annotations.HostnameKey: "foo.example.org.", + annotations.AccessKey: "private", }, expected: []*endpoint.Endpoint{ {DNSName: "_foo._tcp.foo.example.org", Targets: endpoint.Targets{"0 50 30192 foo.example.org"}, RecordType: endpoint.RecordTypeSRV}, @@ -2116,8 +2123,8 @@ func TestServiceSourceNodePortServices(t *testing.T) { svcTrafficPolicy: v1.ServiceExternalTrafficPolicyTypeCluster, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", - accessAnnotationKey: "public", + annotations.HostnameKey: "foo.example.org.", + annotations.AccessKey: "public", }, expected: []*endpoint.Endpoint{ {DNSName: "_foo._tcp.foo.example.org", Targets: endpoint.Targets{"0 50 30192 foo.example.org"}, RecordType: endpoint.RecordTypeSRV}, @@ -2158,8 +2165,8 @@ func TestServiceSourceNodePortServices(t *testing.T) { svcTrafficPolicy: v1.ServiceExternalTrafficPolicyTypeCluster, labels: map[string]string{}, annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", - accessAnnotationKey: "public", + annotations.HostnameKey: "foo.example.org.", + annotations.AccessKey: "public", }, exposeInternalIPv6: true, expected: []*endpoint.Endpoint{ @@ -2515,7 +2522,7 @@ func TestHeadlessServices(t *testing.T) { false, map[string]string{"component": "foo"}, map[string]string{ - hostnameAnnotationKey: "service.example.org", + annotations.HostnameKey: "service.example.org", }, map[string]string{}, v1.ClusterIPNone, @@ -2550,7 +2557,7 @@ func TestHeadlessServices(t *testing.T) { false, map[string]string{"component": "foo"}, map[string]string{ - hostnameAnnotationKey: "service.example.org", + annotations.HostnameKey: "service.example.org", }, map[string]string{}, v1.ClusterIPNone, @@ -2585,7 +2592,7 @@ func TestHeadlessServices(t *testing.T) { false, map[string]string{"component": "foo"}, map[string]string{ - hostnameAnnotationKey: "service.example.org", + annotations.HostnameKey: "service.example.org", }, map[string]string{}, v1.ClusterIPNone, @@ -2616,8 +2623,8 @@ func TestHeadlessServices(t *testing.T) { false, map[string]string{"component": "foo"}, map[string]string{ - hostnameAnnotationKey: "service.example.org", - ttlAnnotationKey: "1", + annotations.HostnameKey: "service.example.org", + annotations.TtlKey: "1", }, map[string]string{}, v1.ClusterIPNone, @@ -2652,8 +2659,8 @@ func TestHeadlessServices(t *testing.T) { false, map[string]string{"component": "foo"}, map[string]string{ - hostnameAnnotationKey: "service.example.org", - ttlAnnotationKey: "1", + annotations.HostnameKey: "service.example.org", + annotations.TtlKey: "1", }, map[string]string{}, v1.ClusterIPNone, @@ -2688,7 +2695,7 @@ func TestHeadlessServices(t *testing.T) { false, map[string]string{"component": "foo"}, map[string]string{ - hostnameAnnotationKey: "service.example.org", + annotations.HostnameKey: "service.example.org", }, map[string]string{}, v1.ClusterIPNone, @@ -2722,7 +2729,7 @@ func TestHeadlessServices(t *testing.T) { false, map[string]string{"component": "foo"}, map[string]string{ - hostnameAnnotationKey: "service.example.org", + annotations.HostnameKey: "service.example.org", }, map[string]string{}, v1.ClusterIPNone, @@ -2757,7 +2764,7 @@ func TestHeadlessServices(t *testing.T) { false, map[string]string{"component": "foo"}, map[string]string{ - hostnameAnnotationKey: "service.example.org", + annotations.HostnameKey: "service.example.org", }, map[string]string{}, v1.ClusterIPNone, @@ -2790,7 +2797,7 @@ func TestHeadlessServices(t *testing.T) { false, map[string]string{"component": "foo"}, map[string]string{ - hostnameAnnotationKey: "service.example.org", + annotations.HostnameKey: "service.example.org", }, map[string]string{}, v1.ClusterIPNone, @@ -2823,7 +2830,7 @@ func TestHeadlessServices(t *testing.T) { false, map[string]string{"component": "foo"}, map[string]string{ - hostnameAnnotationKey: "service.example.org", + annotations.HostnameKey: "service.example.org", }, map[string]string{}, v1.ClusterIPNone, @@ -2856,10 +2863,10 @@ func TestHeadlessServices(t *testing.T) { false, map[string]string{"component": "foo"}, map[string]string{ - hostnameAnnotationKey: "service.example.org", + annotations.HostnameKey: "service.example.org", }, map[string]string{ - targetAnnotationKey: "1.2.3.4", + annotations.TargetKey: "1.2.3.4", }, v1.ClusterIPNone, []string{"1.1.1.1"}, @@ -2891,10 +2898,10 @@ func TestHeadlessServices(t *testing.T) { false, map[string]string{"component": "foo"}, map[string]string{ - hostnameAnnotationKey: "service.example.org", + annotations.HostnameKey: "service.example.org", }, map[string]string{ - targetAnnotationKey: "2001:db8::4", + annotations.TargetKey: "2001:db8::4", }, v1.ClusterIPNone, []string{"2001:db8::1"}, @@ -2926,8 +2933,8 @@ func TestHeadlessServices(t *testing.T) { false, map[string]string{"component": "foo"}, map[string]string{ - hostnameAnnotationKey: "service.example.org", - endpointsTypeAnnotationKey: EndpointsTypeNodeExternalIP, + annotations.HostnameKey: "service.example.org", + annotations.EndpointsTypeKey: EndpointsTypeNodeExternalIP, }, map[string]string{}, v1.ClusterIPNone, @@ -2971,8 +2978,8 @@ func TestHeadlessServices(t *testing.T) { false, map[string]string{"component": "foo"}, map[string]string{ - hostnameAnnotationKey: "service.example.org", - endpointsTypeAnnotationKey: EndpointsTypeNodeExternalIP, + annotations.HostnameKey: "service.example.org", + annotations.EndpointsTypeKey: EndpointsTypeNodeExternalIP, }, map[string]string{}, v1.ClusterIPNone, @@ -3020,8 +3027,8 @@ func TestHeadlessServices(t *testing.T) { true, map[string]string{"component": "foo"}, map[string]string{ - hostnameAnnotationKey: "service.example.org", - endpointsTypeAnnotationKey: EndpointsTypeNodeExternalIP, + annotations.HostnameKey: "service.example.org", + annotations.EndpointsTypeKey: EndpointsTypeNodeExternalIP, }, map[string]string{}, v1.ClusterIPNone, @@ -3065,8 +3072,8 @@ func TestHeadlessServices(t *testing.T) { true, map[string]string{"component": "foo"}, map[string]string{ - hostnameAnnotationKey: "service.example.org", - endpointsTypeAnnotationKey: EndpointsTypeNodeExternalIP, + annotations.HostnameKey: "service.example.org", + annotations.EndpointsTypeKey: EndpointsTypeNodeExternalIP, }, map[string]string{}, v1.ClusterIPNone, @@ -3115,8 +3122,8 @@ func TestHeadlessServices(t *testing.T) { false, map[string]string{"component": "foo"}, map[string]string{ - hostnameAnnotationKey: "service.example.org", - endpointsTypeAnnotationKey: EndpointsTypeHostIP, + annotations.HostnameKey: "service.example.org", + annotations.EndpointsTypeKey: EndpointsTypeHostIP, }, map[string]string{}, v1.ClusterIPNone, @@ -3149,8 +3156,8 @@ func TestHeadlessServices(t *testing.T) { false, map[string]string{"component": "foo"}, map[string]string{ - hostnameAnnotationKey: "service.example.org", - endpointsTypeAnnotationKey: EndpointsTypeHostIP, + annotations.HostnameKey: "service.example.org", + annotations.EndpointsTypeKey: EndpointsTypeHostIP, }, map[string]string{}, v1.ClusterIPNone, @@ -3922,7 +3929,7 @@ func TestHeadlessServicesHostIP(t *testing.T) { false, map[string]string{"component": "foo"}, map[string]string{ - hostnameAnnotationKey: "service.example.org", + annotations.HostnameKey: "service.example.org", }, v1.ClusterIPNone, []string{"1.1.1.1", "1.1.1.2"}, @@ -3956,7 +3963,7 @@ func TestHeadlessServicesHostIP(t *testing.T) { false, map[string]string{"component": "foo"}, map[string]string{ - hostnameAnnotationKey: "service.example.org", + annotations.HostnameKey: "service.example.org", }, v1.ClusterIPNone, []string{"2001:db8::1", "2001:db8::2"}, @@ -3990,7 +3997,7 @@ func TestHeadlessServicesHostIP(t *testing.T) { true, map[string]string{"component": "foo"}, map[string]string{ - hostnameAnnotationKey: "service.example.org", + annotations.HostnameKey: "service.example.org", }, v1.ClusterIPNone, []string{"1.1.1.1", "1.1.1.2"}, @@ -4020,8 +4027,8 @@ func TestHeadlessServicesHostIP(t *testing.T) { false, map[string]string{"component": "foo"}, map[string]string{ - hostnameAnnotationKey: "service.example.org", - ttlAnnotationKey: "1", + annotations.HostnameKey: "service.example.org", + annotations.TtlKey: "1", }, v1.ClusterIPNone, []string{"1.1.1.1", "1.1.1.2"}, @@ -4055,8 +4062,8 @@ func TestHeadlessServicesHostIP(t *testing.T) { false, map[string]string{"component": "foo"}, map[string]string{ - hostnameAnnotationKey: "service.example.org", - ttlAnnotationKey: "1", + annotations.HostnameKey: "service.example.org", + annotations.TtlKey: "1", }, v1.ClusterIPNone, []string{"2001:db8::1", "2001:db8::2"}, @@ -4090,7 +4097,7 @@ func TestHeadlessServicesHostIP(t *testing.T) { false, map[string]string{"component": "foo"}, map[string]string{ - hostnameAnnotationKey: "service.example.org", + annotations.HostnameKey: "service.example.org", }, v1.ClusterIPNone, []string{"1.1.1.1", "1.1.1.2"}, @@ -4123,7 +4130,7 @@ func TestHeadlessServicesHostIP(t *testing.T) { false, map[string]string{"component": "foo"}, map[string]string{ - hostnameAnnotationKey: "service.example.org", + annotations.HostnameKey: "service.example.org", }, v1.ClusterIPNone, []string{"1.1.1.1", "1.1.1.2"}, @@ -4157,7 +4164,7 @@ func TestHeadlessServicesHostIP(t *testing.T) { false, map[string]string{"component": "foo"}, map[string]string{ - hostnameAnnotationKey: "service.example.org", + annotations.HostnameKey: "service.example.org", }, v1.ClusterIPNone, []string{"1.1.1.1", "1.1.1.2"}, @@ -4189,7 +4196,7 @@ func TestHeadlessServicesHostIP(t *testing.T) { false, map[string]string{"component": "foo"}, map[string]string{ - hostnameAnnotationKey: "service.example.org", + annotations.HostnameKey: "service.example.org", }, v1.ClusterIPNone, []string{"2001:db8::1", "2001:db8::2"}, @@ -4221,7 +4228,7 @@ func TestHeadlessServicesHostIP(t *testing.T) { false, map[string]string{"component": "foo"}, map[string]string{ - hostnameAnnotationKey: "service.example.org", + annotations.HostnameKey: "service.example.org", }, v1.ClusterIPNone, []string{"1.1.1.1"}, @@ -4377,7 +4384,7 @@ func TestExternalServices(t *testing.T) { false, map[string]string{"component": "foo"}, map[string]string{ - hostnameAnnotationKey: "service.example.org", + annotations.HostnameKey: "service.example.org", }, "111.111.111.111", []string{}, @@ -4398,7 +4405,7 @@ func TestExternalServices(t *testing.T) { false, map[string]string{"component": "foo"}, map[string]string{ - hostnameAnnotationKey: "service.example.org", + annotations.HostnameKey: "service.example.org", }, "2001:db8::111", []string{}, @@ -4419,7 +4426,7 @@ func TestExternalServices(t *testing.T) { false, map[string]string{"component": "foo"}, map[string]string{ - hostnameAnnotationKey: "service.example.org", + annotations.HostnameKey: "service.example.org", }, "remote.example.com", []string{}, @@ -4440,7 +4447,7 @@ func TestExternalServices(t *testing.T) { false, map[string]string{"component": "foo"}, map[string]string{ - hostnameAnnotationKey: "service.example.org", + annotations.HostnameKey: "service.example.org", }, "service.example.org", []string{"10.2.3.4", "11.2.3.4"}, @@ -4461,7 +4468,7 @@ func TestExternalServices(t *testing.T) { false, map[string]string{"component": "foo"}, map[string]string{ - hostnameAnnotationKey: "service.example.org", + annotations.HostnameKey: "service.example.org", }, "service.example.org", []string{"10.2.3.4", "11.2.3.4", "2001:db8::1", "2001:db8::2"}, @@ -4483,7 +4490,7 @@ func TestExternalServices(t *testing.T) { false, map[string]string{"component": "foo"}, map[string]string{ - hostnameAnnotationKey: "service.example.org", + annotations.HostnameKey: "service.example.org", }, "service.example.org", []string{"10.2.3.4", "11.2.3.4", "2001:db8::1", "2001:db8::2"}, @@ -4563,7 +4570,7 @@ func BenchmarkServiceEndpoints(b *testing.B) { Namespace: "testing", Name: "foo", Annotations: map[string]string{ - hostnameAnnotationKey: "foo.example.org.", + annotations.HostnameKey: "foo.example.org.", }, }, Status: v1.ServiceStatus{ diff --git a/source/skipper_routegroup.go b/source/skipper_routegroup.go index de7c9f6201..e1a7ee7f4d 100644 --- a/source/skipper_routegroup.go +++ b/source/skipper_routegroup.go @@ -254,10 +254,10 @@ func (sc *routeGroupSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint endpoints := []*endpoint.Endpoint{} for _, rg := range rgList.Items { // Check controller annotation to see if we are responsible. - controller, ok := rg.Metadata.Annotations[controllerAnnotationKey] - if ok && controller != controllerAnnotationValue { + controller, ok := rg.Metadata.Annotations[annotations.ControllerKey] + if ok && controller != annotations.ControllerValue { log.Debugf("Skipping routegroup %s/%s because controller value does not match, found: %s, required: %s", - rg.Metadata.Namespace, rg.Metadata.Name, controller, controllerAnnotationValue) + rg.Metadata.Namespace, rg.Metadata.Name, controller, annotations.ControllerValue) continue } diff --git a/source/skipper_routegroup_test.go b/source/skipper_routegroup_test.go index 4c68a8724c..44507fab1c 100644 --- a/source/skipper_routegroup_test.go +++ b/source/skipper_routegroup_test.go @@ -22,6 +22,7 @@ import ( "testing" "sigs.k8s.io/external-dns/endpoint" + "sigs.k8s.io/external-dns/source/annotations" "sigs.k8s.io/external-dns/source/fqdn" ) @@ -103,7 +104,7 @@ func TestEndpointsFromRouteGroups(t *testing.T) { "namespace1", "rg1", map[string]string{ - hostnameAnnotationKey: "my.example", + annotations.HostnameKey: "my.example", }, []string{"rg1.k8s.example"}, []routeGroupLoadBalancer{ @@ -132,7 +133,7 @@ func TestEndpointsFromRouteGroups(t *testing.T) { "namespace1", "rg1", map[string]string{ - hostnameAnnotationKey: "my.example", + annotations.HostnameKey: "my.example", }, []string{"rg1.k8s.example"}, []routeGroupLoadBalancer{ @@ -156,7 +157,7 @@ func TestEndpointsFromRouteGroups(t *testing.T) { "namespace1", "rg1", map[string]string{ - ttlAnnotationKey: "2189", + annotations.TtlKey: "2189", }, []string{"rg1.k8s.example"}, []routeGroupLoadBalancer{ @@ -448,7 +449,7 @@ func TestRouteGroupsEndpoints(t *testing.T) { "namespace1", "rg1", map[string]string{ - ttlAnnotationKey: "2189", + annotations.TtlKey: "2189", }, []string{"rg1.k8s.example"}, []routeGroupLoadBalancer{ @@ -735,7 +736,7 @@ func TestRouteGroupsEndpoints(t *testing.T) { "namespace1", "rg1", map[string]string{ - controllerAnnotationKey: controllerAnnotationValue, + annotations.ControllerKey: annotations.ControllerValue, }, []string{"rg1.k8s.example"}, []routeGroupLoadBalancer{ @@ -748,7 +749,7 @@ func TestRouteGroupsEndpoints(t *testing.T) { "namespace1", "rg2", map[string]string{ - controllerAnnotationKey: "dns", + annotations.ControllerKey: "dns", }, []string{"rg2.k8s.example"}, []routeGroupLoadBalancer{ diff --git a/source/source.go b/source/source.go index aaa2d1dc11..d65595acf0 100644 --- a/source/source.go +++ b/source/source.go @@ -28,17 +28,6 @@ import ( ) const ( - controllerAnnotationKey = annotations.ControllerKey - hostnameAnnotationKey = annotations.HostnameKey - accessAnnotationKey = annotations.AccessKey - endpointsTypeAnnotationKey = annotations.EndpointsTypeKey - targetAnnotationKey = annotations.TargetKey - ttlAnnotationKey = annotations.TtlKey - aliasAnnotationKey = annotations.AliasKey - ingressHostnameSourceKey = annotations.IngressHostnameSourceKey - controllerAnnotationValue = annotations.ControllerValue - internalHostnameAnnotationKey = annotations.InternalHostnameKey - EndpointsTypeNodeExternalIP = "NodeExternalIP" EndpointsTypeHostIP = "HostIP" ) @@ -56,11 +45,11 @@ type kubeObject interface { } func getAccessFromAnnotations(input map[string]string) string { - return input[accessAnnotationKey] + return input[annotations.AccessKey] } -func getEndpointsTypeFromAnnotations(annotations map[string]string) string { - return annotations[endpointsTypeAnnotationKey] +func getEndpointsTypeFromAnnotations(annots map[string]string) string { + return annots[annotations.EndpointsTypeKey] } func getLabelSelector(annotationFilter string) (labels.Selector, error) {