-
Notifications
You must be signed in to change notification settings - Fork 156
K8SPSMDB-1296: improve readiness probe #1917
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
base: main
Are you sure you want to change the base?
Changes from 10 commits
d6e9d6b
09a63a1
40b7674
07f1be6
d75cca1
6f268bf
52df399
5d322e3
363fc77
ce419af
1c3c592
fb8a8ef
e5ae37d
c896cbe
ae932d3
01dedaa
d541d8e
ad260bb
62650d9
160e3ea
5116da4
8fc44b8
5c63a72
0520bbd
5059ea5
6fa92a8
1141926
c0b21b5
cd834df
49886fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package healthcheck | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
|
||
v "github.com/hashicorp/go-version" | ||
"github.com/pkg/errors" | ||
"go.mongodb.org/mongo-driver/bson" | ||
"go.mongodb.org/mongo-driver/bson/primitive" | ||
|
||
"github.com/percona/percona-server-mongodb-operator/pkg/psmdb/mongo" | ||
) | ||
|
||
func getStatus(ctx context.Context, client mongo.Client) (ReplSetStatus, error) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why don't we have all the mongo client-related functions together as part of the Also the response type seems related to the generic mongo model and maybe can be moved to the mongo model file.
This removes the need to have a utils file completely. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
buildInfo, err := client.RSBuildInfo(ctx) | ||
if err != nil { | ||
return ReplSetStatus{}, errors.Wrap(err, "get buildInfo response") | ||
} | ||
|
||
replSetStatusCommand := bson.D{{Key: "replSetGetStatus", Value: 1}} | ||
mongoVersion := v.Must(v.NewVersion(buildInfo.Version)) | ||
if mongoVersion.Compare(v.Must(v.NewVersion("4.2.1"))) < 0 { | ||
// https://docs.mongodb.com/manual/reference/command/replSetGetStatus/#syntax | ||
replSetStatusCommand = append(replSetStatusCommand, primitive.E{Key: "initialSync", Value: 1}) | ||
} | ||
|
||
res := client.Database("admin").RunCommand(ctx, replSetStatusCommand) | ||
if res.Err() != nil { | ||
if res.Err().Error() == ErrNoReplsetConfigStr { | ||
return ReplSetStatus{}, errors.New(ErrNoReplsetConfigStr) | ||
} | ||
return ReplSetStatus{}, errors.Wrap(res.Err(), "get replsetGetStatus response") | ||
} | ||
|
||
// this is a workaround to fix decoding of empty interfaces | ||
// https://jira.mongodb.org/browse/GODRIVER-988 | ||
rsStatus := ReplSetStatus{} | ||
tempResult := bson.M{} | ||
if err := res.Decode(&tempResult); err != nil { | ||
return ReplSetStatus{}, errors.Wrap(err, "decode replsetGetStatus response") | ||
} | ||
result, err := json.Marshal(tempResult) | ||
if err != nil { | ||
return ReplSetStatus{}, errors.Wrap(err, "marshal temp result") | ||
} | ||
if err = json.Unmarshal(result, &rsStatus); err != nil { | ||
return ReplSetStatus{}, errors.Wrap(err, "unmarshal temp result") | ||
} | ||
return rsStatus, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i wonder if we should ignore all errors or only
this node is not a member of replset
?