Skip to content

K8SPSMDB-1389: don't round up pvc sizes#2341

Merged
hors merged 11 commits into
mainfrom
K8SPSMDB-1389
Jun 11, 2026
Merged

K8SPSMDB-1389: don't round up pvc sizes#2341
hors merged 11 commits into
mainfrom
K8SPSMDB-1389

Conversation

@pooknull

@pooknull pooknull commented May 20, 2026

Copy link
Copy Markdown
Contributor

https://perconadev.atlassian.net/browse/K8SPSMDB-1389

DESCRIPTION

Problem:
When volumeSpec.persistentVolumeClaim.resources.requests.storage is set to 1.2Gi operator creates a statefulset with the same size, but 2Gi PVC is created. After updating the cr.yaml to the 2Gi the operator should recreate the statefulset with the new size, but it tries to update statefulset instead and gets the following error: ...update error: StatefulSet.apps "..." is invalid: spec: Forbidden: updates to statefulset spec for fields other than ...

Cause:
The storage provisioners may create a 2Gi PVC for a 1.2Gi request because it allocates storage in larger chunks.
The operator logic rounded the requested size to GiB and then checked for an exact match, but the actual PVC may have a larger size than the value from the cr.yaml.
Because of that, after changing the CR to 2Gi, the operator wasn't able to check if PVC resize update is needed and tried to update the StatefulSet template instead.

Solution:
The operator now uses the exact value from cr.yaml and treats the pvc as correct when its actual size is greater than or equal to the requested size.
It also checks whether the StatefulSet template still has an old storage value. If the PVC already has enough space but the template is different, the operator deletes and recreates the StatefulSet instead of trying to update it

CHECKLIST

Jira

  • Is the Jira ticket created and referenced properly?
  • Does the Jira ticket have the proper statuses for documentation (Needs Doc) and QA (Needs QA)?
  • Does the Jira ticket link to the proper milestone (Fix Version field)?

