Skip to content

Commit

Permalink
Adds a New Condition for PVC Resize Errors
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
andrewlecuyer committed Feb 7, 2025
1 parent 740400d commit 9f9c439
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 10 deletions.
5 changes: 0 additions & 5 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,6 @@ issues:
path: internal/kubernetes/discovery.go
text: k8s.io/client-go/discovery

# PGO-2010
- linters: [exhaustive]
path: internal/controller/postgrescluster/volumes.go
text: 'v1.PersistentVolumeClaimConditionType: v1.PersistentVolumeClaimControllerResizeError, v1.PersistentVolumeClaimNodeResizeError$'

# These value types have unmarshal methods.
# https://github.com/raeperd/recvcheck/issues/7
- linters: [recvcheck]
Expand Down
39 changes: 38 additions & 1 deletion internal/controller/postgrescluster/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import (
// +kubebuilder:rbac:groups="",resources="persistentvolumeclaims",verbs={list}

// observePersistentVolumeClaims reads all PVCs for cluster from the Kubernetes
// API and sets the PersistentVolumeResizing condition as appropriate.
// API and sets the PersistentVolumeResizing and/or the PersistentVolumeResizeError
// conditions as appropriate.
func (r *Reconciler) observePersistentVolumeClaims(
ctx context.Context, cluster *v1beta1.PostgresCluster,
) ([]*corev1.PersistentVolumeClaim, error) {
Expand All @@ -53,6 +54,12 @@ func (r *Reconciler) observePersistentVolumeClaims(
ObservedGeneration: cluster.Generation,
}

// create a condition for surfacing any PVC resize error conditions
resizingError := metav1.Condition{
Type: v1beta1.PersistentVolumeResizeError,
ObservedGeneration: cluster.Generation,
}

minNotZero := func(a, b metav1.Time) metav1.Time {
if b.IsZero() || (a.Before(&b) && !a.IsZero()) {
return a
Expand Down Expand Up @@ -119,7 +126,31 @@ func (r *Reconciler) observePersistentVolumeClaims(
resizing.LastTransitionTime = minNotZero(
resizing.LastTransitionTime, condition.LastTransitionTime)
}
case
// The "ControllerResizeError" and "NodeResizeError" conditions were added in
// Kubernetes v1.31 for indicating node and controller failures when resizing
// a volume:
// - https://github.com/kubernetes/enhancements/pull/4692
// - https://github.com/kubernetes/kubernetes/pull/126108
corev1.PersistentVolumeClaimControllerResizeError,
corev1.PersistentVolumeClaimNodeResizeError:

// Add pertinent details from the resize error condition in the PVC to the resize
// error condition in the PostgresCluster status. In the event that there is both
// a controller resize error and a node resize error, only the details from one
// will be displayed at a time in the PostgresCluster condition.
if condition.Status == corev1.ConditionTrue {
resizingError.Status = metav1.ConditionStatus(condition.Status)
resizingError.Reason = condition.Reason
resizingError.Message = condition.Message
resizingError.LastTransitionTime = condition.LastTransitionTime

// corev1.PersistentVolumeClaimCondition.Reason is optional
// while metav1.Condition.Reason is required.
if resizingError.Reason == "" {
resizingError.Reason = string(condition.Type)
}
}
case
// The "ModifyingVolume" and "ModifyVolumeError" conditions occur
// when the attribute class of a PVC is changing. These attributes
Expand All @@ -140,6 +171,12 @@ func (r *Reconciler) observePersistentVolumeClaims(
meta.RemoveStatusCondition(&cluster.Status.Conditions, resizing.Type)
}

if resizingError.Status != "" {
meta.SetStatusCondition(&cluster.Status.Conditions, resizingError)
} else {
meta.RemoveStatusCondition(&cluster.Status.Conditions, resizingError.Type)
}

return initialize.Pointers(volumes.Items...), err
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,11 @@ type PostgresClusterStatus struct {

// PostgresClusterStatus condition types.
const (
PersistentVolumeResizing = "PersistentVolumeResizing"
PostgresClusterProgressing = "Progressing"
ProxyAvailable = "ProxyAvailable"
Registered = "Registered"
PersistentVolumeResizing = "PersistentVolumeResizing"
PersistentVolumeResizeError = "PersistentVolumeResizeError"
PostgresClusterProgressing = "Progressing"
ProxyAvailable = "ProxyAvailable"
Registered = "Registered"
)

type PostgresInstanceSetSpec struct {
Expand Down

0 comments on commit 9f9c439

Please sign in to comment.