@@ -21,7 +21,6 @@ import (
21
21
22
22
"sigs.k8s.io/external-dns/endpoint"
23
23
24
- log "github.com/sirupsen/logrus"
25
24
corev1 "k8s.io/api/core/v1"
26
25
"k8s.io/apimachinery/pkg/labels"
27
26
kubeinformers "k8s.io/client-go/informers"
@@ -84,40 +83,17 @@ func (ps *podSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error
84
83
85
84
domains := make (map [string ][]string )
86
85
for _ , pod := range pods {
87
- if ! pod .Spec .HostNetwork {
88
- log .Debugf ("skipping pod %s. hostNetwork=false" , pod .Name )
89
- continue
90
- }
91
-
86
+ // accept hostname annotations that point to the pod's IP, no matter if the pod spec uses the host network
92
87
if domain , ok := pod .Annotations [internalHostnameAnnotationKey ]; ok {
93
88
if _ , ok := domains [domain ]; ! ok {
94
89
domains [domain ] = []string {}
95
90
}
96
91
domains [domain ] = append (domains [domain ], pod .Status .PodIP )
97
92
}
98
93
99
- if domain , ok := pod .Annotations [hostnameAnnotationKey ]; ok {
100
- if _ , ok := domains [domain ]; ! ok {
101
- domains [domain ] = []string {}
102
- }
103
-
104
- node , _ := ps .nodeInformer .Lister ().Get (pod .Spec .NodeName )
105
- for _ , address := range node .Status .Addresses {
106
- if address .Type == corev1 .NodeExternalIP {
107
- domains [domain ] = append (domains [domain ], address .Address )
108
- }
109
- }
110
- }
111
-
112
- if ps .compatibility == "kops-dns-controller" {
113
- if domain , ok := pod .Annotations [kopsDNSControllerInternalHostnameAnnotationKey ]; ok {
114
- if _ , ok := domains [domain ]; ! ok {
115
- domains [domain ] = []string {}
116
- }
117
- domains [domain ] = append (domains [domain ], pod .Status .PodIP )
118
- }
119
-
120
- if domain , ok := pod .Annotations [kopsDNSControllerHostnameAnnotationKey ]; ok {
94
+ // accept annotations that point to the node's external IP only for pods using the host network
95
+ if pod .Spec .HostNetwork {
96
+ if domain , ok := pod .Annotations [hostnameAnnotationKey ]; ok {
121
97
if _ , ok := domains [domain ]; ! ok {
122
98
domains [domain ] = []string {}
123
99
}
@@ -129,6 +105,28 @@ func (ps *podSource) Endpoints(ctx context.Context) ([]*endpoint.Endpoint, error
129
105
}
130
106
}
131
107
}
108
+
109
+ if ps .compatibility == "kops-dns-controller" {
110
+ if domain , ok := pod .Annotations [kopsDNSControllerInternalHostnameAnnotationKey ]; ok {
111
+ if _ , ok := domains [domain ]; ! ok {
112
+ domains [domain ] = []string {}
113
+ }
114
+ domains [domain ] = append (domains [domain ], pod .Status .PodIP )
115
+ }
116
+
117
+ if domain , ok := pod .Annotations [kopsDNSControllerHostnameAnnotationKey ]; ok {
118
+ if _ , ok := domains [domain ]; ! ok {
119
+ domains [domain ] = []string {}
120
+ }
121
+
122
+ node , _ := ps .nodeInformer .Lister ().Get (pod .Spec .NodeName )
123
+ for _ , address := range node .Status .Addresses {
124
+ if address .Type == corev1 .NodeExternalIP {
125
+ domains [domain ] = append (domains [domain ], address .Address )
126
+ }
127
+ }
128
+ }
129
+ }
132
130
}
133
131
}
134
132
endpoints := []* endpoint.Endpoint {}
0 commit comments