Move GetPortURL to ingress e2e fw
This commit is contained in:
@@ -24,17 +24,14 @@ import (
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/fields"
|
||||
"k8s.io/apimachinery/pkg/util/rand"
|
||||
"k8s.io/apimachinery/pkg/util/sets"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
clientset "k8s.io/client-go/kubernetes"
|
||||
v1helper "k8s.io/kubernetes/pkg/apis/core/v1/helper"
|
||||
nodectlr "k8s.io/kubernetes/pkg/controller/nodelifecycle"
|
||||
schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
|
||||
e2elog "k8s.io/kubernetes/test/e2e/framework/log"
|
||||
"k8s.io/kubernetes/test/e2e/system"
|
||||
testutils "k8s.io/kubernetes/test/utils"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -189,63 +186,6 @@ func TotalReady(c clientset.Interface) (int, error) {
|
||||
return len(nodes.Items), nil
|
||||
}
|
||||
|
||||
// getSvcNodePort returns the node port for the given service:port.
|
||||
func getSvcNodePort(client clientset.Interface, ns, name string, svcPort int) (int, error) {
|
||||
svc, err := client.CoreV1().Services(ns).Get(name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
for _, p := range svc.Spec.Ports {
|
||||
if p.Port == int32(svcPort) {
|
||||
if p.NodePort != 0 {
|
||||
return int(p.NodePort), nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0, fmt.Errorf(
|
||||
"No node port found for service %v, port %v", name, svcPort)
|
||||
}
|
||||
|
||||
// GetPortURL returns the url to a nodeport Service.
|
||||
func GetPortURL(client clientset.Interface, ns, name string, svcPort int) (string, error) {
|
||||
nodePort, err := getSvcNodePort(client, ns, name, svcPort)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
// This list of nodes must not include the master, which is marked
|
||||
// unschedulable, since the master doesn't run kube-proxy. Without
|
||||
// kube-proxy NodePorts won't work.
|
||||
var nodes *v1.NodeList
|
||||
if wait.PollImmediate(poll, singleCallTimeout, func() (bool, error) {
|
||||
nodes, err = client.CoreV1().Nodes().List(metav1.ListOptions{FieldSelector: fields.Set{
|
||||
"spec.unschedulable": "false",
|
||||
}.AsSelector().String()})
|
||||
if err != nil {
|
||||
if testutils.IsRetryableAPIError(err) {
|
||||
return false, nil
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
return true, nil
|
||||
}) != nil {
|
||||
return "", err
|
||||
}
|
||||
if len(nodes.Items) == 0 {
|
||||
return "", fmt.Errorf("Unable to list nodes in cluster")
|
||||
}
|
||||
for _, node := range nodes.Items {
|
||||
for _, address := range node.Status.Addresses {
|
||||
if address.Type == v1.NodeExternalIP {
|
||||
if address.Address != "" {
|
||||
host := net.JoinHostPort(address.Address, fmt.Sprint(nodePort))
|
||||
return fmt.Sprintf("http://%s", host), nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return "", fmt.Errorf("Failed to find external address for service %v", name)
|
||||
}
|
||||
|
||||
// GetExternalIP returns node external IP concatenated with port 22 for ssh
|
||||
// e.g. 1.2.3.4:22
|
||||
func GetExternalIP(node *v1.Node) (string, error) {
|
||||
|
Reference in New Issue
Block a user