From 9f9c43963ebc5fa399b6b06f7d71dc8f3d2e5f38 Mon Sep 17 00:00:00 2001 From: andrewlecuyer Date: Fri, 7 Feb 2025 14:25:44 +0000 Subject: [PATCH] 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. --- .golangci.yaml | 5 --- .../controller/postgrescluster/volumes.go | 39 ++++++++++++++++++- .../v1beta1/postgrescluster_types.go | 9 +++-- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 1631433a4..da19e2697 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -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] diff --git a/internal/controller/postgrescluster/volumes.go b/internal/controller/postgrescluster/volumes.go index c8d3c0a38..aeeeac616 100644 --- a/internal/controller/postgrescluster/volumes.go +++ b/internal/controller/postgrescluster/volumes.go @@ -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) { @@ -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 @@ -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 @@ -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 } diff --git a/pkg/apis/postgres-operator.crunchydata.com/v1beta1/postgrescluster_types.go b/pkg/apis/postgres-operator.crunchydata.com/v1beta1/postgrescluster_types.go index 57ed32644..f00492c8a 100644 --- a/pkg/apis/postgres-operator.crunchydata.com/v1beta1/postgrescluster_types.go +++ b/pkg/apis/postgres-operator.crunchydata.com/v1beta1/postgrescluster_types.go @@ -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 {