janhoy commented on code in PR #931:
URL: https://github.com/apache/solr-operator/pull/931#discussion_r4797156949
##########
controllers/solrcloud_controller.go:
##########
@@ -1234,6 +1250,80 @@ func (r *SolrCloudReconciler)
storageClassAllowsExpansion(ctx context.Context, c
return allowed, className, nil
}
+// reconcileStatefulSetRecreation replaces the StatefulSet, keeping its pods,
once the data PVCs have been expanded
+// beyond the size in its volumeClaimTemplates, which Kubernetes does not
allow to be updated.
+// Otherwise pods added by a later scale-up would get PVCs of the original
size.
+//
+// The StatefulSet is deleted with its dependents orphaned. A finalizer keeps
it around until it is replaced,
+// so that nothing stored on it (e.g. the clusterOp annotations) is lost.
+func (r *SolrCloudReconciler) reconcileStatefulSetRecreation(ctx
context.Context, instance *solrv1beta1.SolrCloud, statefulSet
*appsv1.StatefulSet, logger logr.Logger) (inProgress bool, err error) {
+ if !statefulSet.DeletionTimestamp.IsZero() {
+ return true, r.finishStatefulSetRecreation(ctx, statefulSet,
logger)
+ }
+ newSize, isExpanded := util.ExpandedDataPvcSize(statefulSet)
+ if !isExpanded {
+ return false, nil
+ }
+ logger.Info("Recreating StatefulSet, keeping its pods, to use the
expanded data PVC size for new pods", "size", newSize.String())
+ if controllerutil.AddFinalizer(statefulSet,
util.SolrStatefulSetRecreateFinalizer) {
+ if err = r.Update(ctx, statefulSet); err != nil {
+ return true, err
+ }
+ }
+ r.Recorder.Eventf(instance, corev1.EventTypeNormal,
"StatefulSetRecreated",
+ "Recreating the StatefulSet, keeping its pods, so that new pods
get data PersistentVolumeClaims of the expanded size %s", newSize.String())
+ return true, r.Delete(ctx, statefulSet,
client.PropagationPolicy(metav1.DeletePropagationOrphan),
client.Preconditions{UID: &statefulSet.UID})
+}
+
+// finishStatefulSetRecreation replaces a StatefulSet that is being deleted
for a recreation,
+// once its pods have been orphaned.
+func (r *SolrCloudReconciler) finishStatefulSetRecreation(ctx context.Context,
statefulSet *appsv1.StatefulSet, logger logr.Logger) (err error) {
+ if !controllerutil.ContainsFinalizer(statefulSet,
util.SolrStatefulSetRecreateFinalizer) || len(statefulSet.Finalizers) > 1 {
+ // Either the pods are yet to be orphaned, or this deletion was
not started by the operator.
+ return nil
+ }
+ newStatefulSet := &appsv1.StatefulSet{
+ ObjectMeta: metav1.ObjectMeta{
+ Name: statefulSet.Name,
+ Namespace: statefulSet.Namespace,
+ Labels: statefulSet.Labels,
+ Annotations: statefulSet.Annotations,
+ OwnerReferences: statefulSet.OwnerReferences,
+ },
+ Spec: *statefulSet.Spec.DeepCopy(),
+ }
+ if newSize, isExpanded := util.ExpandedDataPvcSize(statefulSet);
isExpanded {
+
newStatefulSet.Spec.VolumeClaimTemplates[0].Spec.Resources.Requests =
corev1.ResourceList{corev1.ResourceStorage: newSize}
+ }
+ // Removing the last finalizer deletes the StatefulSet
+ controllerutil.RemoveFinalizer(statefulSet,
util.SolrStatefulSetRecreateFinalizer)
+ if err = r.Update(ctx, statefulSet); err != nil {
Review Comment:
🤖 Fixed in fc9dfe0. The replacement StatefulSet (replicas, annotations,
owner refs) is saved in a ConfigMap before the finalizer is removed, and
restored if the operator is interrupted.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]