mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-10 12:32:03 +00:00
Use endpoint annotation to recover container ports in e2e tests on Mesos
This commit is contained in:
parent
c55e7bf731
commit
f04f31f799
@ -348,7 +348,7 @@ var _ = Describe("Kubectl client", func() {
|
|||||||
endpoints, err := c.Endpoints(ns).Get(name)
|
endpoints, err := c.Endpoints(ns).Get(name)
|
||||||
Expect(err).NotTo(HaveOccurred())
|
Expect(err).NotTo(HaveOccurred())
|
||||||
|
|
||||||
uidToPort := getPortsByPodUID(endpoints.Subsets)
|
uidToPort := getContainerPortsByPodUID(endpoints)
|
||||||
if len(uidToPort) == 0 {
|
if len(uidToPort) == 0 {
|
||||||
Logf("No endpoint found, retrying")
|
Logf("No endpoint found, retrying")
|
||||||
continue
|
continue
|
||||||
|
@ -22,6 +22,7 @@ import (
|
|||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -1023,16 +1024,36 @@ func validateUniqueOrFail(s []string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getPortsByPodUID(subsets []api.EndpointSubset) PortsByPodUID {
|
func getContainerPortsByPodUID(endpoints *api.Endpoints) PortsByPodUID {
|
||||||
m := PortsByPodUID{}
|
m := PortsByPodUID{}
|
||||||
for _, ss := range subsets {
|
for _, ss := range endpoints.Subsets {
|
||||||
for _, port := range ss.Ports {
|
for _, port := range ss.Ports {
|
||||||
for _, addr := range ss.Addresses {
|
for _, addr := range ss.Addresses {
|
||||||
Logf("Found pod %v and port %v", addr.TargetRef.UID, port.Port)
|
containerPort := port.Port
|
||||||
|
hostPort := port.Port
|
||||||
|
|
||||||
|
// use endpoint annotations to recover the container port in a Mesos setup
|
||||||
|
// compare contrib/mesos/pkg/service/endpoints_controller.syncService
|
||||||
|
// TODO(sttts): add ContainerPort to EndpointPort struct, defaulting to (host) Port
|
||||||
|
if providerIs("mesos/docker") {
|
||||||
|
key := fmt.Sprintf("k8s.mesosphere.io/containerPort_%s_%s_%d", port.Protocol, addr.IP, hostPort)
|
||||||
|
containerPortString := endpoints.Annotations[key]
|
||||||
|
if containerPortString == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
var err error
|
||||||
|
containerPort, err = strconv.Atoi(containerPortString)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
Logf("Mapped mesos host port %d to container port %d via annotation %s=%s", hostPort, containerPort, key, containerPortString)
|
||||||
|
}
|
||||||
|
|
||||||
|
Logf("Found pod %v, host port %d and container port %d", addr.TargetRef.UID, hostPort, containerPort)
|
||||||
if _, ok := m[addr.TargetRef.UID]; !ok {
|
if _, ok := m[addr.TargetRef.UID]; !ok {
|
||||||
m[addr.TargetRef.UID] = make([]int, 0)
|
m[addr.TargetRef.UID] = make([]int, 0)
|
||||||
}
|
}
|
||||||
m[addr.TargetRef.UID] = append(m[addr.TargetRef.UID], port.Port)
|
m[addr.TargetRef.UID] = append(m[addr.TargetRef.UID], containerPort)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1089,7 +1110,7 @@ func validateEndpointsOrFail(c *client.Client, namespace, serviceName string, ex
|
|||||||
}
|
}
|
||||||
Logf("Found endpoints %v", endpoints)
|
Logf("Found endpoints %v", endpoints)
|
||||||
|
|
||||||
portsByPodUID := getPortsByPodUID(endpoints.Subsets)
|
portsByPodUID := getContainerPortsByPodUID(endpoints)
|
||||||
Logf("Found port by pod UID %v", portsByPodUID)
|
Logf("Found port by pod UID %v", portsByPodUID)
|
||||||
|
|
||||||
expectedPortsByPodUID := translatePodNameToUIDOrFail(c, namespace, expectedEndpoints)
|
expectedPortsByPodUID := translatePodNameToUIDOrFail(c, namespace, expectedEndpoints)
|
||||||
|
Loading…
Reference in New Issue
Block a user