@@ -31,7 +31,8 @@ import (
3131// +kubebuilder:rbac:groups="",resources="persistentvolumeclaims",verbs={list}
3232
3333// observePersistentVolumeClaims reads all PVCs for cluster from the Kubernetes
34- // API and sets the PersistentVolumeResizing condition as appropriate.
34+ // API and sets the PersistentVolumeResizing and/or the PersistentVolumeResizeError
35+ // conditions as appropriate.
3536func (r * Reconciler ) observePersistentVolumeClaims (
3637 ctx context.Context , cluster * v1beta1.PostgresCluster ,
3738) ([]* corev1.PersistentVolumeClaim , error ) {
@@ -53,6 +54,12 @@ func (r *Reconciler) observePersistentVolumeClaims(
5354 ObservedGeneration : cluster .Generation ,
5455 }
5556
57+ // create a condition for surfacing any PVC resize error conditions
58+ resizingError := metav1.Condition {
59+ Type : v1beta1 .PersistentVolumeResizeError ,
60+ ObservedGeneration : cluster .Generation ,
61+ }
62+
5663 minNotZero := func (a , b metav1.Time ) metav1.Time {
5764 if b .IsZero () || (a .Before (& b ) && ! a .IsZero ()) {
5865 return a
@@ -119,7 +126,31 @@ func (r *Reconciler) observePersistentVolumeClaims(
119126 resizing .LastTransitionTime = minNotZero (
120127 resizing .LastTransitionTime , condition .LastTransitionTime )
121128 }
129+ case
130+ // The "ControllerResizeError" and "NodeResizeError" conditions were added in
131+ // Kubernetes v1.31 for indicating node and controller failures when resizing
132+ // a volume:
133+ // - https://github.com/kubernetes/enhancements/pull/4692
134+ // - https://github.com/kubernetes/kubernetes/pull/126108
135+ corev1 .PersistentVolumeClaimControllerResizeError ,
136+ corev1 .PersistentVolumeClaimNodeResizeError :
137+
138+ // Add pertinent details from the resize error condition in the PVC to the resize
139+ // error condition in the PostgresCluster status. In the event that there is both
140+ // a controller resize error and a node resize error, only the details from one
141+ // will be displayed at a time in the PostgresCluster condition.
142+ if condition .Status == corev1 .ConditionTrue {
143+ resizingError .Status = metav1 .ConditionStatus (condition .Status )
144+ resizingError .Reason = condition .Reason
145+ resizingError .Message = condition .Message
146+ resizingError .LastTransitionTime = condition .LastTransitionTime
122147
148+ // corev1.PersistentVolumeClaimCondition.Reason is optional
149+ // while metav1.Condition.Reason is required.
150+ if resizingError .Reason == "" {
151+ resizingError .Reason = string (condition .Type )
152+ }
153+ }
123154 case
124155 // The "ModifyingVolume" and "ModifyVolumeError" conditions occur
125156 // when the attribute class of a PVC is changing. These attributes
@@ -140,6 +171,12 @@ func (r *Reconciler) observePersistentVolumeClaims(
140171 meta .RemoveStatusCondition (& cluster .Status .Conditions , resizing .Type )
141172 }
142173
174+ if resizingError .Status != "" {
175+ meta .SetStatusCondition (& cluster .Status .Conditions , resizingError )
176+ } else {
177+ meta .RemoveStatusCondition (& cluster .Status .Conditions , resizingError .Type )
178+ }
179+
143180 return initialize .Pointers (volumes .Items ... ), err
144181}
145182
0 commit comments