-
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 4 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" | ||
| logf "sigs.k8s.io/controller-runtime/pkg/log" | ||
|
|
||
| api "github.com/percona/percona-server-mongodb-operator/pkg/apis/psmdb/v1" | ||
|
|
@@ -719,8 +721,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.runCommand({ hello: 1 }).isWritablePrimary'"} | ||
egegunes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| err = r.clientcmd.Exec(ctx, &pod, "mongod", hello, nil, &stdout, &stderr, false) | ||
egegunes marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if err != nil { | ||
| return errors.Wrapf(err, "run hello stdout: %s, stderr: %s", stdout.String(), stderr.String()) | ||
| } | ||
|
|
||
| out := strings.TrimSpace(stdout.String()) | ||
| if out != "true" { | ||
| return errors.Errorf("%s is not the writable primary", pod.Name) | ||
| } | ||
|
|
||
| log.Info(pod.Name+" is the writable primary", "replset", replsetName) | ||
egegunes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return nil | ||
| }) | ||
|
Comment on lines
+716
to
+740
|
||
| if err != nil { | ||
| return nil, nil, errors.Wrap(err, "wait for replset initialization") | ||
| } | ||
egegunes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| log.Info("replset initialized", "replset", replsetName, "pod", pod.Name) | ||
| time.Sleep(time.Second * 5) | ||
|
|
||
| log.Info("creating user admin", "replset", replsetName, "pod", pod.Name, "user", api.RoleUserAdmin) | ||
| userAdmin, err := getInternalCredentials(ctx, r.client, cr, api.RoleUserAdmin) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.