mirror of
https://github.com/kubernetes/client-go.git
synced 2026-01-30 05:50:01 +00:00
Merge pull request #135371 from Nikateen/contextual-logging-leaderelection
Use contextual logging in leaderelection Kubernetes-commit: 3558d1e9ce6829e91b6e81bcf96dda03b21f6258
This commit is contained in:
4
go.mod
4
go.mod
@@ -24,8 +24,8 @@ require (
|
||||
golang.org/x/time v0.9.0
|
||||
google.golang.org/protobuf v1.36.8
|
||||
gopkg.in/evanphx/json-patch.v4 v4.13.0
|
||||
k8s.io/api v0.0.0-20251218062647-56ee7b10ed3f
|
||||
k8s.io/apimachinery v0.0.0-20251218062152-a9de6f8b12f4
|
||||
k8s.io/api v0.0.0-20251218062648-50474f4a1619
|
||||
k8s.io/apimachinery v0.0.0-20251218062153-94056eccfb12
|
||||
k8s.io/klog/v2 v2.130.1
|
||||
k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912
|
||||
k8s.io/utils v0.0.0-20251002143259-bc988d571ff4
|
||||
|
||||
8
go.sum
8
go.sum
@@ -123,10 +123,10 @@ gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
k8s.io/api v0.0.0-20251218062647-56ee7b10ed3f h1:N4fGyAbqjSiHraQokHH8xRlIjp/0coRsXYNKPNXo4Qc=
|
||||
k8s.io/api v0.0.0-20251218062647-56ee7b10ed3f/go.mod h1:oM7eVrx5llqFChHq1g9VJGls8yBZAjmDBwTWVsN9tr4=
|
||||
k8s.io/apimachinery v0.0.0-20251218062152-a9de6f8b12f4 h1:6qzElS1kwIIk7oKF6tlSLLh7bQLDZ60+J406vLzB2Wg=
|
||||
k8s.io/apimachinery v0.0.0-20251218062152-a9de6f8b12f4/go.mod h1:jQCgFZFR1F4Ik7hvr2g84RTJSZegBc8yHgFWKn//hns=
|
||||
k8s.io/api v0.0.0-20251218062648-50474f4a1619 h1:uqLi4NaZ8GcjLm5jQaPyxzeVXqTGKyzUiUo8DXD/8eQ=
|
||||
k8s.io/api v0.0.0-20251218062648-50474f4a1619/go.mod h1:BF6wJ9t7NKHa7KSQlnAZ2/iI3e9YLY3YRFaMfEzOeec=
|
||||
k8s.io/apimachinery v0.0.0-20251218062153-94056eccfb12 h1:EcHv2BCdOt2p8EIoLqsEFb2lTgBE7gy07YerdzjNCGY=
|
||||
k8s.io/apimachinery v0.0.0-20251218062153-94056eccfb12/go.mod h1:jQCgFZFR1F4Ik7hvr2g84RTJSZegBc8yHgFWKn//hns=
|
||||
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk=
|
||||
k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE=
|
||||
k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912 h1:Y3gxNAuB0OBLImH611+UDZcmKS3g6CthxToOb37KgwE=
|
||||
|
||||
@@ -256,7 +256,7 @@ func (le *LeaderElector) acquire(ctx context.Context) bool {
|
||||
desc := le.config.Lock.Describe()
|
||||
logger := klog.FromContext(ctx)
|
||||
logger.Info("Attempting to acquire leader lease...", "lock", desc)
|
||||
wait.JitterUntil(func() {
|
||||
wait.JitterUntilWithContext(ctx, func(ctx context.Context) {
|
||||
if !le.config.Coordinated {
|
||||
succeeded = le.tryAcquireOrRenew(ctx)
|
||||
} else {
|
||||
@@ -271,7 +271,7 @@ func (le *LeaderElector) acquire(ctx context.Context) bool {
|
||||
le.metrics.leaderOn(le.config.Name)
|
||||
logger.Info("Successfully acquired lease", "lock", desc)
|
||||
cancel()
|
||||
}, le.config.RetryPeriod, JitterFactor, true, ctx.Done())
|
||||
}, le.config.RetryPeriod, JitterFactor, true)
|
||||
return succeeded
|
||||
}
|
||||
|
||||
@@ -281,7 +281,7 @@ func (le *LeaderElector) renew(ctx context.Context) {
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
logger := klog.FromContext(ctx)
|
||||
wait.Until(func() {
|
||||
wait.UntilWithContext(ctx, func(ctx context.Context) {
|
||||
err := wait.PollUntilContextTimeout(ctx, le.config.RetryPeriod, le.config.RenewDeadline, true, func(ctx context.Context) (done bool, err error) {
|
||||
if !le.config.Coordinated {
|
||||
return le.tryAcquireOrRenew(ctx), nil
|
||||
@@ -298,7 +298,7 @@ func (le *LeaderElector) renew(ctx context.Context) {
|
||||
le.metrics.leaderOff(le.config.Name)
|
||||
logger.Info("Failed to renew lease", "lock", desc, "err", err)
|
||||
cancel()
|
||||
}, le.config.RetryPeriod, ctx.Done())
|
||||
}, le.config.RetryPeriod)
|
||||
|
||||
// if we hold the lease, give it up
|
||||
if le.config.ReleaseOnCancel {
|
||||
|
||||
Reference in New Issue
Block a user