Tests

  • Is an E2E test/test case added for the new feature/change?
  • Are unit tests added where appropriate?
  • Are OpenShift compare files changed for E2E tests (compare/*-oc.yml)?

Config/Logging/Testability

  • Are all needed new/changed options added to default YAML files?
  • Are all needed new/changed options added to the Helm Chart?
  • Did we add proper logging messages for operator actions?
  • Did we ensure compatibility with the previous version or cluster upgrade process?
  • Does the change support oldest and newest supported MongoDB version?
  • Does the change support oldest and newest supported Kubernetes version?

Copilot AI review requested due to automatic review settings May 20, 2026 13:14
@pull-request-size pull-request-size Bot added the size/L 100-499 lines label May 20, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Updates PVC resize logic to avoid rounding/overshoot issues (e.g., storage backends provisioning larger-than-requested PVCs) and adds tests to cover the revised reconciliation behavior.

Changes:

  • Stop rounding requested PVC sizes up to GiB during reconciliation and autoscaling calculations.
  • Treat PVC resize as finished when capacity is >= requested (not only equal).
  • Add unit tests for PVC reconciliation, including external autoscaling/volume expansion combinations.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
pkg/controller/perconaservermongodb/volumes.go Removes GiB rounding and adjusts resize finish + stale template handling logic.
pkg/controller/perconaservermongodb/volume_autoscaling.go Removes GiB rounding from autoscaling size calculation.
pkg/controller/perconaservermongodb/volumes_test.go Adds new unit tests for reconcilePVCs behavior across resize/shrink/stale-template scenarios.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/controller/perconaservermongodb/volumes_test.go
Comment thread pkg/controller/perconaservermongodb/volumes_test.go
Comment thread pkg/controller/perconaservermongodb/volumes_test.go
Comment thread pkg/controller/perconaservermongodb/volumes_test.go
Comment thread pkg/controller/perconaservermongodb/volumes.go Outdated
@pooknull pooknull marked this pull request as ready for review May 27, 2026 10:59
Copilot AI review requested due to automatic review settings May 27, 2026 10:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

Comment on lines 141 to 147
for _, pvc := range pvcList.Items {
if !validatePVCName(pvc, sts) {
continue
}

if pvc.Status.Capacity.Storage().Cmp(requested) == 0 {
if pvc.Status.Capacity.Storage().Cmp(requested) >= 0 {
updatedPVCs++

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pooknull do we need to address this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread pkg/controller/perconaservermongodb/volumes.go
Comment thread pkg/controller/perconaservermongodb/volumes.go
Comment thread pkg/controller/perconaservermongodb/volumes_test.go
Comment thread pkg/controller/perconaservermongodb/volumes.go
Comment thread pkg/controller/perconaservermongodb/volumes.go
@hors hors added this to the v1.23.0 milestone Jun 8, 2026

@hors hors left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to fix go lint?

"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes/scheme"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pooknull please check golangci-lint error

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot AI review requested due to automatic review settings June 9, 2026 09:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread pkg/controller/perconaservermongodb/volumes.go Outdated
Comment thread pkg/controller/perconaservermongodb/volumes.go
Comment thread pkg/controller/perconaservermongodb/volumes.go Outdated
@pooknull pooknull requested review from egegunes and hors June 9, 2026 09:53
Copilot AI review requested due to automatic review settings June 9, 2026 09:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings June 10, 2026 17:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

}

if pvc.Status.Capacity.Storage().Cmp(requested) == 0 {
if pvc.Status.Capacity.Storage().Cmp(requested) >= 0 {
@JNKPercona

Copy link
Copy Markdown
Collaborator
Test Name Result Time
arbiter passed 00:00:00
balancer passed 00:18:26
cert-management-policy passed 00:00:00
cross-site-sharded passed 00:00:00
custom-replset-name passed 00:00:00
custom-tls passed 00:00:00
custom-users-roles passed 00:00:00
custom-users-roles-sharded passed 00:00:00
data-at-rest-encryption passed 00:00:00
data-sharded passed 00:21:53
demand-backup passed 00:00:00
demand-backup-eks-credentials-irsa passed 00:00:00
demand-backup-fs passed 00:23:31
demand-backup-if-unhealthy passed 00:00:00
demand-backup-incremental-aws passed 00:00:00
demand-backup-incremental-azure passed 00:00:00
demand-backup-incremental-gcp-native passed 00:00:00
demand-backup-incremental-gcp-s3 passed 00:00:00
demand-backup-incremental-minio passed 00:27:06
demand-backup-incremental-sharded-aws passed 00:00:00
demand-backup-incremental-sharded-azure passed 00:00:00
demand-backup-incremental-sharded-gcp-native passed 00:18:07
demand-backup-incremental-sharded-gcp-s3 passed 00:18:07
demand-backup-incremental-sharded-minio passed 00:00:00
demand-backup-logical-minio-native-tls passed 00:09:29
demand-backup-physical-parallel passed 00:00:00
demand-backup-physical-aws passed 00:00:00
demand-backup-physical-azure passed 00:00:00
demand-backup-physical-gcp-s3 passed 00:00:00
demand-backup-physical-gcp-native passed 00:00:00
demand-backup-physical-minio passed 00:00:00
demand-backup-physical-minio-native passed 00:00:00
demand-backup-physical-minio-native-tls passed 00:00:00
demand-backup-physical-sharded-parallel passed 00:00:00
demand-backup-physical-sharded-aws passed 00:00:00
demand-backup-physical-sharded-azure passed 00:00:00
demand-backup-physical-sharded-gcp-native passed 00:00:00
demand-backup-physical-sharded-minio passed 00:00:00
demand-backup-physical-sharded-minio-native passed 00:00:00
demand-backup-sharded passed 00:27:18
demand-backup-snapshot passed 00:39:05
demand-backup-snapshot-vault passed 00:00:00
disabled-auth passed 00:00:00
expose-sharded passed 00:34:15
finalizer passed 00:00:00
ignore-labels-annotations passed 00:00:00
init-deploy passed 00:00:00
ldap passed 00:09:49
ldap-tls passed 00:00:00
limits passed 00:00:00
liveness passed 00:00:00
mongod-major-upgrade passed 00:00:00
mongod-major-upgrade-sharded passed 00:00:00
monitoring-2-0 passed 00:00:00
monitoring-pmm3 passed 00:00:00
multi-cluster-service passed 00:18:12
multi-storage passed 00:00:00
non-voting-and-hidden passed 00:00:00
one-pod passed 00:00:00
operator-self-healing-chaos passed 00:00:00
pitr passed 00:00:00
pitr-physical passed 00:00:00
pitr-sharded passed 00:00:00
pitr-to-new-cluster passed 00:00:00
pitr-physical-backup-source passed 00:00:00
preinit-updates passed 00:00:00
pvc-auto-resize passed 00:00:00
pvc-resize passed 00:16:58
recover-no-primary passed 00:00:00
replset-overrides passed 00:00:00
replset-remapping passed 00:00:00
replset-remapping-sharded passed 00:00:00
rs-shard-migration passed 00:00:00
scaling passed 00:00:00
scheduled-backup passed 00:00:00
security-context passed 00:00:00
self-healing-chaos passed 00:00:00
service-per-pod passed 00:00:00
serviceless-external-nodes passed 00:00:00
smart-update passed 00:00:00
split-horizon passed 00:00:00
split-horizon-manual-tls passed 00:00:00
stable-resource-version passed 00:00:00
storage passed 00:00:00
tls-issue-cert-manager passed 00:00:00
unsafe-psa passed 00:00:00
upgrade passed 00:00:00
upgrade-consistency passed 00:00:00
upgrade-consistency-sharded-tls passed 00:53:16
upgrade-sharded passed 00:00:00
upgrade-partial-backup passed 00:16:13
users passed 00:00:00
users-vault passed 00:00:00
version-service passed 00:25:13
Summary Value
Tests Run 94/94
Job Duration 01:22:01
Total Test Time 06:17:04

commit: 07f38cc
image: perconalab/percona-server-mongodb-operator:PR-2341-07f38ccbd

@hors hors merged commit 3da46f5 into main Jun 11, 2026
16 checks passed
@hors hors deleted the K8SPSMDB-1389 branch June 11, 2026 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L 100-499 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants