-
Notifications
You must be signed in to change notification settings - Fork 67
/
handler.go
64 lines (60 loc) · 2.25 KB
/
handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package service
import (
"fmt"
"github.com/gardener/controller-manager-library/pkg/logger"
"github.com/gardener/controller-manager-library/pkg/resources"
"github.com/gardener/controller-manager-library/pkg/utils"
"github.com/gardener/external-dns-management/pkg/dns"
"github.com/gardener/external-dns-management/pkg/dns/source"
api "k8s.io/api/core/v1"
)
func GetTargets(_ logger.LogContext, obj resources.ObjectData, names dns.DNSNameSet) (*source.TargetExtraction, error) {
svc := obj.(*api.Service)
if svc.Spec.Type != api.ServiceTypeLoadBalancer {
if len(names) == 0 {
return nil, nil
}
return nil, fmt.Errorf("service is not of type LoadBalancer")
}
if len(names) == 1 {
for name := range names {
if name.DNSName == "*" {
return nil, nil
}
}
}
ipstack := ""
set := utils.StringSet{}
for _, i := range svc.Status.LoadBalancer.Ingress {
if i.Hostname != "" && i.IP == "" {
if svc.Annotations["loadbalancer.openstack.org/load-balancer-address"] != "" {
// Support for PROXY protocol on Openstack (which needs a hostname as ingress)
// If the user sets the annotation `loadbalancer.openstack.org/hostname`, the
// annotation `loadbalancer.openstack.org/load-balancer-address` contains the IP address.
// This address can then be used to create a DNS record for the hostname specified both
// in annotation `loadbalancer.openstack.org/hostname` and `dns.gardener.cloud/dnsnames`
// see https://github.com/kubernetes/cloud-provider-openstack/blob/master/docs/openstack-cloud-controller-manager/expose-applications-using-loadbalancer-type-service.md#service-annotations
set.Add(svc.Annotations["loadbalancer.openstack.org/load-balancer-address"])
} else {
set.Add(i.Hostname)
}
} else {
if i.IP != "" {
set.Add(i.IP)
}
}
if svc.Annotations[dns.AnnotationIPStack] != "" {
ipstack = svc.Annotations[dns.AnnotationIPStack]
}
if svc.Annotations["service.beta.kubernetes.io/aws-load-balancer-ip-address-type"] == "dualstack" {
ipstack = dns.AnnotationValueIPStackIPDualStack
}
}
return &source.TargetExtraction{
Targets: set,
IPStack: ipstack,
}, nil
}