mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-07-17 11:28:58 +00:00
Merge pull request #137535 from danwinship/nodeip-e2e-cleanups
e2e cleanups related to node IPs
This commit is contained in:
@@ -89,18 +89,6 @@ type PodNode struct {
|
||||
Node string
|
||||
}
|
||||
|
||||
// FirstAddress returns the first address of the given type of each node.
|
||||
func FirstAddress(nodelist *v1.NodeList, addrType v1.NodeAddressType) string {
|
||||
for _, n := range nodelist.Items {
|
||||
for _, addr := range n.Status.Addresses {
|
||||
if addr.Type == addrType && addr.Address != "" {
|
||||
return addr.Address
|
||||
}
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func isNodeConditionSetAsExpected(node *v1.Node, conditionType v1.NodeConditionType, wantTrue, silent bool) bool {
|
||||
// Check the node readiness condition (logging all).
|
||||
for _, cond := range node.Status.Conditions {
|
||||
@@ -294,19 +282,6 @@ func CollectAddresses(nodes *v1.NodeList, addressType v1.NodeAddressType) []stri
|
||||
return ips
|
||||
}
|
||||
|
||||
// PickIP picks one public node IP
|
||||
func PickIP(ctx context.Context, c clientset.Interface) (string, error) {
|
||||
publicIps, err := GetPublicIps(ctx, c)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("get node public IPs error: %w", err)
|
||||
}
|
||||
if len(publicIps) == 0 {
|
||||
return "", fmt.Errorf("got unexpected number (%d) of public IPs", len(publicIps))
|
||||
}
|
||||
ip := publicIps[0]
|
||||
return ip, nil
|
||||
}
|
||||
|
||||
// GetPublicIps returns a public IP list of nodes.
|
||||
func GetPublicIps(ctx context.Context, c clientset.Interface) ([]string, error) {
|
||||
nodes, err := GetReadySchedulableNodes(ctx, c)
|
||||
|
||||
@@ -361,26 +361,6 @@ func (j *TestJig) CreateLoadBalancerService(ctx context.Context, timeout time.Du
|
||||
return j.WaitForLoadBalancer(ctx, timeout)
|
||||
}
|
||||
|
||||
// GetEndpointNodes returns a map of nodenames:external-ip on which the
|
||||
// endpoints of the Service are running.
|
||||
func (j *TestJig) GetEndpointNodes(ctx context.Context) (map[string][]string, error) {
|
||||
return j.GetEndpointNodesWithIP(ctx, v1.NodeExternalIP)
|
||||
}
|
||||
|
||||
// GetEndpointNodesWithIP returns a map of nodenames:<ip of given type> on which the
|
||||
// endpoints of the Service are running.
|
||||
func (j *TestJig) GetEndpointNodesWithIP(ctx context.Context, addressType v1.NodeAddressType) (map[string][]string, error) {
|
||||
nodes, err := j.ListNodesWithEndpoint(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
nodeMap := map[string][]string{}
|
||||
for _, node := range nodes {
|
||||
nodeMap[node.Name] = e2enode.GetAddresses(&node, addressType)
|
||||
}
|
||||
return nodeMap, nil
|
||||
}
|
||||
|
||||
// ListNodesWithEndpoint returns a list of nodes on which the
|
||||
// endpoints of the given Service are running.
|
||||
func (j *TestJig) ListNodesWithEndpoint(ctx context.Context) ([]v1.Node, error) {
|
||||
|
||||
@@ -125,8 +125,7 @@ func makePrivateKeySignerFromFile(key string) (ssh.Signer, error) {
|
||||
// NodeSSHHosts returns SSH-able host names for all schedulable nodes.
|
||||
// If it can't find any external IPs, it falls back to
|
||||
// looking for internal IPs. If it can't find an internal IP for every node it
|
||||
// returns an error, though it still returns all hosts that it found in that
|
||||
// case.
|
||||
// returns an error.
|
||||
func NodeSSHHosts(ctx context.Context, c clientset.Interface) ([]string, error) {
|
||||
nodelist := waitListSchedulableNodesOrDie(ctx, c)
|
||||
|
||||
@@ -136,10 +135,9 @@ func NodeSSHHosts(ctx context.Context, c clientset.Interface) ([]string, error)
|
||||
framework.Logf("No external IP address on nodes, falling back to internal IPs")
|
||||
hosts = nodeAddresses(nodelist, v1.NodeInternalIP)
|
||||
}
|
||||
|
||||
// Error if neither External nor Internal IPs weren't available for all nodes.
|
||||
if len(hosts) != len(nodelist.Items) {
|
||||
return hosts, fmt.Errorf(
|
||||
// Something is wrong; all schedulable nodes should have at least one IP.
|
||||
return nil, fmt.Errorf(
|
||||
"only found %d IPs on nodes, but found %d nodes. Nodelist: %v",
|
||||
len(hosts), len(nodelist.Items), nodelist)
|
||||
}
|
||||
|
||||
@@ -698,16 +698,17 @@ func waitForAPIServerUp(ctx context.Context, c clientset.Interface) error {
|
||||
// getEndpointNodesWithInternalIP returns a map of nodenames:internal-ip on which the
|
||||
// endpoints of the Service are running.
|
||||
func getEndpointNodesWithInternalIP(ctx context.Context, jig *e2eservice.TestJig) (map[string]string, error) {
|
||||
nodesWithIPs, err := jig.GetEndpointNodesWithIP(ctx, v1.NodeInternalIP)
|
||||
nodes, err := jig.ListNodesWithEndpoint(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
endpointsNodeMap := make(map[string]string, len(nodesWithIPs))
|
||||
for nodeName, internalIPs := range nodesWithIPs {
|
||||
endpointsNodeMap := make(map[string]string, len(nodes))
|
||||
for _, node := range nodes {
|
||||
internalIPs := e2enode.GetAddresses(&node, v1.NodeInternalIP)
|
||||
if len(internalIPs) < 1 {
|
||||
return nil, fmt.Errorf("no internal ip found for node %s", nodeName)
|
||||
return nil, fmt.Errorf("no internal ip found for node %s", node.Name)
|
||||
}
|
||||
endpointsNodeMap[nodeName] = internalIPs[0]
|
||||
endpointsNodeMap[node.Name] = internalIPs[0]
|
||||
}
|
||||
return endpointsNodeMap, nil
|
||||
}
|
||||
|
||||
@@ -54,8 +54,6 @@ var _ = sigDescribe("Services", skipUnlessWindows(func() {
|
||||
ns := f.Namespace.Name
|
||||
|
||||
jig := e2eservice.NewTestJig(cs, ns, serviceName)
|
||||
nodeIP, err := e2enode.PickIP(ctx, jig.Client)
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
ginkgo.By("creating service " + serviceName + " with type=NodePort in namespace " + ns)
|
||||
svc, err := jig.CreateTCPService(ctx, func(svc *v1.Service) {
|
||||
@@ -63,6 +61,11 @@ var _ = sigDescribe("Services", skipUnlessWindows(func() {
|
||||
})
|
||||
framework.ExpectNoError(err)
|
||||
|
||||
node, err := e2enode.GetRandomReadySchedulableNode(ctx, jig.Client)
|
||||
framework.ExpectNoError(err)
|
||||
ips := e2enode.GetAddressesByTypeAndFamily(node, v1.NodeInternalIP, svc.Spec.IPFamilies[0])
|
||||
gomega.Expect(ips).NotTo(gomega.BeEmpty())
|
||||
nodeIP := ips[0]
|
||||
nodePort := int(svc.Spec.Ports[0].NodePort)
|
||||
|
||||
ginkgo.By("creating Pod to be part of service " + serviceName)
|
||||
|
||||
Reference in New Issue
Block a user