@@ -20,6 +20,15 @@ import (
20
20
corev1 "k8s.io/api/core/v1"
21
21
)
22
22
23
+ const (
24
+ // NodeFlannelPublicIPAddress identifies the public IP address of the node as seen by Flannel.
25
+ // This is used by Flannel to communicate with the node.
26
+ NodeFlannelPublicIPAddress corev1.NodeAddressType = "FlannelPublicIPAddress"
27
+
28
+ // FlannelPublicIPAnnotationKey is the key for the annotation that
29
+ FlannelPublicIPAnnotationKey = "flannel.alpha.coreos.com/public-ip"
30
+ )
31
+
23
32
var (
24
33
// DefaultAddressTypePriority is the default node address type
25
34
// priority list, as taken from the Kubernetes API metrics-server options.
36
45
// external, preferring DNS if reported
37
46
corev1 .NodeExternalDNS ,
38
47
corev1 .NodeExternalIP ,
48
+
49
+ // flannel public address
50
+ NodeFlannelPublicIPAddress ,
39
51
}
40
52
)
41
53
@@ -56,6 +68,16 @@ type prioNodeAddrResolver struct {
56
68
func (r * prioNodeAddrResolver ) NodeAddress (node * corev1.Node ) (string , error ) {
57
69
// adapted from k8s.io/kubernetes/pkg/util/node
58
70
for _ , addrType := range r .addrTypePriority {
71
+ if addrType == NodeFlannelPublicIPAddress {
72
+ // read flannel annotation
73
+ flannelAddr , ok := node .Annotations [FlannelPublicIPAnnotationKey ]
74
+ if ! ok {
75
+ continue
76
+ }
77
+
78
+ return flannelAddr , nil
79
+ }
80
+
59
81
for _ , addr := range node .Status .Addresses {
60
82
if addr .Type == addrType {
61
83
return addr .Address , nil
0 commit comments