returnfmt.Errorf("unable to refresh the service IP block: %v",err)
}
r:=ipallocator.NewCIDRRange(c.network)
for_,svc:=rangelist.Items{
if!api.IsServiceIPSet(&svc){
continue
}
ip:=net.ParseIP(svc.Spec.PortalIP)
ifip==nil{
// portal IP is broken, reallocate
util.HandleError(fmt.Errorf("the portal IP %s for service %s/%s is not a valid IP; please recreate",svc.Spec.PortalIP,svc.Name,svc.Namespace))
continue
}
switcherr:=r.Allocate(ip);err{
casenil:
caseipallocator.ErrAllocated:
// TODO: send event
// portal IP is broken, reallocate
util.HandleError(fmt.Errorf("the portal IP %s for service %s/%s was assigned to multiple services; please recreate",ip,svc.Name,svc.Namespace))
caseipallocator.ErrNotInRange:
// TODO: send event
// portal IP is broken, reallocate
util.HandleError(fmt.Errorf("the portal IP %s for service %s/%s is not within the service CIDR %s; please recreate",ip,svc.Name,svc.Namespace,c.network))
caseipallocator.ErrFull:
// TODO: send event
returnfmt.Errorf("the service CIDR %s is full; you must widen the CIDR in order to create new services")
default:
returnfmt.Errorf("unable to allocate portal IP %s for service %s/%s due to an unknown error, exiting: %v",ip,svc.Name,svc.Namespace,err)
}
}
service.SnapshotRange(latest,r)
iferr:=c.alloc.CreateOrUpdate(latest);err!=nil{
returnfmt.Errorf("unable to persist the updated service IP allocations: %v",err)