Skip to content

Commit 41a2e88

Browse files
committed
Replace azure-metadata-* annotations with azure-tags
1 parent 9e08a42 commit 41a2e88

File tree

4 files changed

+42
-25
lines changed

4 files changed

+42
-25
lines changed

docs/tutorials/azure.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,7 @@ kind: Ingress
523523
metadata:
524524
name: my-ingress
525525
annotations:
526-
external-dns.alpha.kubernetes.io/azure-metadata-cost-center: "12345"
527-
external-dns.alpha.kubernetes.io/azure-metadata-owner: backend-team
526+
external-dns.alpha.kubernetes.io/azure-tags: "cost-center=12345,owner=backend-team"
528527
spec:
529528
rules:
530529
- host: app.example.com
@@ -547,8 +546,7 @@ kind: HTTPRoute
547546
metadata:
548547
name: my-route
549548
annotations:
550-
external-dns.alpha.kubernetes.io/azure-metadata-environment: production
551-
external-dns.alpha.kubernetes.io/azure-metadata-app: myapp
549+
external-dns.alpha.kubernetes.io/azure-tags: "environment=production,app=myapp"
552550
spec:
553551
parentRefs:
554552
- name: my-gateway
@@ -565,7 +563,7 @@ spec:
565563
### Annotation Format
566564

567565
Metadata annotations must follow the format:
568-
`external-dns.alpha.kubernetes.io/azure-metadata-<key>: <value>`
566+
`external-dns.alpha.kubernetes.io/azure-tags: "key1=value1,key2=value2"`
569567
570568
## Deploy ExternalDNS
571569

source/annotations/annotations.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ var (
3737
CloudflareRecordCommentKey string
3838
CloudflareTagsKey string
3939

40+
// AzureTagsKey The annotation used for Azure DNS record tags
41+
AzureTagsKey string
42+
4043
AWSPrefix string
4144
CoreDNSPrefix string
4245
SCWPrefix string
@@ -80,6 +83,9 @@ func SetAnnotationPrefix(prefix string) {
8083
CloudflareRecordCommentKey = AnnotationKeyPrefix + "cloudflare-record-comment"
8184
CloudflareTagsKey = AnnotationKeyPrefix + "cloudflare-tags"
8285

86+
// Azure annotations
87+
AzureTagsKey = AnnotationKeyPrefix + "azure-tags"
88+
8389
// Provider prefixes
8490
AWSPrefix = AnnotationKeyPrefix + "aws-"
8591
CoreDNSPrefix = AnnotationKeyPrefix + "coredns-"

source/annotations/provider_specific.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,25 @@ func ProviderSpecificAnnotations(annotations map[string]string) (endpoint.Provid
5454
Name: fmt.Sprintf("coredns/%s", attr),
5555
Value: v,
5656
})
57-
} else if attr, ok := strings.CutPrefix(k, AzurePrefix); ok {
58-
providerSpecificAnnotations = append(providerSpecificAnnotations, endpoint.ProviderSpecificProperty{
59-
Name: fmt.Sprintf("azure/%s", attr),
60-
Value: v,
61-
})
57+
} else if k == AzureTagsKey {
58+
// Parse azure-tags annotation (key1=value1,key2=value2)
59+
for _, tag := range strings.Split(v, ",") {
60+
tag = strings.TrimSpace(tag)
61+
if tag == "" {
62+
continue
63+
}
64+
parts := strings.SplitN(tag, "=", 2)
65+
if len(parts) == 2 {
66+
key := strings.TrimSpace(parts[0])
67+
value := strings.TrimSpace(parts[1])
68+
if key != "" && value != "" {
69+
providerSpecificAnnotations = append(providerSpecificAnnotations, endpoint.ProviderSpecificProperty{
70+
Name: fmt.Sprintf("azure/metadata-%s", key),
71+
Value: value,
72+
})
73+
}
74+
}
75+
}
6276
} else if strings.HasPrefix(k, CloudflarePrefix) {
6377
switch {
6478
case strings.Contains(k, CloudflareCustomHostnameKey):

source/annotations/provider_specific_test.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,23 @@ func TestProviderSpecificAnnotations(t *testing.T) {
8282
setIdentifier: "",
8383
},
8484
{
85-
name: "Azure metadata annotation",
85+
name: "Azure tags annotation",
8686
annotations: map[string]string{
87-
"external-dns.alpha.kubernetes.io/azure-metadata-environment": "production",
87+
AzureTagsKey: "cost-center=12345,owner=backend-team",
8888
},
8989
expected: endpoint.ProviderSpecific{
90+
{Name: "azure/metadata-cost-center", Value: "12345"},
91+
{Name: "azure/metadata-owner", Value: "backend-team"},
92+
},
93+
setIdentifier: "",
94+
},
95+
{
96+
name: "Azure tags annotation with spaces",
97+
annotations: map[string]string{
98+
AzureTagsKey: "environment=production, app=myapp ",
99+
},
100+
expected: endpoint.ProviderSpecific{
101+
{Name: "azure/metadata-app", Value: "myapp"},
90102
{Name: "azure/metadata-environment", Value: "production"},
91103
},
92104
setIdentifier: "",
@@ -375,19 +387,6 @@ func TestGetProviderSpecificIdentifierAnnotations(t *testing.T) {
375387
},
376388
expectedIdentifier: "id1",
377389
},
378-
{
379-
title: "azure- provider specific annotations are set correctly",
380-
annotations: map[string]string{
381-
"external-dns.alpha.kubernetes.io/azure-metadata-foo": "bar",
382-
SetIdentifierKey: "id1",
383-
"external-dns.alpha.kubernetes.io/azure-metadata-baz": "qux",
384-
},
385-
expectedResult: map[string]string{
386-
"azure/metadata-foo": "bar",
387-
"azure/metadata-baz": "qux",
388-
},
389-
expectedIdentifier: "id1",
390-
},
391390
} {
392391
t.Run(tc.title, func(t *testing.T) {
393392
providerSpecificAnnotations, identifier := ProviderSpecificAnnotations(tc.annotations)

0 commit comments

Comments
 (0)