From a49b3317945d7c2fdf4748139dc4bfefad1fecbb Mon Sep 17 00:00:00 2001 From: Clayton Coleman Date: Tue, 29 Jul 2014 11:42:19 -0400 Subject: [PATCH] Cleanly delete service without endpoints key If a service is deleted before the etcd key corresponding to its endpoints has been created, a 500 error is returned (etcd key not found). Instead, key not found should be ignored silently. There is a potential race condition with the controller creating endpoints after the service has been deleted which a cleanup task should handle in the future. Closes #684 --- pkg/registry/etcd_registry.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/registry/etcd_registry.go b/pkg/registry/etcd_registry.go index 626f9ba083e..4bed72cf900 100644 --- a/pkg/registry/etcd_registry.go +++ b/pkg/registry/etcd_registry.go @@ -274,6 +274,10 @@ func (registry *EtcdRegistry) GetService(name string) (*api.Service, error) { return &svc, nil } +func makeServiceEndpointsKey(name string) string { + return "/registry/services/endpoints/" + name +} + // DeleteService deletes a Service specified by its name. func (registry *EtcdRegistry) DeleteService(name string) error { key := makeServiceKey(name) @@ -284,9 +288,12 @@ func (registry *EtcdRegistry) DeleteService(name string) error { if err != nil { return err } - key = "/registry/services/endpoints/" + name + key = makeServiceEndpointsKey(name) _, err = registry.etcdClient.Delete(key, true) - return err + if !tools.IsEtcdNotFound(err) { + return err + } + return nil } // UpdateService replaces an existing Service.