Merge pull request #55758 from wackxu/updateService

Automatic merge from submit-queue (batch tested with PRs 55657, 54758, 47584, 55758, 55651). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>.

WaitForCacheSync fail should return for service controller

**What this PR does / why we need it**:

1. WaitForCacheSync fail should return for service controller as other controller
2. remove unused function
3. fix several weak error follow up #54280 according to https://github.com/golang/go/wiki/CodeReviewComments#error-strings

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
Fixes #

**Special notes for your reviewer**:

**Release note**:

```release-note
NONE
```
This commit is contained in:
Kubernetes Submit Queue 2017-11-15 23:57:31 -08:00 committed by GitHub
commit 817e8a2e43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 14 deletions

View File

@ -188,6 +188,7 @@ func (s *ServiceController) Run(stopCh <-chan struct{}, workers int) {
defer glog.Info("Shutting down service controller") defer glog.Info("Shutting down service controller")
if !controller.WaitForCacheSync("service", stopCh, s.serviceListerSynced, s.nodeListerSynced) { if !controller.WaitForCacheSync("service", stopCh, s.serviceListerSynced, s.nodeListerSynced) {
return
} }
for i := 0; i < workers; i++ { for i := 0; i < workers; i++ {
@ -219,12 +220,12 @@ func (s *ServiceController) worker() {
func (s *ServiceController) init() error { func (s *ServiceController) init() error {
if s.cloud == nil { if s.cloud == nil {
return fmt.Errorf("WARNING: no cloud provider provided, services of type LoadBalancer will fail.") return fmt.Errorf("WARNING: no cloud provider provided, services of type LoadBalancer will fail")
} }
balancer, ok := s.cloud.LoadBalancer() balancer, ok := s.cloud.LoadBalancer()
if !ok { if !ok {
return fmt.Errorf("the cloud provider does not support external load balancers.") return fmt.Errorf("the cloud provider does not support external load balancers")
} }
s.balancer = balancer s.balancer = balancer
@ -284,7 +285,7 @@ func (s *ServiceController) createLoadBalancerIfNeeded(key string, service *v1.S
if !wantsLoadBalancer(service) { if !wantsLoadBalancer(service) {
_, exists, err := s.balancer.GetLoadBalancer(s.clusterName, service) _, exists, err := s.balancer.GetLoadBalancer(s.clusterName, service)
if err != nil { if err != nil {
return fmt.Errorf("Error getting LB for service %s: %v", key, err), retryable return fmt.Errorf("error getting LB for service %s: %v", key, err), retryable
} }
if exists { if exists {
glog.Infof("Deleting existing load balancer for service %s that no longer needs a load balancer.", key) glog.Infof("Deleting existing load balancer for service %s that no longer needs a load balancer.", key)
@ -304,7 +305,7 @@ func (s *ServiceController) createLoadBalancerIfNeeded(key string, service *v1.S
s.eventRecorder.Event(service, v1.EventTypeNormal, "EnsuringLoadBalancer", "Ensuring load balancer") s.eventRecorder.Event(service, v1.EventTypeNormal, "EnsuringLoadBalancer", "Ensuring load balancer")
newState, err = s.ensureLoadBalancer(service) newState, err = s.ensureLoadBalancer(service)
if err != nil { if err != nil {
return fmt.Errorf("Failed to ensure load balancer for service %s: %v", key, err), retryable return fmt.Errorf("failed to ensure load balancer for service %s: %v", key, err), retryable
} }
s.eventRecorder.Event(service, v1.EventTypeNormal, "EnsuredLoadBalancer", "Ensured load balancer") s.eventRecorder.Event(service, v1.EventTypeNormal, "EnsuredLoadBalancer", "Ensured load balancer")
} }
@ -319,7 +320,7 @@ func (s *ServiceController) createLoadBalancerIfNeeded(key string, service *v1.S
service.Status.LoadBalancer = *newState service.Status.LoadBalancer = *newState
if err := s.persistUpdate(service); err != nil { if err := s.persistUpdate(service); err != nil {
return fmt.Errorf("Failed to persist updated status to apiserver, even after retries. Giving up: %v", err), notRetryable return fmt.Errorf("failed to persist updated status to apiserver, even after retries. Giving up: %v", err), notRetryable
} }
} else { } else {
glog.V(2).Infof("Not persisting unchanged LoadBalancerStatus for service %s to registry.", key) glog.V(2).Infof("Not persisting unchanged LoadBalancerStatus for service %s to registry.", key)
@ -346,7 +347,7 @@ func (s *ServiceController) persistUpdate(service *v1.Service) error {
// TODO: Try to resolve the conflict if the change was unrelated to load // TODO: Try to resolve the conflict if the change was unrelated to load
// balancer status. For now, just pass it up the stack. // balancer status. For now, just pass it up the stack.
if errors.IsConflict(err) { if errors.IsConflict(err) {
return fmt.Errorf("Not persisting update to service '%s/%s' that has been changed since we received it: %v", return fmt.Errorf("not persisting update to service '%s/%s' that has been changed since we received it: %v",
service.Namespace, service.Name, err) service.Namespace, service.Name, err)
} }
glog.Warningf("Failed to persist updated LoadBalancerStatus to service '%s/%s' after creating its load balancer: %v", glog.Warningf("Failed to persist updated LoadBalancerStatus to service '%s/%s' after creating its load balancer: %v",
@ -511,7 +512,7 @@ func getPortsForLB(service *v1.Service) ([]*v1.ServicePort, error) {
protocol = sp.Protocol protocol = sp.Protocol
} else if protocol != sp.Protocol && wantsLoadBalancer(service) { } else if protocol != sp.Protocol && wantsLoadBalancer(service) {
// TODO: Convert error messages to use event recorder // TODO: Convert error messages to use event recorder
return nil, fmt.Errorf("mixed protocol external load balancers are not supported.") return nil, fmt.Errorf("mixed protocol external load balancers are not supported")
} }
} }
return ports, nil return ports, nil
@ -599,10 +600,6 @@ func stringSlicesEqual(x, y []string) bool {
return true return true
} }
func includeNodeFromNodeList(node *v1.Node) bool {
return !node.Spec.Unschedulable
}
func getNodeConditionPredicate() corelisters.NodeConditionPredicate { func getNodeConditionPredicate() corelisters.NodeConditionPredicate {
return func(node *v1.Node) bool { return func(node *v1.Node) bool {
// We add the master to the node list, but its unschedulable. So we use this to filter // We add the master to the node list, but its unschedulable. So we use this to filter
@ -784,7 +781,7 @@ func (s *ServiceController) syncService(key string) error {
s.workingQueue.AddAfter(obj, delay) s.workingQueue.AddAfter(obj, delay)
}(key, retryDelay) }(key, retryDelay)
} else if err != nil { } else if err != nil {
runtime.HandleError(fmt.Errorf("Failed to process service %v. Not retrying: %v", key, err)) runtime.HandleError(fmt.Errorf("failed to process service %v. Not retrying: %v", key, err))
} }
return nil return nil
} }
@ -795,7 +792,7 @@ func (s *ServiceController) syncService(key string) error {
func (s *ServiceController) processServiceDeletion(key string) (error, time.Duration) { func (s *ServiceController) processServiceDeletion(key string) (error, time.Duration) {
cachedService, ok := s.cache.get(key) cachedService, ok := s.cache.get(key)
if !ok { if !ok {
return fmt.Errorf("Service %s not in cache even though the watcher thought it was. Ignoring the deletion.", key), doNotRetry return fmt.Errorf("service %s not in cache even though the watcher thought it was. Ignoring the deletion", key), doNotRetry
} }
return s.processLoadBalancerDelete(cachedService, key) return s.processLoadBalancerDelete(cachedService, key)
} }

View File

@ -506,7 +506,7 @@ func TestProcessServiceDeletion(t *testing.T) {
}, },
expectedFn: func(svcErr error, retryDuration time.Duration) error { expectedFn: func(svcErr error, retryDuration time.Duration) error {
expectedError := "Service external-balancer not in cache even though the watcher thought it was. Ignoring the deletion." expectedError := "service external-balancer not in cache even though the watcher thought it was. Ignoring the deletion"
if svcErr == nil || svcErr.Error() != expectedError { if svcErr == nil || svcErr.Error() != expectedError {
//cannot be nil or Wrong error message //cannot be nil or Wrong error message
return fmt.Errorf("Expected=%v Obtained=%v", expectedError, svcErr) return fmt.Errorf("Expected=%v Obtained=%v", expectedError, svcErr)