mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 11:21:47 +00:00
e2e: recognize multi-node control planes
We were treating multiple nodes as a failure; instead we can return all the node (internal) IPs we find.
This commit is contained in:
parent
67541a1bcc
commit
33055a8b6b
@ -1234,20 +1234,23 @@ func RunCmdEnv(env []string, command string, args ...string) (string, string, er
|
|||||||
return stdout, stderr, nil
|
return stdout, stderr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// getMasterAddresses returns the externalIP, internalIP and hostname fields of the master.
|
// getControlPlaneAddresses returns the externalIP, internalIP and hostname fields of control plane nodes.
|
||||||
// If any of these is unavailable, it is set to "".
|
// If any of these is unavailable, empty slices are returned.
|
||||||
func getMasterAddresses(c clientset.Interface) (string, string, string) {
|
func getControlPlaneAddresses(c clientset.Interface) ([]string, []string, []string) {
|
||||||
var externalIP, internalIP, hostname string
|
var externalIPs, internalIPs, hostnames []string
|
||||||
|
|
||||||
// Populate the internal IP.
|
// Populate the internal IPs.
|
||||||
eps, err := c.CoreV1().Endpoints(metav1.NamespaceDefault).Get(context.TODO(), "kubernetes", metav1.GetOptions{})
|
eps, err := c.CoreV1().Endpoints(metav1.NamespaceDefault).Get(context.TODO(), "kubernetes", metav1.GetOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Failf("Failed to get kubernetes endpoints: %v", err)
|
Failf("Failed to get kubernetes endpoints: %v", err)
|
||||||
}
|
}
|
||||||
if len(eps.Subsets) != 1 || len(eps.Subsets[0].Addresses) != 1 {
|
for _, subset := range eps.Subsets {
|
||||||
Failf("There are more than 1 endpoints for kubernetes service: %+v", eps)
|
for _, address := range subset.Addresses {
|
||||||
|
if address.IP != "" {
|
||||||
|
internalIPs = append(internalIPs, address.IP)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
internalIP = eps.Subsets[0].Addresses[0].IP
|
|
||||||
|
|
||||||
// Populate the external IP/hostname.
|
// Populate the external IP/hostname.
|
||||||
hostURL, err := url.Parse(TestContext.Host)
|
hostURL, err := url.Parse(TestContext.Host)
|
||||||
@ -1255,12 +1258,12 @@ func getMasterAddresses(c clientset.Interface) (string, string, string) {
|
|||||||
Failf("Failed to parse hostname: %v", err)
|
Failf("Failed to parse hostname: %v", err)
|
||||||
}
|
}
|
||||||
if net.ParseIP(hostURL.Host) != nil {
|
if net.ParseIP(hostURL.Host) != nil {
|
||||||
externalIP = hostURL.Host
|
externalIPs = append(externalIPs, hostURL.Host)
|
||||||
} else {
|
} else {
|
||||||
hostname = hostURL.Host
|
hostnames = append(hostnames, hostURL.Host)
|
||||||
}
|
}
|
||||||
|
|
||||||
return externalIP, internalIP, hostname
|
return externalIPs, internalIPs, hostnames
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetControlPlaneAddresses returns all IP addresses on which the kubelet can reach the control plane.
|
// GetControlPlaneAddresses returns all IP addresses on which the kubelet can reach the control plane.
|
||||||
@ -1268,16 +1271,16 @@ func getMasterAddresses(c clientset.Interface) (string, string, string) {
|
|||||||
// e.g. internal IPs to be used (issue #56787), so that we can be
|
// e.g. internal IPs to be used (issue #56787), so that we can be
|
||||||
// sure to block the control plane fully during tests.
|
// sure to block the control plane fully during tests.
|
||||||
func GetControlPlaneAddresses(c clientset.Interface) []string {
|
func GetControlPlaneAddresses(c clientset.Interface) []string {
|
||||||
externalIP, internalIP, _ := getMasterAddresses(c)
|
externalIPs, internalIPs, _ := getControlPlaneAddresses(c)
|
||||||
|
|
||||||
ips := sets.NewString()
|
ips := sets.NewString()
|
||||||
switch TestContext.Provider {
|
switch TestContext.Provider {
|
||||||
case "gce", "gke":
|
case "gce", "gke":
|
||||||
if externalIP != "" {
|
for _, ip := range externalIPs {
|
||||||
ips.Insert(externalIP)
|
ips.Insert(ip)
|
||||||
}
|
}
|
||||||
if internalIP != "" {
|
for _, ip := range internalIPs {
|
||||||
ips.Insert(internalIP)
|
ips.Insert(ip)
|
||||||
}
|
}
|
||||||
case "aws":
|
case "aws":
|
||||||
ips.Insert(awsMasterIP)
|
ips.Insert(awsMasterIP)
|
||||||
|
Loading…
Reference in New Issue
Block a user