Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "OCPBUGS-30169: add timeout to etcd client.New config" #1222

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 13 additions & 17 deletions pkg/etcdcli/etcdcli.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,10 @@ import (
)

const (
BootstrapIPAnnotationKey = "alpha.installer.openshift.io/etcd-bootstrap"
DefaultDialTimeout = 15 * time.Second
DefaultDialKeepAliveTimeout = 60 * time.Second
DefragDialTimeout = 60 * time.Second
DefaultClientTimeout = 30 * time.Second
BootstrapIPAnnotationKey = "alpha.installer.openshift.io/etcd-bootstrap"
DefaultDialTimeout = 15 * time.Second
DefragDialTimeout = 60 * time.Second
DefaultClientTimeout = 30 * time.Second
)

type etcdClientGetter struct {
Expand Down Expand Up @@ -117,21 +116,14 @@ func newEtcdClientWithClientOpts(endpoints []string, skipConnectionTest bool, op
return nil, fmt.Errorf("failed building client logger: %w", err)
}

ctx, cancel := context.WithTimeout(context.Background(), DefaultClientTimeout)
defer cancel()

cfg := &clientv3.Config{
Context: ctx,
DialOptions: dialOptions,
Endpoints: endpoints,
DialTimeout: clientOpts.dialTimeout,
DialKeepAliveTimeout: clientOpts.dialKeepAliveTimeout,
TLS: tlsConfig,
Logger: l,
DialOptions: dialOptions,
Endpoints: endpoints,
DialTimeout: clientOpts.dialTimeout,
TLS: tlsConfig,
Logger: l,
}

// Note that this already establishes a connection that can fail, whereas skipConnectionTest only applies to the member listing,
// which will fail when the member would be a learner
cli, err := clientv3.New(*cfg)
if err != nil {
return nil, fmt.Errorf("failed to make etcd client for endpoints %v: %w", endpoints, err)
Expand All @@ -142,6 +134,10 @@ func newEtcdClientWithClientOpts(endpoints []string, skipConnectionTest bool, op
if skipConnectionTest {
return cli, err
}

// Test client connection.
ctx, cancel := context.WithTimeout(context.Background(), DefaultClientTimeout)
defer cancel()
_, err = cli.MemberList(ctx)
if err != nil {
if clientv3.IsConnCanceled(err) {
Expand Down
6 changes: 2 additions & 4 deletions pkg/etcdcli/etcdcli_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ import (
)

type ClientOptions struct {
dialTimeout time.Duration
dialKeepAliveTimeout time.Duration
dialTimeout time.Duration
}

func newClientOpts(opts ...ClientOption) (*ClientOptions, error) {
clientOpts := &ClientOptions{
dialTimeout: DefaultDialTimeout,
dialKeepAliveTimeout: DefaultDialKeepAliveTimeout,
dialTimeout: DefaultDialTimeout,
}
clientOpts.applyOpts(opts)
return clientOpts, nil
Expand Down