external-dns/source/annotations/provider_specific.go
Basil Pozdeev e3d8983ed4
feat(azure): dns metadata (tags) support (#5984)
* feat: Add Azure DNS metadata (tags) support

* fix: address PR review comments for Azure metadata support

* test: add Azure metadata annotation test cases and fix prefix initialization

* Replace azure-metadata-* annotations with azure-tags

* refactor: move Azure tags parsing to provider package

Move provider-specific Azure tags annotation parsing from
source/annotations to provider/azure, following the same
pattern as Cloudflare tags handling.

* fix: use GetProviderSpecificProperty and handle duplicate tags

* fix: align with upstream Go 1.26 migration and short-form property names
2026-04-02 13:11:04 +05:30

105 lines
4.0 KiB
Go

/*
Copyright 2025 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package annotations
import (
"fmt"
"strings"
"sigs.k8s.io/external-dns/endpoint"
)
func ProviderSpecificAnnotations(annotations map[string]string) (endpoint.ProviderSpecific, string) {
providerSpecificAnnotations := endpoint.ProviderSpecific{}
if hasAliasFromAnnotations(annotations) {
providerSpecificAnnotations = append(providerSpecificAnnotations, endpoint.ProviderSpecificProperty{
Name: "alias",
Value: "true",
})
}
if v, ok := annotations[RecordTypeKey]; ok {
providerSpecificAnnotations = append(providerSpecificAnnotations, endpoint.ProviderSpecificProperty{
Name: endpoint.ProviderSpecificRecordType,
Value: v,
})
}
setIdentifier := ""
for k, v := range annotations {
if k == SetIdentifierKey {
setIdentifier = v
} else if attr, ok := strings.CutPrefix(k, AWSPrefix); ok {
providerSpecificAnnotations = append(providerSpecificAnnotations, endpoint.ProviderSpecificProperty{
Name: fmt.Sprintf("aws/%s", attr),
Value: v,
})
} else if attr, ok := strings.CutPrefix(k, SCWPrefix); ok {
providerSpecificAnnotations = append(providerSpecificAnnotations, endpoint.ProviderSpecificProperty{
Name: fmt.Sprintf("scw/%s", attr),
Value: v,
})
} else if attr, ok := strings.CutPrefix(k, WebhookPrefix); ok {
// Support for wildcard annotations for webhook providers
providerSpecificAnnotations = append(providerSpecificAnnotations, endpoint.ProviderSpecificProperty{
Name: fmt.Sprintf("webhook/%s", attr),
Value: v,
})
} else if attr, ok := strings.CutPrefix(k, CoreDNSPrefix); ok {
providerSpecificAnnotations = append(providerSpecificAnnotations, endpoint.ProviderSpecificProperty{
Name: fmt.Sprintf("coredns/%s", attr),
Value: v,
})
} else if k == AzureTagsKey {
providerSpecificAnnotations = append(providerSpecificAnnotations, endpoint.ProviderSpecificProperty{
Name: "azure/tags",
Value: v,
})
} else if strings.HasPrefix(k, CloudflarePrefix) {
// TODO: unlike other providers which normalise to "provider/attr",
// Cloudflare retains the full annotation key as the property name
// (e.g. "external-dns.alpha.kubernetes.io/cloudflare-proxied").
// This is why RetainProviderProperties has a special case for cloudflare.
// Should be aligned with the standard convention in a future change.
switch {
case strings.Contains(k, CloudflareCustomHostnameKey):
providerSpecificAnnotations = append(providerSpecificAnnotations, endpoint.ProviderSpecificProperty{
Name: CloudflareCustomHostnameKey,
Value: v,
})
case strings.Contains(k, CloudflareProxiedKey):
providerSpecificAnnotations = append(providerSpecificAnnotations, endpoint.ProviderSpecificProperty{
Name: CloudflareProxiedKey,
Value: v,
})
case strings.Contains(k, CloudflareRegionKey):
providerSpecificAnnotations = append(providerSpecificAnnotations, endpoint.ProviderSpecificProperty{
Name: CloudflareRegionKey,
Value: v,
})
case strings.Contains(k, CloudflareRecordCommentKey):
providerSpecificAnnotations = append(providerSpecificAnnotations, endpoint.ProviderSpecificProperty{
Name: CloudflareRecordCommentKey,
Value: v,
})
case strings.Contains(k, CloudflareTagsKey):
providerSpecificAnnotations = append(providerSpecificAnnotations, endpoint.ProviderSpecificProperty{
Name: CloudflareTagsKey,
Value: v,
})
}
}
}
return providerSpecificAnnotations, setIdentifier
}