mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Allow configuration of etcd healthcheck timeout
Signed-off-by: Patrik Cyvoct <patrik@ptrk.io>
This commit is contained in:
parent
2ad48d384d
commit
2e430ba622
@ -160,6 +160,7 @@ func TestAddFlags(t *testing.T) {
|
|||||||
CompactionInterval: storagebackend.DefaultCompactInterval,
|
CompactionInterval: storagebackend.DefaultCompactInterval,
|
||||||
CountMetricPollPeriod: time.Minute,
|
CountMetricPollPeriod: time.Minute,
|
||||||
DBMetricPollInterval: storagebackend.DefaultDBMetricPollInterval,
|
DBMetricPollInterval: storagebackend.DefaultDBMetricPollInterval,
|
||||||
|
HealthcheckTimeout: storagebackend.DefaultHealthcheckTimeout,
|
||||||
},
|
},
|
||||||
DefaultStorageMediaType: "application/vnd.kubernetes.protobuf",
|
DefaultStorageMediaType: "application/vnd.kubernetes.protobuf",
|
||||||
DeleteCollectionWorkers: 1,
|
DeleteCollectionWorkers: 1,
|
||||||
|
@ -180,6 +180,9 @@ func (s *EtcdOptions) AddFlags(fs *pflag.FlagSet) {
|
|||||||
|
|
||||||
fs.DurationVar(&s.StorageConfig.DBMetricPollInterval, "etcd-db-metric-poll-interval", s.StorageConfig.DBMetricPollInterval,
|
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")
|
"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 {
|
func (s *EtcdOptions) ApplyTo(c *server.Config) error {
|
||||||
|
@ -30,6 +30,7 @@ const (
|
|||||||
|
|
||||||
DefaultCompactInterval = 5 * time.Minute
|
DefaultCompactInterval = 5 * time.Minute
|
||||||
DefaultDBMetricPollInterval = 30 * time.Second
|
DefaultDBMetricPollInterval = 30 * time.Second
|
||||||
|
DefaultHealthcheckTimeout = 2 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
// TransportConfig holds all connection related info, i.e. equal TransportConfig means equal servers we talk to.
|
// 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
|
CountMetricPollPeriod time.Duration
|
||||||
// DBMetricPollInterval specifies how often should storage backend metric be updated.
|
// DBMetricPollInterval specifies how often should storage backend metric be updated.
|
||||||
DBMetricPollInterval time.Duration
|
DBMetricPollInterval time.Duration
|
||||||
|
// HealthcheckTimeout specifies the timeout used when checking health
|
||||||
|
HealthcheckTimeout time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDefaultConfig(prefix string, codec runtime.Codec) *Config {
|
func NewDefaultConfig(prefix string, codec runtime.Codec) *Config {
|
||||||
@ -83,5 +86,6 @@ func NewDefaultConfig(prefix string, codec runtime.Codec) *Config {
|
|||||||
Codec: codec,
|
Codec: codec,
|
||||||
CompactionInterval: DefaultCompactInterval,
|
CompactionInterval: DefaultCompactInterval,
|
||||||
DBMetricPollInterval: DefaultDBMetricPollInterval,
|
DBMetricPollInterval: DefaultDBMetricPollInterval,
|
||||||
|
HealthcheckTimeout: DefaultHealthcheckTimeout,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ func newETCD3HealthCheck(c storagebackend.Config) (func() error, error) {
|
|||||||
return fmt.Errorf(errMsg)
|
return fmt.Errorf(errMsg)
|
||||||
}
|
}
|
||||||
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(), c.HealthcheckTimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
// See https://github.com/etcd-io/etcd/blob/c57f8b3af865d1b531b979889c602ba14377420e/etcdctl/ctlv3/command/ep_command.go#L118
|
// 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"))
|
_, err := client.Get(ctx, path.Join("/", c.Prefix, "health"))
|
||||||
|
Loading…
Reference in New Issue
Block a user