Implement multi-port endpoints
Instead of endpoints being a flat list, it is now a list of "subsets" where each is a struct of {Addresses, Ports}. To generate the list of endpoints you need to take union of the Cartesian products of the subsets. This is compact in the vast majority of cases, yet still represents named ports and corner cases (e.g. each pod has a different port number). This also stores subsets in a deterministic order (sorted by hash) to avoid spurious updates and comparison problems. This is a fully compatible change - old objects and clients will keepworking as long as they don't need the new functionality. This is the prep for multi-port Services, which will add API to produce endpoints in this new structure.
This commit is contained in:
@@ -283,13 +283,27 @@ func endpointsSet(c *client.Client, serviceNamespace, serviceID string, endpoint
|
||||
glog.Infof("Error on creating endpoints: %v", err)
|
||||
return false, nil
|
||||
}
|
||||
for _, e := range endpoints.Endpoints {
|
||||
glog.Infof("%s/%s endpoint: %s:%d %#v", serviceNamespace, serviceID, e.IP, e.Port, e.TargetRef)
|
||||
count := 0
|
||||
for _, ss := range endpoints.Subsets {
|
||||
for _, addr := range ss.Addresses {
|
||||
for _, port := range ss.Ports {
|
||||
count++
|
||||
glog.Infof("%s/%s endpoint: %s:%d %#v", serviceNamespace, serviceID, addr.IP, port.Port, addr.TargetRef)
|
||||
}
|
||||
}
|
||||
}
|
||||
return len(endpoints.Endpoints) == endpointCount, nil
|
||||
return count == endpointCount, nil
|
||||
}
|
||||
}
|
||||
|
||||
func countEndpoints(eps *api.Endpoints) int {
|
||||
count := 0
|
||||
for i := range eps.Subsets {
|
||||
count += len(eps.Subsets[i].Addresses) * len(eps.Subsets[i].Ports)
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
func podExists(c *client.Client, podNamespace string, podID string) wait.ConditionFunc {
|
||||
return func() (bool, error) {
|
||||
_, err := c.Pods(podNamespace).Get(podID)
|
||||
@@ -669,7 +683,7 @@ func runMasterServiceTest(client *client.Client) {
|
||||
if err != nil {
|
||||
glog.Fatalf("unexpected error listing endpoints for kubernetes service: %v", err)
|
||||
}
|
||||
if len(ep.Endpoints) == 0 {
|
||||
if countEndpoints(ep) == 0 {
|
||||
glog.Fatalf("no endpoints for kubernetes service: %v", ep)
|
||||
}
|
||||
} else {
|
||||
@@ -680,7 +694,7 @@ func runMasterServiceTest(client *client.Client) {
|
||||
if err != nil {
|
||||
glog.Fatalf("unexpected error listing endpoints for kubernetes service: %v", err)
|
||||
}
|
||||
if len(ep.Endpoints) == 0 {
|
||||
if countEndpoints(ep) == 0 {
|
||||
glog.Fatalf("no endpoints for kubernetes service: %v", ep)
|
||||
}
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user