-
Notifications
You must be signed in to change notification settings - Fork 308
Fix Issue 2023: Validate VolumeClaimTemplate overrides contain spec and provide helpful error messages when they don't
#2024
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: main
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 | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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) | ||||||||||||||
|
Member
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. Setting the status condition is done higher up in the stack, it shouldn't be done here, inside a helper function. cluster-operator/controllers/rabbitmqcluster_controller.go Lines 228 to 231 in a25511e
|
||||||||||||||
| 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) | ||||||||||||||
|
|
@@ -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") | ||||||||||||||
|
Comment on lines
+39
to
+42
Member
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. This error message is too specific and leaks implementation details. Gemini suggests the following:
Suggested change
|
||||||||||||||
| } | ||||||||||||||
| return storage, nil | ||||||||||||||
| } | ||||||||||||||
| } | ||||||||||||||
| return k8sresource.MustParse("0") | ||||||||||||||
| // No persistence template found - this is valid for ephemeral storage (storage: "0Gi") | ||||||||||||||
| return k8sresource.MustParse("0"), nil | ||||||||||||||
| } | ||||||||||||||
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.
You are already providing a lot of information below in the stack, in the return error of
persistenceStorageCapacity(). In addition to that, the function logger.Error(err, any...) already prints the error, there's no need to template the error inside the messagemsg.