Repository navigation
core HA | set PodManagementPolicy to Parallel #2103
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: master
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| package system | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
| "maps" | ||
|
|
@@ -34,6 +35,7 @@ import ( | |
| "k8s.io/apimachinery/pkg/labels" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
| "k8s.io/apimachinery/pkg/util/intstr" | ||
| "k8s.io/apimachinery/pkg/util/wait" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
| ) | ||
|
|
||
|
|
@@ -241,6 +243,10 @@ func (r *Reconciler) ReconcilePhaseCreatingForMainClusters() error { | |
| } | ||
| } | ||
|
|
||
| if err := r.ensureParallelCoreStatefulSet(); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| if err := r.ReconcileObject(r.CoreApp, r.SetDesiredCoreApp); err != nil { | ||
| return err | ||
| } | ||
|
|
@@ -810,6 +816,92 @@ func (r *Reconciler) setDesiredCoreEnv(c *corev1.Container) { | |
| r.setDesiredS3TablesEnv(c) | ||
| } | ||
|
|
||
| // checks if the statefulset has parallel pod management policy | ||
| func hasParallelPodManagement(sts *appsv1.StatefulSet) bool { | ||
| if sts.UID == "" { | ||
| return false | ||
| } | ||
| return sts.Spec.PodManagementPolicy == appsv1.ParallelPodManagement | ||
| } | ||
|
|
||
| // How long to wait for the core StatefulSet to disappear after an orphan-propagation | ||
| // delete before returning a retryable reconcile error. Avoids util.KubeDelete's | ||
| // unbounded poll (and Panic) when finalizers leave the object terminating. | ||
| const coreStatefulSetDeleteWaitTimeout = 30 * time.Second | ||
|
|
||
| // ensures that the statefulset has parallel pod management policy | ||
| // PodManagementPolicy is immutable, so we need to delete the statefulset and create a new one | ||
| // can happen when upgrading from older operator versions | ||
| func (r *Reconciler) ensureParallelCoreStatefulSet() error { | ||
| if !util.KubeCheckQuiet(r.CoreApp) { | ||
| return nil | ||
| } | ||
| if hasParallelPodManagement(r.CoreApp) { | ||
| return nil | ||
| } | ||
|
|
||
| if owner := metav1.GetControllerOf(r.CoreApp); owner != nil && owner.UID != r.NooBaa.UID { | ||
| return fmt.Errorf( | ||
| "%s StatefulSet is controlled by %s %s, not deleting it", | ||
| r.CoreApp.Name, owner.Kind, owner.Name, | ||
| ) | ||
| } | ||
|
|
||
| current := r.CoreApp.Spec.PodManagementPolicy | ||
| if current == "" { | ||
| current = appsv1.OrderedReadyPodManagement | ||
| } | ||
| r.Logger.Infof( | ||
| "upgrading %s StatefulSet to parallel pod startup (delete STS, keep pods, recreate) from %q", | ||
| r.CoreApp.Name, current, | ||
| ) | ||
|
|
||
| // Delete the StatefulSet and keep the pods. Use the reconcile context (bounded | ||
| // wait below) instead of util.KubeDelete, which polls forever and can Panic. | ||
| orphan := metav1.DeletePropagationOrphan | ||
|
nadavMiz marked this conversation as resolved.
Resolved
|
||
| if err := r.Client.Delete(r.Ctx, r.CoreApp, &client.DeleteOptions{PropagationPolicy: &orphan}); err != nil && !errors.IsNotFound(err) { | ||
| return fmt.Errorf( | ||
| "failed to delete %s StatefulSet for parallel pod startup upgrade (pods preserved): %w", | ||
| r.CoreApp.Name, err, | ||
| ) | ||
| } | ||
|
|
||
| delCtx, cancel := context.WithTimeout(r.Ctx, coreStatefulSetDeleteWaitTimeout) | ||
| defer cancel() | ||
| err := wait.PollUntilContextCancel(delCtx, time.Second, true, func(ctx context.Context) (bool, error) { | ||
| getErr := r.Client.Get(ctx, util.ObjectKey(r.CoreApp), r.CoreApp) | ||
| if errors.IsNotFound(getErr) { | ||
| return true, nil | ||
| } | ||
| if getErr != nil { | ||
| return false, getErr | ||
| } | ||
| return false, nil | ||
| }) | ||
| if err != nil { | ||
| return fmt.Errorf( | ||
| "waiting for %s StatefulSet deletion for parallel pod startup upgrade (will retry): %w", | ||
| r.CoreApp.Name, err, | ||
| ) | ||
| } | ||
|
|
||
| clearStatefulSetServerFieldsForRecreate(r.CoreApp) | ||
| return nil | ||
| } | ||
|
|
||
| // clearStatefulSetServerFieldsForRecreate removes server-owned metadata after the | ||
| // StatefulSet object was deleted. Without this, the next Create would reuse stale | ||
| // uid/resourceVersion from the deleted object. | ||
| func clearStatefulSetServerFieldsForRecreate(obj metav1.Object) { | ||
| obj.SetResourceVersion("") | ||
| obj.SetUID("") | ||
| obj.SetGeneration(0) | ||
| obj.SetCreationTimestamp(metav1.Time{}) | ||
| obj.SetDeletionTimestamp(nil) | ||
| obj.SetDeletionGracePeriodSeconds(nil) | ||
| obj.SetManagedFields(nil) | ||
|
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. Remove the orphan finalizer before recreating the StatefulSet. The deletion wait reads into Clear the orphan finalizer in the recreate helper and keep the other finalizers: Suggested fix
Add a test case that starts with the orphan finalizer and checks that the recreated object does not keep it.
|
||
| } | ||
|
|
||
| // SetDesiredCoreApp updates the CoreApp as desired for reconciling | ||
| func (r *Reconciler) SetDesiredCoreApp() error { | ||
| if coreLabels, ok := r.NooBaa.Spec.Labels["core"]; ok { | ||
|
|
@@ -822,6 +914,8 @@ func (r *Reconciler) SetDesiredCoreApp() error { | |
| r.CoreApp.Spec.Template.Labels["noobaa-mgmt"] = r.Request.Name | ||
| r.CoreApp.Spec.Selector.MatchLabels["noobaa-core"] = r.Request.Name | ||
| r.CoreApp.Spec.ServiceName = r.ServiceMgmt.Name | ||
| // Parallel startup so HA scale-down/recreate does not wait on NotReady standbys. | ||
| r.CoreApp.Spec.PodManagementPolicy = appsv1.ParallelPodManagement | ||
| // OnDelete avoids RollingUpdate stall on never-Ready HA standbys; see restartStaleCorePods. | ||
| r.CoreApp.Spec.UpdateStrategy = appsv1.StatefulSetUpdateStrategy{ | ||
| Type: appsv1.OnDeleteStatefulSetStrategyType, | ||
|
|
||
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.
Why is this needed?
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.
its not strictly needed. its just so we don't delete existing pods when deleting the sts. since we only need to change the sts itself. the pods will remain if available