From 2e430ba622817b534642fd93098f87ea7f983aee Mon Sep 17 00:00:00 2001 From: Patrik Cyvoct Date: Mon, 20 Jul 2020 09:22:13 +0200 Subject: [PATCH] Allow configuration of etcd healthcheck timeout Signed-off-by: Patrik Cyvoct --- cmd/kube-apiserver/app/options/options_test.go | 1 + staging/src/k8s.io/apiserver/pkg/server/options/etcd.go | 3 +++ .../src/k8s.io/apiserver/pkg/storage/storagebackend/config.go | 4 ++++ .../apiserver/pkg/storage/storagebackend/factory/etcd3.go | 2 +- 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/cmd/kube-apiserver/app/options/options_test.go b/cmd/kube-apiserver/app/options/options_test.go index 29e40727a4d..f6dc3daee83 100644 --- a/cmd/kube-apiserver/app/options/options_test.go +++ b/cmd/kube-apiserver/app/options/options_test.go @@ -160,6 +160,7 @@ func TestAddFlags(t *testing.T) { CompactionInterval: storagebackend.DefaultCompactInterval, CountMetricPollPeriod: time.Minute, DBMetricPollInterval: storagebackend.DefaultDBMetricPollInterval, + HealthcheckTimeout: storagebackend.DefaultHealthcheckTimeout, }, DefaultStorageMediaType: "application/vnd.kubernetes.protobuf", DeleteCollectionWorkers: 1, diff --git a/staging/src/k8s.io/apiserver/pkg/server/options/etcd.go b/staging/src/k8s.io/apiserver/pkg/server/options/etcd.go index 192edeb6b21..d9c6f9e54bb 100644 --- a/staging/src/k8s.io/apiserver/pkg/server/options/etcd.go +++ b/staging/src/k8s.io/apiserver/pkg/server/options/etcd.go @@ -180,6 +180,9 @@ func (s *EtcdOptions) AddFlags(fs *pflag.FlagSet) { fs.DurationVar(&s.StorageConfig.DBMetricPollInterval, "etcd-db-metric-poll-interval", s.StorageConfig.DBMetricPollInterval, "The interval of requests to poll etcd and update metric. 0 disables the metric collection") + + fs.DurationVar(&s.StorageConfig.HealthcheckTimeout, "etcd-healthcheck-timeout", s.StorageConfig.HealthcheckTimeout, + "The timeout to use when checking etcd health.") } func (s *EtcdOptions) ApplyTo(c *server.Config) error { diff --git a/staging/src/k8s.io/apiserver/pkg/storage/storagebackend/config.go b/staging/src/k8s.io/apiserver/pkg/storage/storagebackend/config.go index 5dc0bbfb349..af94efcea88 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/storagebackend/config.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/storagebackend/config.go @@ -30,6 +30,7 @@ const ( DefaultCompactInterval = 5 * time.Minute DefaultDBMetricPollInterval = 30 * time.Second + DefaultHealthcheckTimeout = 2 * time.Second ) // TransportConfig holds all connection related info, i.e. equal TransportConfig means equal servers we talk to. @@ -74,6 +75,8 @@ type Config struct { CountMetricPollPeriod time.Duration // DBMetricPollInterval specifies how often should storage backend metric be updated. DBMetricPollInterval time.Duration + // HealthcheckTimeout specifies the timeout used when checking health + HealthcheckTimeout time.Duration } func NewDefaultConfig(prefix string, codec runtime.Codec) *Config { @@ -83,5 +86,6 @@ func NewDefaultConfig(prefix string, codec runtime.Codec) *Config { Codec: codec, CompactionInterval: DefaultCompactInterval, DBMetricPollInterval: DefaultDBMetricPollInterval, + HealthcheckTimeout: DefaultHealthcheckTimeout, } } diff --git a/staging/src/k8s.io/apiserver/pkg/storage/storagebackend/factory/etcd3.go b/staging/src/k8s.io/apiserver/pkg/storage/storagebackend/factory/etcd3.go index 3d1f2f150fa..cb32bfc9ed0 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/storagebackend/factory/etcd3.go +++ b/staging/src/k8s.io/apiserver/pkg/storage/storagebackend/factory/etcd3.go @@ -92,7 +92,7 @@ func newETCD3HealthCheck(c storagebackend.Config) (func() error, error) { return fmt.Errorf(errMsg) } client := clientValue.Load().(*clientv3.Client) - ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), c.HealthcheckTimeout) defer cancel() // See https://github.com/etcd-io/etcd/blob/c57f8b3af865d1b531b979889c602ba14377420e/etcdctl/ctlv3/command/ep_command.go#L118 _, err := client.Get(ctx, path.Join("/", c.Prefix, "health"))