func newEndpoints(service *kapi.Service, subsets ...kapi.EndpointSubset) *kapi.Endpoints { endpoints := kapi.Endpoints{ ObjectMeta: service.ObjectMeta, Subsets: []kapi.EndpointSubset{}, } endpoints.Subsets = append(endpoints.Subsets, subsets...) return &endpoints }
func newEndpoints(service kapi.Service, subsets ...kapi.EndpointSubset) kapi.Endpoints { endpoints := kapi.Endpoints{ ObjectMeta: service.ObjectMeta, Subsets: []kapi.EndpointSubset{}, } for _, subset := range subsets { endpoints.Subsets = append(endpoints.Subsets, subset) } return endpoints }
// HandleEndpoints processes watch events on the Endpoints resource and // creates and deletes pools and pool members in response. func (p *F5Plugin) HandleEndpoints(eventType watch.EventType, endpoints *kapi.Endpoints) error { glog.V(4).Infof("Processing %d Endpoints for Name: %v (%v)", len(endpoints.Subsets), endpoints.Name, eventType) for i, s := range endpoints.Subsets { glog.V(4).Infof(" Subset %d : %#v", i, s) } switch eventType { case watch.Added, watch.Modified: // Name of the pool in F5. poolname := poolName(endpoints.Namespace, endpoints.Name) if len(endpoints.Subsets) == 0 { // F5 does not permit us to delete a pool if it has a rule associated with // it. However, a pool does not necessarily have a rule associated with // it because it may be from a service for which no route was created. // Thus we first delete the endpoints from the pool, then we try to delete // the pool, in case there is no route associated, but if there *is* // a route associated though, the delete will fail and we will have to // rely on HandleRoute to delete the pool when it deletes the route. glog.V(4).Infof("Deleting endpoints for pool %s", poolname) err := p.updatePool(poolname, endpoints) if err != nil { return err } glog.V(4).Infof("Deleting pool %s", poolname) err = p.deletePool(poolname) if err != nil { return err } } else { glog.V(4).Infof("Updating endpoints for pool %s", poolname) err := p.ensurePoolExists(poolname) if err != nil { return err } err = p.updatePool(poolname, endpoints) if err != nil { return err } } case watch.Deleted: poolname := poolName(endpoints.Namespace, endpoints.Name) // presumably, the endpoints are a nil subnet now, reset it anyway endpoints.Subsets = nil err := p.updatePool(poolname, endpoints) if err != nil { return err } glog.V(4).Infof("Deleting pool %s", poolname) err = p.deletePool(poolname) if err != nil { return err } } glog.V(4).Infof("Done processing Endpoints for Name: %v.", endpoints.Name) return nil }
func (f *fakeServicesDiagnostic) addEndpointSubsetTo(service string) { endpoints := kapi.Endpoints{} endpoints.Subsets = []kapi.EndpointSubset{{}} f.endpoints[service] = endpoints }