Skip to content
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

K8SPXC-1461: improve pvc resize logs #1947

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pkg/controller/pxc/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/tools/record"
k8sretry "k8s.io/client-go/util/retry"
"sigs.k8s.io/controller-runtime/pkg/builder"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -72,13 +73,14 @@ func newReconciler(mgr manager.Manager) (reconcile.Reconciler, error) {
serverVersion: sv,
clientcmd: cli,
lockers: newLockStore(),
recorder: mgr.GetEventRecorderFor(naming.OperatorController),
}, nil
}

// add adds a new Controller to mgr with r as the reconcile.Reconciler
func add(mgr manager.Manager, r reconcile.Reconciler) error {
return builder.ControllerManagedBy(mgr).
Named("pxc-controller").
Named(naming.OperatorController).
Watches(&api.PerconaXtraDBCluster{}, &handler.EnqueueRequestForObject{}).
Complete(r)
}
Expand All @@ -96,6 +98,7 @@ type ReconcilePerconaXtraDBCluster struct {
syncUsersState int32
serverVersion *version.ServerVersion
lockers lockStore
recorder record.EventRecorder
}

type lockStore struct {
Expand Down
40 changes: 22 additions & 18 deletions pkg/controller/pxc/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pxc

import (
"context"
stderrors "errors"
"math"
"slices"
"strings"
Expand Down Expand Up @@ -137,6 +138,8 @@ func (r *ReconcilePerconaXtraDBCluster) reconcilePersistentVolumes(ctx context.C
}

updatedPVCs := 0
var resizeErrors []error
pendingResize := false
for _, pvc := range pvcList.Items {
if !validatePVCName(pvc, sts) {
continue
Expand Down Expand Up @@ -181,20 +184,29 @@ func (r *ReconcilePerconaXtraDBCluster) reconcilePersistentVolumes(ctx context.C
switch event.Reason {
case "Resizing", "ExternalExpanding", "FileSystemResizeRequired":
log.Info("PVC resize in progress", "pvc", pvc.Name, "reason", event.Reason, "message", event.Note)
pendingResize = true
case "FileSystemResizeSuccessful":
log.Info("PVC resize completed", "pvc", pvc.Name, "reason", event.Reason, "message", event.Note)
case "VolumeResizeFailed":
case "VolumeResizeFailed", naming.EventExceededQuota, naming.EventStorageClassNotSupportResize:
log.Error(nil, "PVC resize failed", "pvc", pvc.Name, "reason", event.Reason, "message", event.Note)

if err := r.handlePVCResizeFailure(ctx, cr, configured); err != nil {
return err
}

return errors.Errorf("volume resize failed: %s", event.Note)
resizeErrors = append(resizeErrors, errors.Errorf("%s pvc resize failed: %s: %s", pvc.Name, event.Reason, event.Note))
continue
}
}
}

if len(resizeErrors) > 0 {
if pendingResize {
return nil
}

if err := r.handlePVCResizeFailure(ctx, cr, configured); err != nil {
return err
}
return stderrors.Join(resizeErrors...)
}

resizeSucceeded := updatedPVCs == len(pvcsToUpdate)
if resizeSucceeded {
log.Info("Deleting statefulset")
Expand Down Expand Up @@ -255,21 +267,13 @@ func (r *ReconcilePerconaXtraDBCluster) reconcilePersistentVolumes(ctx context.C
if err := r.client.Update(ctx, &pvc); err != nil {
switch {
case strings.Contains(err.Error(), "exceeded quota"):
log.Error(err, "PVC resize failed", "reason", "ExceededQuota", "message", err.Error())
r.recorder.Event(&pvc, corev1.EventTypeWarning, naming.EventExceededQuota, "PVC resize failed")

if err := r.handlePVCResizeFailure(ctx, cr, configured); err != nil {
return err
}

return errors.Wrapf(err, "update persistentvolumeclaim/%s", pvc.Name)
continue
case strings.Contains(err.Error(), "the storageclass that provisions the pvc must support resize"):
log.Error(err, "PVC resize failed", "reason", "StorageClassNotSupportResize", "message", err.Error())
r.recorder.Event(&pvc, corev1.EventTypeWarning, naming.EventStorageClassNotSupportResize, "PVC resize failed")

if err := r.handlePVCResizeFailure(ctx, cr, configured); err != nil {
return err
}

return errors.Wrapf(err, "update persistentvolumeclaim/%s", pvc.Name)
continue
default:
return errors.Wrapf(err, "update persistentvolumeclaim/%s", pvc.Name)
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/naming/naming.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,12 @@ const (
FinalizerDeleteBackup = annotationPrefix + "delete-backup"
FinalizerS3DeleteBackup = "delete-s3-backup"
)

const (
OperatorController = "pxc-controller"
)

const (
EventStorageClassNotSupportResize = "StorageClassNotSupportResize"
EventExceededQuota = "ExceededQuota"
)
Loading