Skip to content

Commit

Permalink
feat: ensure that the lease can be actively released before program s…
Browse files Browse the repository at this point in the history
…hutdown to reduce the time required for failover (#827)
  • Loading branch information
nic-6443 authored and tao12345666333 committed Apr 22, 2022
1 parent 4c94c76 commit fd76c2a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
5 changes: 5 additions & 0 deletions cmd/ingress/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"os"
"os/signal"
"strings"
"sync"
"syscall"
"time"

Expand Down Expand Up @@ -124,13 +125,17 @@ the apisix cluster and others are created`,
if err != nil {
dief("failed to create ingress controller: %s", err)
}
wg := sync.WaitGroup{}
wg.Add(1)
go func() {
defer wg.Done()
if err := ingress.Run(stop); err != nil {
dief("failed to run ingress controller: %s", err)
}
}()

waitForSignal(stop)
wg.Wait()
log.Info("apisix ingress controller exited")
},
}
Expand Down
5 changes: 1 addition & 4 deletions pkg/ingress/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,7 @@ func (c *Controller) Run(stop chan struct{}) error {
c.apisix.DeleteCluster(c.cfg.APISIX.DefaultClusterName)
},
},
// Set it to false as current leaderelection implementation will report
// "Failed to release lock: resource name may not be empty" error when
// ReleaseOnCancel is true and the Run context is cancelled.
ReleaseOnCancel: false,
ReleaseOnCancel: true,
Name: "ingress-apisix",
}

Expand Down
4 changes: 2 additions & 2 deletions test/e2e/ingress/sanity.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ var _ = ginkgo.Describe("leader election", func() {
ginkgo.GinkgoT().Logf("lease is %s", *lease.Spec.HolderIdentity)
assert.Nil(ginkgo.GinkgoT(), s.KillPod(pods[leaderIdx].Name))

// Wait the old lease expire and new leader was elected.
time.Sleep(25 * time.Second)
// Wait the old leader given up lease and new leader was elected.
time.Sleep(3 * time.Second)

newLease, err := s.WaitGetLeaderLease()
assert.Nil(ginkgo.GinkgoT(), err)
Expand Down

0 comments on commit fd76c2a

Please sign in to comment.