Skip to content

Commit fc560f9

Browse files
committed
fixes
1 parent ba44229 commit fc560f9

File tree

3 files changed

+14
-19
lines changed

3 files changed

+14
-19
lines changed

pkg/controller/perconaservermongodb/metrics_client.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@ import (
77
"strings"
88
"time"
99

10+
"github.com/percona/percona-server-mongodb-operator/pkg/naming"
11+
"github.com/percona/percona-server-mongodb-operator/pkg/psmdb/config"
1012
"github.com/pkg/errors"
1113
corev1 "k8s.io/api/core/v1"
1214
"k8s.io/apimachinery/pkg/util/wait"
1315
"k8s.io/client-go/util/retry"
14-
logf "sigs.k8s.io/controller-runtime/pkg/log"
15-
16-
"github.com/percona/percona-server-mongodb-operator/pkg/naming"
17-
"github.com/percona/percona-server-mongodb-operator/pkg/psmdb/config"
1816
)
1917

2018
// PVCUsage contains information about PVC disk usage
@@ -30,17 +28,10 @@ func (r *ReconcilePerconaServerMongoDB) getPVCUsageFromMetrics(
3028
pod *corev1.Pod,
3129
pvcName string,
3230
) (*PVCUsage, error) {
33-
log := logf.FromContext(ctx).WithName("StorageAutoscaling").WithValues("pvc", pvcName)
34-
3531
if pod == nil {
3632
return nil, errors.New("pod is nil")
3733
}
3834

39-
if !isContainerAndPodRunning(*pod, naming.ComponentMongod) {
40-
log.V(1).Info("skipping PVC metrics check: container and pod not running", "phase", pod.Status.Phase)
41-
return nil, nil
42-
}
43-
4435
backoff := wait.Backoff{
4536
Steps: 5,
4637
Duration: 5 * time.Second,

pkg/controller/perconaservermongodb/statefulset.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,14 @@ func (r *ReconcilePerconaServerMongoDB) reconcileStatefulSet(ctx context.Context
5454
return sfs, nil
5555
}
5656

57-
if err := r.reconcilePVCs(ctx, cr, sfs, ls, volumeSpec); err != nil {
58-
return nil, errors.Wrapf(err, "reconcile PVCs for %s", sfs.Name)
59-
}
60-
61-
// (non-blocking)
6257
if err := r.reconcileStorageAutoscaling(ctx, cr, sfs, volumeSpec, ls); err != nil {
6358
log.Error(err, "failed to reconcile storage autoscaling", "statefulset", sfs.Name)
6459
}
6560

61+
if err := r.reconcilePVCs(ctx, cr, sfs, ls, volumeSpec); err != nil {
62+
return nil, errors.Wrapf(err, "reconcile PVCs for %s", sfs.Name)
63+
}
64+
6665
if _, ok := sfs.Annotations[api.AnnotationPVCResizeInProgress]; ok {
6766
log.V(1).Info("PVC resize in progress, skipping reconciliation of statefulset", "name", sfs.Name)
6867
return sfs, nil

pkg/controller/perconaservermongodb/volume_autoscaling.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"strings"
66
"time"
77

8+
"github.com/percona/percona-server-mongodb-operator/pkg/naming"
89
"github.com/pkg/errors"
910
appsv1 "k8s.io/api/apps/v1"
1011
corev1 "k8s.io/api/core/v1"
@@ -102,6 +103,11 @@ func (r *ReconcilePerconaServerMongoDB) checkAndResizePVC(
102103
) error {
103104
log := logf.FromContext(ctx).WithName("StorageAutoscaling").WithValues("pvc", pvc.Name)
104105

106+
if !isContainerAndPodRunning(*pod, naming.ComponentMongod) {
107+
log.V(1).Info("skipping PVC metrics check: container and pod not running", "phase", pod.Status.Phase)
108+
return nil
109+
}
110+
105111
usage, err := r.getPVCUsageFromMetrics(ctx, pod, pvc.Name)
106112
if err != nil {
107113
return errors.Wrap(err, "get PVC usage from metrics")
@@ -193,12 +199,11 @@ func (r *ReconcilePerconaServerMongoDB) triggerResize(
193199
) error {
194200
log := logf.FromContext(ctx).WithName("StorageAutoscaling").WithValues("pvc", pvc.Name)
195201

196-
patch := client.MergeFrom(cr.DeepCopy())
202+
orig := cr.DeepCopy()
197203

198-
// We are modifying cr directly through the pointer. So the original cr object does get the storage size updated.
199204
volumeSpec.PersistentVolumeClaim.Resources.Requests[corev1.ResourceStorage] = newSize
200205

201-
if err := r.client.Patch(ctx, cr.DeepCopy(), patch); err != nil {
206+
if err := r.client.Patch(ctx, cr.DeepCopy(), client.MergeFrom(orig)); err != nil {
202207
return errors.Wrap(err, "patch CR with new storage size")
203208
}
204209

0 commit comments

Comments
 (0)