Skip to content
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

Recover cluster after multiple pod failures #366

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Review changes
Signed-off-by: Sebastian Woehrl <[email protected]>
swoehrl-mw committed Feb 3, 2023
commit f851a707d6f3e2354d1b362b16d89f35db2fbd6f
2 changes: 1 addition & 1 deletion docs/userguide/main.md
Original file line number Diff line number Diff line change
@@ -685,7 +685,7 @@ The operator contains several features that automate management tasks that might
### Cluster recovery

This operator automatically handles common failure scenarios and restarts crashed pods, normally this is done in a one-by-one fashion to maintain quorum and cluster stability.
In case the operator detects several crashed or missing pods (for a nodepool) at the same time it will switch into a special recovery mode and start all pods at once and allow the cluster to form a new quorum. This parallel recovery mode is currently experimental and only works with PVC-backed storage. If you encounter problems with it, you can disable it by redeploying the operator and adding `manager.parallelRecoveryEnabled: false` to your `values.yaml`. Please also report any problems by opening an issue in the operator github project.
In case the operator detects several crashed or missing pods (for a nodepool) at the same time it will switch into a special recovery mode and start all pods at once and allow the cluster to form a new quorum. This parallel recovery mode is currently experimental and only works with PVC-backed storage as it uses the number of existing PVCs to determine the number of missing pods. The recovery is done by temporarily changing the statefulset underlying each nodepool and setting the `podManagementPolicy` to `Parallel`. If you encounter problems with it, you can disable it by redeploying the operator and adding `manager.parallelRecoveryEnabled: false` to your `values.yaml`. Please also report any problems by opening an issue in the operator github project.

The recovery mode also kicks in if you deleted your cluster but kept the PVCs around and are then reinstalling the cluster.

17 changes: 11 additions & 6 deletions opensearch-operator/pkg/helpers/helpers.go
Original file line number Diff line number Diff line change
@@ -17,6 +17,11 @@ import (
"sigs.k8s.io/controller-runtime/pkg/client"
)

const (
stsUpdateWaitTime = 30
updateStepTime = 3
)

func ContainsString(slice []string, s string) bool {
for _, item := range slice {
if item == s {
@@ -191,43 +196,43 @@ func WaitForSTSDelete(ctx context.Context, k8sClient client.Client, obj *appsv1.
if err := k8sClient.Delete(ctx, obj, &opts); err != nil {
return err
}
for i := 1; i <= 10; i++ {
for i := 1; i <= stsUpdateWaitTime/updateStepTime; i++ {
existing := appsv1.StatefulSet{}
err := k8sClient.Get(ctx, client.ObjectKeyFromObject(obj), &existing)
if err != nil {
return nil
}
time.Sleep(time.Second * 2)
time.Sleep(time.Second * updateStepTime)
}
return fmt.Errorf("failed to delete STS")
}

// Wait for max 30s until a STS has at least the given number of replicas
func WaitForSTSReplicas(ctx context.Context, k8sClient client.Client, obj *appsv1.StatefulSet, replicas int32) error {
for i := 1; i <= 10; i++ {
for i := 1; i <= stsUpdateWaitTime/updateStepTime; i++ {
existing := appsv1.StatefulSet{}
err := k8sClient.Get(ctx, client.ObjectKeyFromObject(obj), &existing)
if err == nil {
if existing.Status.Replicas >= replicas {
return nil
}
}
time.Sleep(time.Second * 3)
time.Sleep(time.Second * updateStepTime)
}
return fmt.Errorf("failed to wait for replicas")
}

// Wait for max 30s until a STS has a normal status (CurrentRevision != "")
func WaitForSTSStatus(ctx context.Context, k8sClient client.Client, obj *appsv1.StatefulSet) (*appsv1.StatefulSet, error) {
for i := 1; i <= 10; i++ {
for i := 1; i <= stsUpdateWaitTime/updateStepTime; i++ {
existing := appsv1.StatefulSet{}
err := k8sClient.Get(ctx, client.ObjectKeyFromObject(obj), &existing)
if err == nil {
if existing.Status.CurrentRevision != "" {
return &existing, nil
}
}
time.Sleep(time.Second * 3)
time.Sleep(time.Second * updateStepTime)
}
return nil, fmt.Errorf("failed to wait for STS")
}