mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
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.
This commit is contained in:
parent
a271771341
commit
bb697cee7e
@ -256,33 +256,33 @@ func (s *ServiceController) createLoadBalancerIfNeeded(namespacedName types.Name
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !wantsExternalLoadBalancer(service) {
|
|
||||||
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)
|
|
||||||
|
|
||||||
// The load balancer doesn't exist yet, so create it.
|
|
||||||
|
|
||||||
// Save the state so we can avoid a write if it doesn't change
|
// Save the state so we can avoid a write if it doesn't change
|
||||||
previousState := api.LoadBalancerStatusDeepCopy(&service.Status.LoadBalancer)
|
previousState := api.LoadBalancerStatusDeepCopy(&service.Status.LoadBalancer)
|
||||||
|
|
||||||
|
if !wantsExternalLoadBalancer(service) {
|
||||||
|
glog.Infof("Not creating LB for service %s that doesn't want one.", namespacedName)
|
||||||
|
|
||||||
|
service.Status.LoadBalancer = api.LoadBalancerStatus{}
|
||||||
|
} else {
|
||||||
|
glog.V(2).Infof("Creating LB for service %s", namespacedName)
|
||||||
|
|
||||||
|
// The load balancer doesn't exist yet, so create it.
|
||||||
err := s.createExternalLoadBalancer(service)
|
err := s.createExternalLoadBalancer(service)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create external load balancer for service %s: %v", namespacedName, err), retryable
|
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 {
|
||||||
}
|
|
||||||
|
|
||||||
// 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 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.")
|
||||||
|
}
|
||||||
|
|
||||||
return nil, notRetryable
|
return nil, notRetryable
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user