Skip to content

Commit 5059ea5

Browse files
committed
ignore invalid replset
1 parent 0520bbd commit 5059ea5

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

cmd/mongodb-healthcheck/healthcheck/readiness.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ func MongodReadinessCheck(ctx context.Context, cnf *db.Config) error {
5757
}()
5858
rs, err := client.RSStatus(ctx)
5959
if err != nil {
60+
if errors.Is(err, mongo.ErrInvalidReplsetConfig) {
61+
return nil, nil
62+
}
6063
return nil, err
6164
}
6265
return &rs, nil

pkg/psmdb/mongo/mongo.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,11 +375,18 @@ func (client *mongoClient) WriteConfig(ctx context.Context, cfg RSConfig, force
375375
return nil
376376
}
377377

378+
var ErrInvalidReplsetConfig = errors.New("invalid replicaset config")
379+
378380
func (client *mongoClient) RSStatus(ctx context.Context) (Status, error) {
379381
status := Status{}
380382

381383
resp := client.Database("admin").RunCommand(ctx, bson.D{{Key: "replSetGetStatus", Value: 1}})
382384
if resp.Err() != nil {
385+
if cmdErr, ok := resp.Err().(mongo.CommandError); ok {
386+
if cmdErr.Code == 93 {
387+
return status, ErrInvalidReplsetConfig
388+
}
389+
}
383390
return status, errors.Wrap(resp.Err(), "replSetGetStatus")
384391
}
385392

0 commit comments

Comments
 (0)