mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 21:47:07 +00:00
Merge pull request #72896 from lorenz/fix-apiserver-healthcheck
Fix etcd healthcheck for consensus failures
This commit is contained in:
commit
b04d7ca976
@ -19,6 +19,7 @@ package factory
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
@ -72,10 +73,12 @@ func newETCD3HealthCheck(c storagebackend.Config) (func() error, error) {
|
|||||||
client := clientValue.Load().(*clientv3.Client)
|
client := clientValue.Load().(*clientv3.Client)
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
if _, err := client.Cluster.MemberList(ctx); err != nil {
|
// See https://github.com/etcd-io/etcd/blob/master/etcdctl/ctlv3/command/ep_command.go#L118
|
||||||
return fmt.Errorf("error listing etcd members: %v", err)
|
_, err := client.Get(ctx, path.Join(c.Prefix, "health"))
|
||||||
|
if err == nil {
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
return nil
|
return fmt.Errorf("error getting data from etcd: %v", err)
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user