-
Notifications
You must be signed in to change notification settings - Fork 7.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
networking: match multiple VIPs in sidecar outbound listener #51967
Changes from all commits
b1356eb
389db0f
865ae50
04baef7
bebe1ac
c083686
a5d793d
b458c32
535c2da
b30db4d
4ab355e
e8938d4
8d5b979
936a768
d978091
87beba3
ee73ef8
f753f11
57d7415
cc85553
41f54c4
a6798b0
bfcde66
21e0748
31b93da
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1261,22 1261,26 @@ func (s *Service) GetAddressForProxy(node *Proxy) string { | |
// GetExtraAddressesForProxy returns a k8s service's extra addresses to the cluster where the node resides. | ||
// Especially for dual stack k8s service to get other IP family addresses. | ||
func (s *Service) GetExtraAddressesForProxy(node *Proxy) []string { | ||
if features.EnableDualStack && node.Metadata != nil { | ||
if node.Metadata.ClusterID != "" { | ||
addresses := s.ClusterVIPs.GetAddressesFor(node.Metadata.ClusterID) | ||
if len(addresses) > 1 { | ||
return addresses[1:] | ||
} | ||
} | ||
addresses := s.getAllAddressesForProxy(node) | ||
if len(addresses) > 1 { | ||
return addresses[1:] | ||
} | ||
return nil | ||
} | ||
|
||
// GetAllAddressesForProxy returns a k8s service's extra addresses to the cluster where the node resides. | ||
// Especially for dual stack k8s service to get other IP family addresses. | ||
func (s *Service) GetAllAddressesForProxy(node *Proxy) []string { | ||
if (features.EnableDualStack || features.EnableAmbient) && node.Metadata != nil && node.Metadata.ClusterID != "" { | ||
return s.getAllAddressesForProxy(node) | ||
} | ||
|
||
func (s *Service) getAllAddressesForProxy(node *Proxy) []string { | ||
if node.Metadata != nil && node.Metadata.ClusterID != "" { | ||
addresses := s.ClusterVIPs.GetAddressesFor(node.Metadata.ClusterID) | ||
if (features.EnableDualStack || features.EnableAmbient) && len(addresses) > 0 { | ||
keithmattix marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. donot we need to check whether pod support dual stack? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Like a multi cluster mesh, one cluster support only ipv4, the other support dual stack There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, this function returns addresses relevant for the cluster of the requesting proxy. Btw. this is irrelevant in this PR, as I didn't change anything related to dual-stack. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, none of your bussiness. Just see this and indeed it is a bug There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general, we shouldn't be making decisions based on |
||
return addresses | ||
} | ||
addresses = filterAddresses(addresses, node.SupportsIPv4(), node.SupportsIPv6()) | ||
if len(addresses) > 0 { | ||
return addresses | ||
} | ||
|
@@ -1298,6 1302,37 @@ func (s *Service) getAllAddresses() []string { | |
return addresses | ||
} | ||
|
||
func filterAddresses(addresses []string, supportsV4, supportsV6 bool) []string { | ||
var ipv4Addresses []string | ||
var ipv6Addresses []string | ||
for _, addr := range addresses { | ||
// check if an address is a CIDR range | ||
if strings.Contains(addr, "/") { | ||
if prefix, err := netip.ParsePrefix(addr); err != nil { | ||
log.Warnf("failed to parse prefix address '%s': %s", addr, err) | ||
continue | ||
} else if supportsV4 && prefix.Addr().Is4() { | ||
ipv4Addresses = append(ipv4Addresses, addr) | ||
} else if supportsV6 && prefix.Addr().Is6() { | ||
ipv6Addresses = append(ipv6Addresses, addr) | ||
} | ||
} else { | ||
if ipAddr, err := netip.ParseAddr(addr); err != nil { | ||
log.Warnf("failed to parse address '%s': %s", addr, err) | ||
continue | ||
} else if supportsV4 && ipAddr.Is4() { | ||
ipv4Addresses = append(ipv4Addresses, addr) | ||
} else if supportsV6 && ipAddr.Is6() { | ||
ipv6Addresses = append(ipv6Addresses, addr) | ||
} | ||
} | ||
} | ||
if len(ipv4Addresses) > 0 { | ||
return ipv4Addresses | ||
} | ||
return ipv6Addresses | ||
} | ||
|
||
// GetTLSModeFromEndpointLabels returns the value of the label | ||
// security.istio.io/tlsMode if set. Do not return Enums or constants | ||
// from this function as users could provide values other than istio/disabled | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Allowing GetExtraAddressesForProxy to return multiple addresses even in non-Dual-Stack scenarios (though all addresses will share the same family in single-stack), means the "additional-addresses codepath", previously gated behind DS or Ambient flags, could be executed more frequently.
I'm fine with that but I would suggest that we eventually reconsider exposing the DS flag to users. As it is becoming less impactful as times goes on, it may be better to enable this functionality automatically based on internal checks rather than relying on user input.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah long term I would like to remove GetExtraAddressesForProxy and the DS flag
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DS flag cannot be removed very soon. It is still alpha