add V(4) log when apiserver lease was deleted before this controller reacts

This commit is contained in:
Haowei Cai 2020-11-10 15:30:14 -08:00
parent bfebc7aefd
commit e363709d73

View File

@ -108,7 +108,10 @@ func (c *Controller) gc() {
continue continue
} }
if errors.IsNotFound(err) || lease == nil { if errors.IsNotFound(err) || lease == nil {
// the lease was deleted by the same GC controller in another apiserver // In an HA cluster, this can happen if the lease was deleted
// by the same GC controller in another apiserver, which is legit.
// We don't expect other components to delete the lease.
klog.V(4).Infof("cannot find apiserver lease: %v", err)
continue continue
} }
// evaluate lease from apiserver // evaluate lease from apiserver
@ -116,13 +119,18 @@ func (c *Controller) gc() {
continue continue
} }
if err := c.kubeclientset.CoordinationV1().Leases(c.leaseNamespace).Delete( if err := c.kubeclientset.CoordinationV1().Leases(c.leaseNamespace).Delete(
context.TODO(), lease.Name, metav1.DeleteOptions{}); err != nil && !errors.IsNotFound(err) { context.TODO(), lease.Name, metav1.DeleteOptions{}); err != nil {
// If we get a 404, the lease was deleted by the same GC controller if errors.IsNotFound(err) {
// in another apiserver. Only log error if we get something other than 404. // In an HA cluster, this can happen if the lease was deleted
// by the same GC controller in another apiserver, which is legit.
// We don't expect other components to delete the lease.
klog.V(4).Infof("apiserver lease is gone already: %v", err)
} else {
klog.Errorf("Error deleting lease: %v", err) klog.Errorf("Error deleting lease: %v", err)
} }
} }
} }
}
func isLeaseExpired(lease *v1.Lease) bool { func isLeaseExpired(lease *v1.Lease) bool {
currentTime := time.Now() currentTime := time.Now()