Skip to content

Commit

Permalink
The init command does not return SSL errors (#4479)
Browse files Browse the repository at this point in the history
  • Loading branch information
fguimond authored Nov 4, 2021
1 parent ce60c5b commit 7902137
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased

### Fixed
- In addition to the context error print the connection error when sensu-go can't connect to etcd.
### Changed

- Empty and zero value configuration parameters for `etcd` do not overwrite
Expand Down
10 changes: 6 additions & 4 deletions backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ func newClient(ctx context.Context, config *Config, backend *Backend) (*clientv3
Password: config.EtcdClientPassword,
TLS: tlsConfig,
DialOptions: []grpc.DialOption{
grpc.WithReturnConnectionError(),
grpc.WithBlock(),
},
}
Expand All @@ -208,6 +209,7 @@ func newClient(ctx context.Context, config *Config, backend *Backend) (*clientv3
DialTimeout: 5 * time.Second,
TLS: tlsConfig,
DialOptions: []grpc.DialOption{
grpc.WithReturnConnectionError(),
grpc.WithBlock(),
},
}
Expand Down Expand Up @@ -538,11 +540,11 @@ func Initialize(ctx context.Context, config *Config) (*Backend, error) {

// Prepare the authentication providers
authenticator := &authentication.Authenticator{}
basic := &basic.Provider{
provider := &basic.Provider{
ObjectMeta: corev2.ObjectMeta{Name: basic.Type},
Store: b.Store,
}
authenticator.AddProvider(basic)
authenticator.AddProvider(provider)

var clusterVersion string
// only retrieve the cluster version if etcd is embedded
Expand Down Expand Up @@ -625,7 +627,7 @@ func Initialize(ctx context.Context, config *Config) (*Backend, error) {

func (b *Backend) runOnce() error {
eCloser := b.StoreUpdater.(closer)
defer eCloser.Close()
defer func() { _ = eCloser.Close() }()

var derr error

Expand Down Expand Up @@ -682,7 +684,7 @@ func (b *Backend) runOnce() error {
if err != nil {
logger.WithError(err).Error("unable to open platform metrics log file")
} else {
defer metricsLogWriter.Close()
defer func() { _ = metricsLogWriter.Close() }()
metricsBridge, err := metrics.NewInfluxBridge(&metrics.InfluxBridgeConfig{
Writer: metricsLogWriter,
Interval: b.Cfg.PlatformMetricsLoggingInterval,
Expand Down
24 changes: 15 additions & 9 deletions backend/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,17 +197,23 @@ func InitCommand() *cobra.Command {

if etcdClientUsername != "" && etcdClientPassword != "" {
clientConfig = clientv3.Config{
Endpoints: []string{url},
Username: etcdClientUsername,
Password: etcdClientPassword,
TLS: tlsConfig,
DialOptions: []grpc.DialOption{grpc.WithBlock()},
Endpoints: []string{url},
Username: etcdClientUsername,
Password: etcdClientPassword,
TLS: tlsConfig,
DialOptions: []grpc.DialOption{
grpc.WithReturnConnectionError(),
grpc.WithBlock(),
},
}
} else {
clientConfig = clientv3.Config{
Endpoints: []string{url},
TLS: tlsConfig,
DialOptions: []grpc.DialOption{grpc.WithBlock()},
Endpoints: []string{url},
TLS: tlsConfig,
DialOptions: []grpc.DialOption{
grpc.WithReturnConnectionError(),
grpc.WithBlock(),
},
}
}
err := initializeStore(clientConfig, initConfig, url)
Expand Down Expand Up @@ -254,7 +260,7 @@ func initializeStore(clientConfig clientv3.Config, initConfig initConfig, endpoi
if err != nil {
return fmt.Errorf("error connecting to etcd endpoint: %w", err)
}
defer client.Close()
defer func() { _ = client.Close() }()

// Check if etcd endpoint is reachable
if _, err := client.Status(ctx, endpoint); err != nil {
Expand Down
1 change: 1 addition & 0 deletions backend/etcd/etcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ func (e *Etcd) NewClientContext(ctx context.Context) (*clientv3.Client, error) {
DialTimeout: 60 * time.Second,
TLS: tlsConfig,
DialOptions: []grpc.DialOption{
grpc.WithReturnConnectionError(),
grpc.WithBlock(),
},
Context: ctx,
Expand Down

0 comments on commit 7902137

Please sign in to comment.