Skip to content

Commit

Permalink
Don't clear the cached resourcelock when errors occurs on updates
Browse files Browse the repository at this point in the history
This allows the lock to be release normally - even with a
potentially stale lock. This flow should only occur when we're
the lease holders.

Kubernetes-commit: 04170f66529f98367bc0d91f9419962948f95188
  • Loading branch information
dprotaso authored and k8s-publishing-bot committed Oct 28, 2020
1 parent 2f053ea commit 89beb5b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
8 changes: 6 additions & 2 deletions tools/leaderelection/resourcelock/configmaplock.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,12 @@ func (cml *ConfigMapLock) Update(ctx context.Context, ler LeaderElectionRecord)
cml.cm.Annotations = make(map[string]string)
}
cml.cm.Annotations[LeaderElectionRecordAnnotationKey] = string(recordBytes)
cml.cm, err = cml.Client.ConfigMaps(cml.ConfigMapMeta.Namespace).Update(ctx, cml.cm, metav1.UpdateOptions{})
return err
cm, err := cml.Client.ConfigMaps(cml.ConfigMapMeta.Namespace).Update(ctx, cml.cm, metav1.UpdateOptions{})
if err != nil {
return err
}
cml.cm = cm
return nil
}

// RecordEvent in leader election while adding meta-data
Expand Down
8 changes: 6 additions & 2 deletions tools/leaderelection/resourcelock/endpointslock.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,12 @@ func (el *EndpointsLock) Update(ctx context.Context, ler LeaderElectionRecord) e
el.e.Annotations = make(map[string]string)
}
el.e.Annotations[LeaderElectionRecordAnnotationKey] = string(recordBytes)
el.e, err = el.Client.Endpoints(el.EndpointsMeta.Namespace).Update(ctx, el.e, metav1.UpdateOptions{})
return err
e, err := el.Client.Endpoints(el.EndpointsMeta.Namespace).Update(ctx, el.e, metav1.UpdateOptions{})
if err != nil {
return err
}
el.e = e
return nil
}

// RecordEvent in leader election while adding meta-data
Expand Down
11 changes: 8 additions & 3 deletions tools/leaderelection/resourcelock/leaselock.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,14 @@ func (ll *LeaseLock) Update(ctx context.Context, ler LeaderElectionRecord) error
return errors.New("lease not initialized, call get or create first")
}
ll.lease.Spec = LeaderElectionRecordToLeaseSpec(&ler)
var err error
ll.lease, err = ll.Client.Leases(ll.LeaseMeta.Namespace).Update(ctx, ll.lease, metav1.UpdateOptions{})
return err

lease, err := ll.Client.Leases(ll.LeaseMeta.Namespace).Update(ctx, ll.lease, metav1.UpdateOptions{})
if err != nil {
return err
}

ll.lease = lease
return nil
}

// RecordEvent in leader election while adding meta-data
Expand Down

0 comments on commit 89beb5b

Please sign in to comment.