Skip to content

Commit 9f9c439

Browse files
committed
Adds a New Condition for PVC Resize Errors
A new condition has been created to surface controller and node resize error condition details in the PostgresCluster status. This also allows an exclude rule for the linter to be removed.
1 parent 740400d commit 9f9c439

File tree

3 files changed

+43
-10
lines changed

3 files changed

+43
-10
lines changed

.golangci.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,6 @@ issues:
114114
path: internal/kubernetes/discovery.go
115115
text: k8s.io/client-go/discovery
116116

117-
# PGO-2010
118-
- linters: [exhaustive]
119-
path: internal/controller/postgrescluster/volumes.go
120-
text: 'v1.PersistentVolumeClaimConditionType: v1.PersistentVolumeClaimControllerResizeError, v1.PersistentVolumeClaimNodeResizeError$'
121-
122117
# These value types have unmarshal methods.
123118
# https://github.com/raeperd/recvcheck/issues/7
124119
- linters: [recvcheck]

internal/controller/postgrescluster/volumes.go

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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.
3536
func (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

pkg/apis/postgres-operator.crunchydata.com/v1beta1/postgrescluster_types.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -410,10 +410,11 @@ type PostgresClusterStatus struct {
410410

411411
// PostgresClusterStatus condition types.
412412
const (
413-
PersistentVolumeResizing = "PersistentVolumeResizing"
414-
PostgresClusterProgressing = "Progressing"
415-
ProxyAvailable = "ProxyAvailable"
416-
Registered = "Registered"
413+
PersistentVolumeResizing = "PersistentVolumeResizing"
414+
PersistentVolumeResizeError = "PersistentVolumeResizeError"
415+
PostgresClusterProgressing = "Progressing"
416+
ProxyAvailable = "ProxyAvailable"
417+
Registered = "Registered"
417418
)
418419

419420
type PostgresInstanceSetSpec struct {

0 commit comments

Comments
 (0)