Skip to content

feat: Support PVC resize by propagating pvcSize changes to CNPG Cluster #298

@WentingWu666666

Description

@WentingWu666666

Problem

When a user updates spec.resource.storage.pvcSize on an existing DocumentDB CR, the change is accepted by the API server but never propagated to the underlying CNPG Cluster object or PVCs. The resize is silently ignored.

Verified behavior on Kind cluster:

Layer After patching pvcSize from 1Gi to 2Gi
DocumentDB CR Updated to 2Gi
CNPG Cluster spec.storage.size Stayed at 1Gi
PVCs Stayed at 1Gi

Root cause

In operator/src/internal/controller/physical_replication.go, TryUpdateCluster() returns early (nil, -1) when ReplicaCluster is nil, which is the case for non-replicating clusters. This means storage size changes are never compared or patched on the CNPG Cluster object. Even for replicating clusters, storage is not in the patched field set.

Proposed solution

  1. In the reconciliation loop, detect when pvcSize in the DocumentDB CR differs from the current CNPG Cluster's spec.storage.size
  2. Patch the CNPG Cluster's spec.storage.size field to match the desired size
  3. CNPG will then handle the actual PVC expansion (requires allowVolumeExpansion: true on the StorageClass)
  4. Add validation: reject shrink attempts (PVC expansion is one-way)

Files to modify

  • operator/src/internal/controller/physical_replication.go Add storage size comparison and patching
  • operator/src/internal/controller/documentdb_controller.go Ensure storage changes trigger CNPG cluster update
  • Consider adding a webhook to reject pvcSize decreases

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions