Skip to content

Commit 02d37a8

Browse files
fix: added flannel public address read support
1 parent 9ebbad9 commit 02d37a8

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

pkg/utils/address_resolver.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ import (
2020
corev1 "k8s.io/api/core/v1"
2121
)
2222

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+
2332
var (
2433
// DefaultAddressTypePriority is the default node address type
2534
// priority list, as taken from the Kubernetes API metrics-server options.
@@ -36,6 +45,9 @@ var (
3645
// external, preferring DNS if reported
3746
corev1.NodeExternalDNS,
3847
corev1.NodeExternalIP,
48+
49+
// flannel public address
50+
NodeFlannelPublicIPAddress,
3951
}
4052
)
4153

@@ -56,6 +68,16 @@ type prioNodeAddrResolver struct {
5668
func (r *prioNodeAddrResolver) NodeAddress(node *corev1.Node) (string, error) {
5769
// adapted from k8s.io/kubernetes/pkg/util/node
5870
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+
5981
for _, addr := range node.Status.Addresses {
6082
if addr.Type == addrType {
6183
return addr.Address, nil

0 commit comments

Comments
 (0)