Skip to content

Commit

Permalink
pkg/start/start_integration_test: Do not assume "deleted" for ConfigM…
Browse files Browse the repository at this point in the history
…ap lock release

From the godocs:

  $ grep -A5 '// HolderIdentity' vendor/k8s.io/client-go/tools/leaderelection/resourcelock/interface.go
    // HolderIdentity is the ID that owns the lease. If empty, no one owns this lease and
    // all callers may acquire. Versions of this library prior to Kubernetes 1.14 will not
    // attempt to acquire leases with empty identities and will wait for the full lease
    // interval to expire before attempting to reacquire. This value is set to empty when
    // a client voluntarily steps down.
    HolderIdentity       string      `json:"holderIdentity"`

The previous assumption that the release would involve ConfigMap
deletion was born with the test in 2b81f47 (cvo: Release our leader
lease when we are gracefully terminated, 2019-01-16, openshift#87).
  • Loading branch information
wking committed Aug 25, 2020
1 parent cc1921d commit dd09c3f
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions pkg/start/start_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ func TestIntegrationCVO_gracefulStepDown(t *testing.T) {

// wait until the lock record exists
err = wait.PollImmediate(200*time.Millisecond, 60*time.Second, func() (bool, error) {
_, err := kc.CoreV1().ConfigMaps(ns).Get(ctx, ns, metav1.GetOptions{})
_, _, err := lock.Get(ctx)
if err != nil {
if errors.IsNotFound(err) {
return false, nil
Expand All @@ -582,26 +582,26 @@ func TestIntegrationCVO_gracefulStepDown(t *testing.T) {
t.Fatalf("no leader election events found in\n%#v", events.Items)
}

t.Logf("after the context is closed, the lock record should be deleted quickly")
t.Logf("after the context is closed, the lock should be released quickly")
cancel()
startTime := time.Now()
var endTime time.Time
// the lock should be deleted immediately
err = wait.PollImmediate(100*time.Millisecond, 10*time.Second, func() (bool, error) {
_, err := kc.CoreV1().ConfigMaps(ns).Get(ctx, ns, metav1.GetOptions{})
if errors.IsNotFound(err) {
endTime = time.Now()
return true, nil
}
electionRecord, _, err := lock.Get(ctx)
if err != nil {
if errors.IsNotFound(err) {
return false, nil
}
return false, err
}
return false, nil
endTime = time.Now()
return electionRecord.HolderIdentity == "", nil
})
if err != nil {
t.Fatal(err)
}
t.Logf("lock deleted in %s", endTime.Sub(startTime))
t.Logf("lock released in %s", endTime.Sub(startTime))

select {
case <-time.After(time.Second):
Expand Down

0 comments on commit dd09c3f

Please sign in to comment.