Commit bb697cee authored by Justin Santa Barbara's avatar Justin Santa Barbara

Clear LoadBalancerStatus both on LB delete and on update in the API

Although it takes some time to destroy a load balancer, we hide this complexity from the user.
parent a2717713
...@@ -256,33 +256,33 @@ func (s *ServiceController) createLoadBalancerIfNeeded(namespacedName types.Name ...@@ -256,33 +256,33 @@ func (s *ServiceController) createLoadBalancerIfNeeded(namespacedName types.Name
} }
} }
// Save the state so we can avoid a write if it doesn't change
previousState := api.LoadBalancerStatusDeepCopy(&service.Status.LoadBalancer)
if !wantsExternalLoadBalancer(service) { if !wantsExternalLoadBalancer(service) {
glog.Infof("Not creating LB for service %s that doesn't want one.", namespacedName) glog.Infof("Not creating LB for service %s that doesn't want one.", namespacedName)
return nil, notRetryable
}
glog.V(2).Infof("Creating LB for service %s", namespacedName) service.Status.LoadBalancer = api.LoadBalancerStatus{}
} else {
// The load balancer doesn't exist yet, so create it. glog.V(2).Infof("Creating LB for service %s", namespacedName)
// Save the state so we can avoid a write if it doesn't change
previousState := api.LoadBalancerStatusDeepCopy(&service.Status.LoadBalancer)
err := s.createExternalLoadBalancer(service) // The load balancer doesn't exist yet, so create it.
if err != nil { err := s.createExternalLoadBalancer(service)
return fmt.Errorf("failed to create external load balancer for service %s: %v", namespacedName, err), retryable if err != nil {
return fmt.Errorf("failed to create external load balancer for service %s: %v", namespacedName, err), retryable
}
} }
// Write the state if changed // Write the state if changed
if api.LoadBalancerStatusEqual(previousState, &service.Status.LoadBalancer) { // TODO: Be careful here ... what if there were other changes to the service?
glog.Infof("Not persisting unchanged service to registry.") if !api.LoadBalancerStatusEqual(previousState, &service.Status.LoadBalancer) {
return nil, notRetryable 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
}
} else {
glog.Infof("Not persisting unchanged LoadBalancerStatus to registry.")
} }
// If creating the load balancer succeeded, persist the updated service.
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 nil, notRetryable return nil, notRetryable
} }
......
...@@ -265,6 +265,12 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, boo ...@@ -265,6 +265,12 @@ func (rs *REST) Update(ctx api.Context, obj runtime.Object) (runtime.Object, boo
nodePortOp.ReleaseDeferred(oldNodePort) nodePortOp.ReleaseDeferred(oldNodePort)
} }
// Remove any LoadBalancerStatus now if Type != LoadBalancer;
// although loadbalancer delete is actually asynchronous, we don't need to expose the user to that complexity.
if service.Spec.Type != api.ServiceTypeLoadBalancer {
service.Status.LoadBalancer = api.LoadBalancerStatus{}
}
out, err := rs.registry.UpdateService(ctx, service) out, err := rs.registry.UpdateService(ctx, service)
if err == nil { if err == 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