You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by zh...@apache.org on 2022/01/11 07:46:11 UTC
[apisix-ingress-controller] branch master updated: feat: ensure that the lease can be actively released before program shutdown to reduce the time required for failover (#827)
This is an automated email from the ASF dual-hosted git repository.
zhangjintao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix-ingress-controller.git
The following commit(s) were added to refs/heads/master by this push:
new de52243 feat: ensure that the lease can be actively released before program shutdown to reduce the time required for failover (#827)
de52243 is described below
commit de522437bd3db3dc3e8d8f33c92f322de67531b8
Author: Nic <qi...@api7.ai>
AuthorDate: Tue Jan 11 15:46:05 2022 +0800
feat: ensure that the lease can be actively released before program shutdown to reduce the time required for failover (#827)
---
cmd/ingress/ingress.go | 5 +++++
pkg/ingress/controller.go | 5 +----
test/e2e/ingress/sanity.go | 4 ++--
3 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/cmd/ingress/ingress.go b/cmd/ingress/ingress.go
index 58ed28f..a905ac3 100644
--- a/cmd/ingress/ingress.go
+++ b/cmd/ingress/ingress.go
@@ -20,6 +20,7 @@ import (
"os"
"os/signal"
"strings"
+ "sync"
"syscall"
"time"
@@ -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")
},
}
diff --git a/pkg/ingress/controller.go b/pkg/ingress/controller.go
index b519b75..0496a78 100644
--- a/pkg/ingress/controller.go
+++ b/pkg/ingress/controller.go
@@ -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",
}
diff --git a/test/e2e/ingress/sanity.go b/test/e2e/ingress/sanity.go
index d8b44d4..ff3dd45 100644
--- a/test/e2e/ingress/sanity.go
+++ b/test/e2e/ingress/sanity.go
@@ -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)