-
Notifications
You must be signed in to change notification settings - Fork 161
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
Open
pooknull
wants to merge
39
commits into
main
Choose a base branch
from
K8SPSMDB-1296
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
d6e9d6b
K8SPSMDB-1296: improve readiness probe
pooknull 09a63a1
Merge branch 'main' into K8SPSMDB-1296
pooknull 40b7674
Merge branch 'main' into K8SPSMDB-1296
pooknull 07f1be6
Merge branch 'main' into K8SPSMDB-1296
pooknull d75cca1
fix tests
pooknull 6f268bf
Merge branch 'main' into K8SPSMDB-1296
pooknull 52df399
fix unit-test
pooknull 5d322e3
fix tests
pooknull 363fc77
Merge branch 'main' into K8SPSMDB-1296
pooknull ce419af
Merge remote-tracking branch 'origin/main' into K8SPSMDB-1296
pooknull 1c3c592
Merge branch 'main' into K8SPSMDB-1296
pooknull fb8a8ef
fix unit-test
pooknull e5ae37d
Merge remote-tracking branch 'origin/main' into K8SPSMDB-1296
pooknull c896cbe
ignore connection error in readiness probe
pooknull ae932d3
delete util.go
pooknull 01dedaa
fix manifests
pooknull d541d8e
Merge remote-tracking branch 'origin/main' into K8SPSMDB-1296
pooknull ad260bb
Merge branch 'main' into K8SPSMDB-1296
hors 62650d9
fix compare files
pooknull 160e3ea
Merge branch 'main' into K8SPSMDB-1296
pooknull 5116da4
fix tests
pooknull 8fc44b8
add readiness probe to hidden replsets
pooknull 5c63a72
Merge branch 'main' into K8SPSMDB-1296
pooknull 0520bbd
Merge branch 'main' into K8SPSMDB-1296
hors 5059ea5
ignore invalid replset
pooknull 6fa92a8
Merge branch 'main' into K8SPSMDB-1296
hors 1141926
Merge branch 'main' into K8SPSMDB-1296
hors c0b21b5
Merge branch 'main' into K8SPSMDB-1296
hors cd834df
fix upgrade-consistency test
pooknull 49886fe
Merge branch 'main' into K8SPSMDB-1296
hors 64dfbf7
Merge remote-tracking branch 'origin/main' into K8SPSMDB-1296
pooknull b0bedb6
fix tests
pooknull c66e663
Merge remote-tracking branch 'origin/main' into K8SPSMDB-1296
pooknull b9f688b
add check
pooknull aa34abc
small improvement
pooknull 335aef1
fix tests
pooknull 704adc3
small improvements
pooknull 854d35b
add comment
pooknull 02b4bc7
Merge branch 'main' into K8SPSMDB-1296
pooknull File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ package healthcheck | |
| import ( | ||
| "context" | ||
| "net" | ||
| "time" | ||
|
|
||
| "github.com/pkg/errors" | ||
| "go.mongodb.org/mongo-driver/bson" | ||
|
|
@@ -27,21 +28,64 @@ import ( | |
| ) | ||
|
|
||
| // MongodReadinessCheck runs a ping on a pmgo.SessionManager to check server readiness | ||
| func MongodReadinessCheck(ctx context.Context, addr string) error { | ||
| func MongodReadinessCheck(ctx context.Context, cnf *db.Config) error { | ||
| log := logf.FromContext(ctx).WithName("MongodReadinessCheck") | ||
| ctx = logf.IntoContext(ctx, log) | ||
|
|
||
| var d net.Dialer | ||
|
|
||
| if len(cnf.Hosts) == 0 { | ||
| return errors.New("no hosts found") | ||
| } | ||
| addr := cnf.Hosts[0] | ||
| log.V(1).Info("Connecting to " + addr) | ||
| conn, err := d.DialContext(ctx, "tcp", addr) | ||
| if err != nil { | ||
| return errors.Wrap(err, "dial") | ||
| } | ||
| return conn.Close() | ||
| if err := conn.Close(); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| s, err := func() (status *mongo.Status, err error) { | ||
| cnf.Timeout = time.Second | ||
| client, err := db.Dial(ctx, cnf) | ||
pooknull marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if err != nil { | ||
| // The operator waits for the StatefulSet to be ready before initializing the database. | ||
| // Until then, it is not possible to connect to it. | ||
| // We should ignore any errors from Dial to allow the cluster to be deployed. | ||
| return nil, nil | ||
|
Contributor
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 are we swallowing this error?
Contributor
Author
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. |
||
| } | ||
| defer func() { | ||
| if derr := client.Disconnect(ctx); derr != nil && err == nil { | ||
| err = errors.Wrap(derr, "failed to disconnect") | ||
| } | ||
pooknull marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }() | ||
| var rs mongo.Status | ||
| rs, err = client.RSStatus(ctx) | ||
| if err != nil { | ||
| if errors.Is(err, mongo.ErrInvalidReplsetConfig) { | ||
| log.Info("Couldn't connect to mongo due to invalid replset config. Ignoring", "error", err) | ||
| return nil, nil | ||
| } | ||
| return nil, err | ||
| } | ||
| return &rs, nil | ||
| }() | ||
| if err != nil || s == nil { | ||
| return errors.Wrap(err, "failed to get rs status") | ||
| } | ||
pooknull marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if err := CheckState(*s, 0, 0); err != nil { | ||
| return errors.Wrap(err, "check state") | ||
| } | ||
pooknull marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func MongosReadinessCheck(ctx context.Context, cnf *db.Config) (err error) { | ||
| log := logf.FromContext(ctx).WithName("MongosReadinessCheck") | ||
| ctx = logf.IntoContext(ctx, log) | ||
|
|
||
| client, err := db.Dial(ctx, cnf) | ||
| if err != nil { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should we ensure that hosts are not empty/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.
704adc3