Unverified Commit 0dda5c8a authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #59749 from zioproto/issues/59421-CheckCIDR

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Detect CIDR IPv4 or IPv6 version to select nexthop **What this PR does / why we need it**: The node `InternalIP` is used as nexthop by the Kubernetes master to create routes in the Neutron router for Pods reachability. If a node has more than one `InternalIP`s, eventually IPv4 and IPv6, a random `InternalIP` from the list is returned. This can lead to the bug described in https://github.com/kubernetes/kubernetes/issues/59421 We need to check when we build a route that the CIDR and the nexthop belong to the same IP Address Family (both IPv4 or both IPv6) **Which issue(s) this PR fixes** : Fixes https://github.com/kubernetes/kubernetes/issues/59421 It is related to https://github.com/kubernetes/kubernetes/issues/55202 **Special notes for your reviewer**: This is the suggested way to fix the problem after the discussion in https://github.com/kubernetes/kubernetes/pull/59502 **Release note**: ```release-note NONE ```
parents f2b6e49e 2eff8bf3
...@@ -23,6 +23,7 @@ import ( ...@@ -23,6 +23,7 @@ import (
"fmt" "fmt"
"io" "io"
"io/ioutil" "io/ioutil"
"net"
"net/http" "net/http"
"os" "os"
"regexp" "regexp"
...@@ -511,7 +512,7 @@ func getAddressesByName(client *gophercloud.ServiceClient, name types.NodeName) ...@@ -511,7 +512,7 @@ func getAddressesByName(client *gophercloud.ServiceClient, name types.NodeName)
return nodeAddresses(srv) return nodeAddresses(srv)
} }
func getAddressByName(client *gophercloud.ServiceClient, name types.NodeName) (string, error) { func getAddressByName(client *gophercloud.ServiceClient, name types.NodeName, needIPv6 bool) (string, error) {
addrs, err := getAddressesByName(client, name) addrs, err := getAddressesByName(client, name)
if err != nil { if err != nil {
return "", err return "", err
...@@ -520,12 +521,20 @@ func getAddressByName(client *gophercloud.ServiceClient, name types.NodeName) (s ...@@ -520,12 +521,20 @@ func getAddressByName(client *gophercloud.ServiceClient, name types.NodeName) (s
} }
for _, addr := range addrs { for _, addr := range addrs {
if addr.Type == v1.NodeInternalIP { isIPv6 := net.ParseIP(addr.Address).To4() == nil
if (addr.Type == v1.NodeInternalIP) && (isIPv6 == needIPv6) {
return addr.Address, nil return addr.Address, nil
} }
} }
return addrs[0].Address, nil for _, addr := range addrs {
isIPv6 := net.ParseIP(addr.Address).To4() == nil
if (addr.Type == v1.NodeExternalIP) && (isIPv6 == needIPv6) {
return addr.Address, nil
}
}
// It should never return an address from a different IP Address family than the one needed
return "", ErrNoAddressFound
} }
// getAttachedInterfacesByID returns the node interfaces of the specified instance. // getAttachedInterfacesByID returns the node interfaces of the specified instance.
......
...@@ -19,6 +19,7 @@ package openstack ...@@ -19,6 +19,7 @@ package openstack
import ( import (
"context" "context"
"errors" "errors"
"net"
"github.com/gophercloud/gophercloud" "github.com/gophercloud/gophercloud"
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers" "github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
...@@ -146,7 +147,10 @@ func (r *Routes) CreateRoute(ctx context.Context, clusterName string, nameHint s ...@@ -146,7 +147,10 @@ func (r *Routes) CreateRoute(ctx context.Context, clusterName string, nameHint s
onFailure := newCaller() onFailure := newCaller()
addr, err := getAddressByName(r.compute, route.TargetNode) ip, _, _ := net.ParseCIDR(route.DestinationCIDR)
isCIDRv6 := ip.To4() == nil
addr, err := getAddressByName(r.compute, route.TargetNode, isCIDRv6)
if err != nil { if err != nil {
return err return err
} }
...@@ -219,7 +223,10 @@ func (r *Routes) DeleteRoute(ctx context.Context, clusterName string, route *clo ...@@ -219,7 +223,10 @@ func (r *Routes) DeleteRoute(ctx context.Context, clusterName string, route *clo
onFailure := newCaller() onFailure := newCaller()
addr, err := getAddressByName(r.compute, route.TargetNode) ip, _, _ := net.ParseCIDR(route.DestinationCIDR)
isCIDRv6 := ip.To4() == nil
addr, err := getAddressByName(r.compute, route.TargetNode, isCIDRv6)
if err != nil { if err != nil {
return err return err
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment