-
Notifications
You must be signed in to change notification settings - Fork 176
K8SPSMDB-1451: Wait until primary elected after rs initialization #2149
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
Changes from 6 commits
1bf9e34
c684204
15f463a
8b57e54
65db8e0
6234b53
1bb3527
9e380b0
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 | ||||
|---|---|---|---|---|---|---|
|
|
@@ -17,6 +17,8 @@ import ( | |||||
| corev1 "k8s.io/api/core/v1" | ||||||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||||||
| "k8s.io/apimachinery/pkg/types" | ||||||
| "k8s.io/apimachinery/pkg/util/wait" | ||||||
| "k8s.io/client-go/util/retry" | ||||||
| "k8s.io/utils/ptr" | ||||||
| logf "sigs.k8s.io/controller-runtime/pkg/log" | ||||||
|
|
||||||
|
|
@@ -724,8 +726,35 @@ func (r *ReconcilePerconaServerMongoDB) handleReplsetInit(ctx context.Context, c | |||||
| return nil, nil, fmt.Errorf("exec rs.initiate: %v / %s / %s", err, outb.String(), errb.String()) | ||||||
| } | ||||||
|
|
||||||
| backoff := wait.Backoff{ | ||||||
| Steps: 5, | ||||||
| Duration: 50 * time.Millisecond, | ||||||
| Factor: 5.0, | ||||||
| Jitter: 0.1, | ||||||
| } | ||||||
| err = retry.OnError(backoff, func(err error) bool { return true }, func() error { | ||||||
egegunes marked this conversation as resolved.
Show resolved
Hide resolved
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. Are we going to also retry permanent errors, like auth, for example?
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. i think yes. at this point there shouldn't be any auth errors any way. and in the worst case scenario we'll retry for 6 seconds. |
||||||
| var stderr, stdout bytes.Buffer | ||||||
|
|
||||||
| hello := []string{"sh", "-c", | ||||||
| mongoCmd + " --quiet --eval 'db.hello().isWritablePrimary'"} | ||||||
| err := r.clientcmd.Exec(ctx, &pod, "mongod", hello, nil, &stdout, &stderr, false) | ||||||
|
||||||
| err := r.clientcmd.Exec(ctx, &pod, "mongod", hello, nil, &stdout, &stderr, false) | |
| err = r.clientcmd.Exec(ctx, &pod, "mongod", hello, nil, &stdout, &stderr, false) |
egegunes marked this conversation as resolved.
Show resolved
Hide resolved
Copilot
AI
Jan 5, 2026
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.
The new backoff retry logic for waiting until a primary is elected lacks test coverage. Consider adding unit tests to verify the retry behavior, including successful primary election, timeout scenarios, and error handling. Other functions in mgo_test.go demonstrate the testing pattern used in this package.
Uh oh!
There was an error while loading. Please reload this page.