-
Notifications
You must be signed in to change notification settings - Fork 38.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
federation: use generated listers #41927
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,9 +17,9 @@ limitations under the License. | |
package service | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"k8s.io/apimachinery/pkg/api/errors" | ||
cache "k8s.io/client-go/tools/cache" | ||
fedclientset "k8s.io/kubernetes/federation/client/clientset_generated/federation_clientset" | ||
v1 "k8s.io/kubernetes/pkg/api/v1" | ||
|
@@ -81,29 +81,25 @@ func (cc *clusterClientCache) syncEndpoint(key, clusterName string, clusterCache | |
// here we filtered all non-federation services | ||
return nil | ||
} | ||
endpointInterface, exists, err := clusterCache.endpointStore.GetByKey(key) | ||
namespace, name, err := cache.SplitMetaNamespaceKey(key) | ||
if err != nil { | ||
glog.Errorf("Did not successfully get %v from store: %v, will retry later", key, err) | ||
clusterCache.endpointQueue.Add(key) | ||
return err | ||
} | ||
if exists { | ||
endpoint, ok := endpointInterface.(*v1.Endpoints) | ||
if ok { | ||
glog.V(4).Infof("Found endpoint for federation service %s/%s from cluster %s", endpoint.Namespace, endpoint.Name, clusterName) | ||
err = cc.processEndpointUpdate(cachedService, endpoint, clusterName, serviceController) | ||
} else { | ||
_, ok := endpointInterface.(cache.DeletedFinalStateUnknown) | ||
if !ok { | ||
return fmt.Errorf("Object contained wasn't a service or a deleted key: %+v", endpointInterface) | ||
} | ||
glog.Infof("Found tombstone for %v", key) | ||
err = cc.processEndpointDeletion(cachedService, clusterName, serviceController) | ||
} | ||
} else { | ||
endpoint, err := clusterCache.endpointStore.Endpoints(namespace).Get(name) | ||
switch { | ||
case errors.IsNotFound(err): | ||
// service absence in store means watcher caught the deletion, ensure LB info is cleaned | ||
glog.Infof("Can not get endpoint %v for cluster %s from endpointStore", key, clusterName) | ||
err = cc.processEndpointDeletion(cachedService, clusterName, serviceController) | ||
case err != nil: | ||
glog.Errorf("Did not successfully get %v from store: %v, will retry later", key, err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. util.HandleError. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would require sweeping through the entire package and doing a find/replace. I opted not to do that here and would prefer to do it in a follow up if that's ok? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You added new code? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "ish". Before, it just did |
||
clusterCache.endpointQueue.Add(key) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this case used to return There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @deads2k fixed, ptal |
||
return err | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (no action required) I don't think returning an error from this function makes any sense. The only thing the caller does is log it at Info level, and it's already logged at Error level. |
||
default: | ||
glog.V(4).Infof("Found endpoint for federation service %s/%s from cluster %s", endpoint.Namespace, endpoint.Name, clusterName) | ||
err = cc.processEndpointUpdate(cachedService, endpoint, clusterName, serviceController) | ||
} | ||
if err != nil { | ||
glog.Errorf("Failed to sync service: %+v, put back to service queue", err) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,6 @@ limitations under the License. | |
package service | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"k8s.io/apimachinery/pkg/api/errors" | ||
|
@@ -85,31 +84,26 @@ func (cc *clusterClientCache) syncService(key, clusterName string, clusterCache | |
// if serviceCache does not exists, that means the service is not created by federation, we should skip it | ||
return nil | ||
} | ||
serviceInterface, exists, err := clusterCache.serviceStore.Indexer.GetByKey(key) | ||
namespace, name, err := cache.SplitMetaNamespaceKey(key) | ||
if err != nil { | ||
glog.Errorf("Did not successfully get %v from store: %v, will retry later", key, err) | ||
clusterCache.serviceQueue.Add(key) | ||
return err | ||
} | ||
var needUpdate, isDeletion bool | ||
if exists { | ||
service, ok := serviceInterface.(*v1.Service) | ||
if ok { | ||
glog.V(4).Infof("Found service for federation service %s/%s from cluster %s", service.Namespace, service.Name, clusterName) | ||
needUpdate = cc.processServiceUpdate(cachedService, service, clusterName) | ||
} else { | ||
_, ok := serviceInterface.(cache.DeletedFinalStateUnknown) | ||
if !ok { | ||
return fmt.Errorf("Object contained wasn't a service or a deleted key: %+v", serviceInterface) | ||
} | ||
glog.Infof("Found tombstone for %v", key) | ||
needUpdate = cc.processServiceDeletion(cachedService, clusterName) | ||
isDeletion = true | ||
} | ||
} else { | ||
service, err := clusterCache.serviceStore.Services(namespace).Get(name) | ||
switch { | ||
case errors.IsNotFound(err): | ||
glog.Infof("Can not get service %v for cluster %s from serviceStore", key, clusterName) | ||
needUpdate = cc.processServiceDeletion(cachedService, clusterName) | ||
isDeletion = true | ||
case err != nil: | ||
glog.Errorf("Did not successfully get %v from store: %v, will retry later", key, err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. util.HandleError |
||
clusterCache.serviceQueue.Add(key) | ||
return err | ||
default: | ||
glog.V(4).Infof("Found service for federation service %s/%s from cluster %s", service.Namespace, service.Name, clusterName) | ||
needUpdate = cc.processServiceUpdate(cachedService, service, clusterName) | ||
} | ||
|
||
if needUpdate { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,7 @@ import ( | |
"k8s.io/kubernetes/pkg/api" | ||
v1 "k8s.io/kubernetes/pkg/api/v1" | ||
kubeclientset "k8s.io/kubernetes/pkg/client/clientset_generated/clientset" | ||
"k8s.io/kubernetes/pkg/client/legacylisters" | ||
corelisters "k8s.io/kubernetes/pkg/client/listers/core/v1" | ||
"k8s.io/kubernetes/pkg/controller" | ||
) | ||
|
||
|
@@ -121,7 +121,7 @@ type ServiceController struct { | |
serviceCache *serviceCache | ||
clusterCache *clusterClientCache | ||
// A store of services, populated by the serviceController | ||
serviceStore listers.StoreToServiceLister | ||
serviceStore corelisters.ServiceLister | ||
// Watches changes to all services | ||
serviceController cache.Controller | ||
federatedInformer fedutil.FederatedInformer | ||
|
@@ -180,7 +180,8 @@ func New(federationClient fedclientset.Interface, dns dnsprovider.Interface, | |
knownClusterSet: make(sets.String), | ||
} | ||
s.clusterDeliverer = util.NewDelayingDeliverer() | ||
s.serviceStore.Indexer, s.serviceController = cache.NewIndexerInformer( | ||
var serviceIndexer cache.Indexer | ||
serviceIndexer, s.serviceController = cache.NewIndexerInformer( | ||
&cache.ListWatch{ | ||
ListFunc: func(options metav1.ListOptions) (pkgruntime.Object, error) { | ||
return s.federationClient.Core().Services(metav1.NamespaceAll).List(options) | ||
|
@@ -203,6 +204,7 @@ func New(federationClient fedclientset.Interface, dns dnsprovider.Interface, | |
}, | ||
cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, | ||
) | ||
s.serviceStore = corelisters.NewServiceLister(serviceIndexer) | ||
s.clusterStore.Store, s.clusterController = cache.NewInformer( | ||
&cache.ListWatch{ | ||
ListFunc: func(options metav1.ListOptions) (pkgruntime.Object, error) { | ||
|
@@ -938,44 +940,40 @@ func (s *ServiceController) syncService(key string) error { | |
defer func() { | ||
glog.V(4).Infof("Finished syncing service %q (%v)", key, time.Now().Sub(startTime)) | ||
}() | ||
// obj holds the latest service info from apiserver | ||
objFromStore, exists, err := s.serviceStore.Indexer.GetByKey(key) | ||
|
||
namespace, name, err := cache.SplitMetaNamespaceKey(key) | ||
if err != nil { | ||
glog.Errorf("Unable to retrieve service %v from store: %v", key, err) | ||
s.queue.Add(key) | ||
return err | ||
} | ||
if !exists { | ||
|
||
service, err := s.serviceStore.Services(namespace).Get(name) | ||
switch { | ||
case errors.IsNotFound(err): | ||
// service absence in store means watcher caught the deletion, ensure LB info is cleaned | ||
glog.Infof("Service has been deleted %v", key) | ||
err, retryDelay = s.processServiceDeletion(key) | ||
} | ||
// Create a copy before modifying the obj to prevent race condition with | ||
// other readers of obj from store. | ||
obj, err := conversion.NewCloner().DeepCopy(objFromStore) | ||
if err != nil { | ||
glog.Errorf("Error in deep copying service %v retrieved from store: %v", key, err) | ||
case err != nil: | ||
glog.Errorf("Unable to retrieve service %v from store: %v", key, err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. handleError everywhere |
||
s.queue.Add(key) | ||
return err | ||
} | ||
|
||
if exists { | ||
service, ok := obj.(*v1.Service) | ||
if ok { | ||
cachedService = s.serviceCache.getOrCreate(key) | ||
err, retryDelay = s.processServiceUpdate(cachedService, service, key) | ||
} else { | ||
tombstone, ok := obj.(cache.DeletedFinalStateUnknown) | ||
if !ok { | ||
return fmt.Errorf("Object contained wasn't a service or a deleted key: %+v", obj) | ||
} | ||
glog.Infof("Found tombstone for %v", key) | ||
err, retryDelay = s.processServiceDeletion(tombstone.Key) | ||
default: | ||
// Create a copy before modifying the obj to prevent race condition with | ||
// other readers of obj from store. | ||
copy, err := conversion.NewCloner().DeepCopy(service) | ||
if err != nil { | ||
glog.Errorf("Error in deep copying service %v retrieved from store: %v", key, err) | ||
s.queue.Add(key) | ||
return err | ||
} | ||
service := copy.(*v1.Service) | ||
cachedService = s.serviceCache.getOrCreate(key) | ||
err, retryDelay = s.processServiceUpdate(cachedService, service, key) | ||
} | ||
|
||
if retryDelay != 0 { | ||
s.enqueueService(obj) | ||
s.enqueueService(service) | ||
} else if err != nil { | ||
runtime.HandleError(fmt.Errorf("Failed to process service. Not retrying: %v", err)) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could never actually have happened before, rigth?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I honestly don't remember in what situation(s) a tombstone is possible