Skip to content

Commit

Permalink
fix: added flannel public address read support
Browse files Browse the repository at this point in the history
  • Loading branch information
BhautikChudasama committed Dec 4, 2024
1 parent 9ebbad9 commit 02d37a8
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pkg/utils/address_resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ import (
corev1 "k8s.io/api/core/v1"
)

const (
// NodeFlannelPublicIPAddress identifies the public IP address of the node as seen by Flannel.
// This is used by Flannel to communicate with the node.
NodeFlannelPublicIPAddress corev1.NodeAddressType = "FlannelPublicIPAddress"

// FlannelPublicIPAnnotationKey is the key for the annotation that
FlannelPublicIPAnnotationKey = "flannel.alpha.coreos.com/public-ip"
)

var (
// DefaultAddressTypePriority is the default node address type
// priority list, as taken from the Kubernetes API metrics-server options.
Expand All @@ -36,6 +45,9 @@ var (
// external, preferring DNS if reported
corev1.NodeExternalDNS,
corev1.NodeExternalIP,

// flannel public address
NodeFlannelPublicIPAddress,
}
)

Expand All @@ -56,6 +68,16 @@ type prioNodeAddrResolver struct {
func (r *prioNodeAddrResolver) NodeAddress(node *corev1.Node) (string, error) {
// adapted from k8s.io/kubernetes/pkg/util/node
for _, addrType := range r.addrTypePriority {
if addrType == NodeFlannelPublicIPAddress {
// read flannel annotation
flannelAddr, ok := node.Annotations[FlannelPublicIPAnnotationKey]
if !ok {
continue
}

return flannelAddr, nil
}

for _, addr := range node.Status.Addresses {
if addr.Type == addrType {
return addr.Address, nil
Expand Down

0 comments on commit 02d37a8

Please sign in to comment.