Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 4 additions & 2 deletions api/v1beta1/rabbitmqcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,10 @@ type PersistentVolumeClaim struct {

// Spec defines the desired characteristics of a volume requested by a pod author.
// More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#persistentvolumeclaims
// +optional
Spec corev1.PersistentVolumeClaimSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
// When using override.statefulSet.spec.volumeClaimTemplates, you must provide the complete
// template including spec.resources.requests.storage. Overrides replace the entire template.
// +kubebuilder:validation:Required
Spec corev1.PersistentVolumeClaimSpec `json:"spec" protobuf:"bytes,2,opt,name=spec"`
}

// TLSSpec allows for the configuration of TLS certificates to be used by RabbitMQ. Also allows for non-TLS traffic to be disabled.
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/rabbitmq.com_rabbitmqclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5059,6 +5059,8 @@ spec:
volumeName:
type: string
type: object
required:
- spec
type: object
type: array
type: object
Expand Down
25 changes: 20 additions & 5 deletions controllers/reconcile_persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ import (

func (r *RabbitmqClusterReconciler) reconcilePVC(ctx context.Context, rmq *rabbitmqv1beta1.RabbitmqCluster, desiredSts *appsv1.StatefulSet) error {
logger := ctrl.LoggerFrom(ctx)
desiredCapacity := persistenceStorageCapacity(desiredSts.Spec.VolumeClaimTemplates)
err := scaling.NewPersistenceScaler(r.Clientset).Scale(ctx, *rmq, desiredCapacity)
desiredCapacity, err := persistenceStorageCapacity(desiredSts.Spec.VolumeClaimTemplates)
if err != nil {
msg := fmt.Sprintf("Failed to determine PVC capacity: %s", err.Error())
logger.Error(err, msg)
r.Recorder.Event(rmq, corev1.EventTypeWarning, "FailedReconcilePersistence", msg)
return err
}
err = scaling.NewPersistenceScaler(r.Clientset).Scale(ctx, *rmq, desiredCapacity)
if err != nil {
msg := fmt.Sprintf("Failed to scale PVCs: %s", err.Error())
logger.Error(fmt.Errorf("hit an error while scaling PVC capacity: %w", err), msg)
Expand All @@ -24,11 +30,20 @@ func (r *RabbitmqClusterReconciler) reconcilePVC(ctx context.Context, rmq *rabbi
return err
}

func persistenceStorageCapacity(templates []corev1.PersistentVolumeClaim) k8sresource.Quantity {
func persistenceStorageCapacity(templates []corev1.PersistentVolumeClaim) (k8sresource.Quantity, error) {
for _, t := range templates {
if t.Name == "persistence" {
return t.Spec.Resources.Requests[corev1.ResourceStorage]
storage := t.Spec.Resources.Requests[corev1.ResourceStorage]
if storage.IsZero() {
return storage, fmt.Errorf(
"PVC template 'persistence' has spec.resources.requests.storage=0 (or missing). " +
"If using override.statefulSet.spec.volumeClaimTemplates, you must provide " +
"the COMPLETE template including spec.resources.requests.storage. " +
"Overrides replace the entire volumeClaimTemplate, not merge with it")
}
return storage, nil
}
}
return k8sresource.MustParse("0")
// No persistence template found - this is valid for ephemeral storage (storage: "0Gi")
return k8sresource.MustParse("0"), nil
}
2 changes: 2 additions & 0 deletions docs/api/rabbitmq.com.ref.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-

| *`spec`* __link:https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.23/#persistentvolumeclaimspec-v1-core[$$PersistentVolumeClaimSpec$$]__ | Spec defines the desired characteristics of a volume requested by a pod author.
More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#persistentvolumeclaims
When using override.statefulSet.spec.volumeClaimTemplates, you must provide the complete
template including spec.resources.requests.storage. Overrides replace the entire template.
|===


Expand Down
3 changes: 2 additions & 1 deletion internal/scaling/scaling.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ func (p PersistenceScaler) Scale(ctx context.Context, rmq rabbitmqv1beta1.Rabbit

// desired storage capacity is smaller than the current capacity; we can't proceed lest we lose data
if err == nil && existingCapacity.Cmp(desiredCapacity) == 1 {
msg := "shrinking persistent volumes is not supported"
msg := fmt.Sprintf("shrinking persistent volumes is not supported (existing: %s, desired: %s)",
existingCapacity.String(), desiredCapacity.String())
logger.Error(errors.New("unsupported operation"), msg)
return errors.New(msg)
}
Expand Down
Loading