Commit 0ce2bfdf authored by Geoff Simmons's avatar Geoff Simmons

Fix Service deletion.

- The varnish controller deleted a service from its
map under the wrong conditions.

- Not an error if there are no Endpoints for the
Service when the Delete event is synced -- they
may already be gone.

- Varnish and haproxy controllers delete the service
from their maps before any other sync actions are
taken -- otherwise error returns may prevent the
deletion from ever happening.

- Permanent network errors on attempts to communicate
with the admin interfaces are ignored (do not cause
re-queue), since the instance may be gone.
parent b3937d5e
......@@ -44,7 +44,12 @@ func (worker *NamespaceWorker) syncEndp(key string) error {
return nil
}
if isIngress, err := worker.isVarnishIngSvc(svc); err != nil {
if eps, err := worker.getServiceEndpoints(svc); err != nil {
return err
} else if eps == nil {
return fmt.Errorf("could not find endpoints for service: %s/%s",
svc.Namespace, svc.Name)
} else if isIngress, err := worker.isVarnishIngSvc(svc, eps); err != nil {
return err
} else if isIngress {
worker.log.Infof("Endpoints changed for Varnish Ingress "+
......
......@@ -63,7 +63,12 @@ func (worker *NamespaceWorker) filterVarnishIngSvcs(
) ([]*api_v1.Service, error) {
n := 0
for _, svc := range svcs {
if isIngress, err := worker.isVarnishIngSvc(svc); err != nil {
if eps, err := worker.getServiceEndpoints(svc); err != nil {
return nil, err
} else if eps == nil {
return nil, fmt.Errorf("could not find endpoints for "+
"service: %s/%s", svc.Namespace, svc.Name)
} else if isIngress, err := worker.isVarnishIngSvc(svc, eps); err != nil {
return nil, err
} else if isIngress {
svcs[n] = svc
......
......@@ -51,14 +51,16 @@ const (
// can implement Ingress, for which this controller is responsible.
// Currently the app label must point to a hardwired name, and a
// hardwired admin port name must be defined for one of the Endpoints.
func (worker *NamespaceWorker) isVarnishIngSvc(svc *api_v1.Service) (bool, error) {
func (worker *NamespaceWorker) isVarnishIngSvc(
svc *api_v1.Service,
endps *api_v1.Endpoints,
) (bool, error) {
app, exists := svc.Labels[labelKey]
if !exists || app != labelVal {
return false, nil
}
endps, err := worker.getServiceEndpoints(svc)
if err != nil {
return false, err
if endps == nil {
panic("isVarnishIngSvc(svc, endps == nil")
}
for _, subset := range endps.Subsets {
worker.log.Debugf("Service %s/%s Endpoint subset: %+v",
......@@ -193,7 +195,12 @@ func (worker *NamespaceWorker) syncSvc(key string) error {
if err != nil {
return err
}
if isIngress, err := worker.isVarnishIngSvc(svc); err != nil {
if eps, err := worker.getServiceEndpoints(svc); err != nil {
return err
} else if eps == nil {
return fmt.Errorf("could not find endpoints for service: %s/%s",
svc.Namespace, svc.Name)
} else if isIngress, err := worker.isVarnishIngSvc(svc, eps); err != nil {
return err
} else if !isIngress {
return worker.enqueueIngressForService(svc)
......@@ -373,18 +380,29 @@ func (worker *NamespaceWorker) deleteSvc(obj interface{}) error {
return nil
}
nsKey := svc.Namespace + "/" + svc.Name
worker.log.Info("Deleting Service:", nsKey)
if isIngress, err := worker.isVarnishIngSvc(svc); err != nil {
worker.log.Info("Deleting Service: ", nsKey)
if worker.vController.HasVarnishSvc(nsKey) {
if err := worker.vController.DeleteVarnishSvc(nsKey); err != nil {
return err
}
}
if worker.hController.HasOffloader(nsKey) {
if err := worker.hController.DeleteOffldSvc(nsKey); err != nil {
return err
}
}
if endps, err := worker.getServiceEndpoints(svc); err != nil {
return err
} else if endps == nil {
worker.log.Warnf("Service %s: Endpoints already deleted", nsKey)
return nil
} else if isIngress, err := worker.isVarnishIngSvc(svc, endps); err != nil {
return err
} else if !isIngress {
return worker.enqueueIngressForService(svc)
}
if err := worker.vController.DeleteVarnishSvc(nsKey); err != nil {
return err
}
if worker.hController.HasOffloader(nsKey) {
return worker.hController.DeleteOffldSvc(nsKey)
}
return nil
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment