add kubernetes service back when it is deleted in kubernetes cluster

pull/6/head
mfanjie 2016-06-21 09:33:09 +08:00
parent fae7285b00
commit 669bf0773f
1 changed files with 12 additions and 1 deletions

View File

@ -68,7 +68,7 @@ func (cc *clusterClientCache) syncService(key, clusterName string, clusterCache
clusterCache.serviceQueue.Add(key)
return err
}
var needUpdate bool
var needUpdate, isDeletion bool
if exists {
service, ok := serviceInterface.(*v1.Service)
if ok {
@ -81,10 +81,12 @@ func (cc *clusterClientCache) syncService(key, clusterName string, clusterCache
}
glog.Infof("Found tombstone for %v", key)
needUpdate = cc.processServiceDeletion(cachedService, clusterName)
isDeletion = true
}
} else {
glog.Infof("Can not get service %v for cluster %s from serviceStore", key, clusterName)
needUpdate = cc.processServiceDeletion(cachedService, clusterName)
isDeletion = true
}
if needUpdate {
@ -108,6 +110,15 @@ func (cc *clusterClientCache) syncService(key, clusterName string, clusterCache
}
}
}
if isDeletion {
// cachedService is not reliable here as
// deleting cache is the last step of federation service deletion
_, err := fedClient.Core().Services(cachedService.lastState.Namespace).Get(cachedService.lastState.Name)
// rebuild service if federation service still exists
if err == nil || !errors.IsNotFound(err) {
return sc.ensureClusterService(cachedService, clusterName, cachedService.appliedState, clusterCache.clientset)
}
}
return nil
}