Skip to content

fix(pvc): support VolumeAttributesClass reconciliation - #7885

Merged
gbartolini merged 4 commits into
mainfrom
dev/7800
Jul 9, 2025
Merged

gbartolini merged 4 commits into
mainfrom
dev/7800

Conversation

@armru

@armru armru commented Jun 24, 2025 •

Copy link
Copy Markdown
Member

Add missing support for reconciling VolumeAttributesClass in pvcTemplate, leveraging the feature promoted to beta in Kubernetes 1.31 (disabled by default).

A VolumeAttributesClass allows administrators (typically cloud providers) to define mutable "classes" of storage, mapping to different quality-of-service levels, while Kubernetes remains unopinionated about their semantics.
See: https://kubernetes.io/docs/concepts/storage/volume-attributes-classes/

This patch also refactors the PVC reconciliation logic to simplify handling additional parameters.

Closes #7800

Release notes

The operator now ensures that the VolumeAttributesClassName in PVCs matches the configuration defined in the pvcTemplate.

@armru
armru requested a review from a team June 24, 2025 14:09
@cnpg-bot cnpg-bot added backport-requested ◀️ This pull request should be backported to all supported releases release-1.22 labels Jun 24, 2025
@github-actions

Copy link
Copy Markdown
Contributor

❗ By default, the pull request is configured to backport to all release branches.

  • To stop backporting this pr, remove the label: backport-requested ◀️ or add the label 'do not backport'
  • To stop backporting this pr to a certain release branch, remove the specific branch label: release-x.y

@armru

armru commented Jun 24, 2025

Copy link
Copy Markdown
Member Author

/test limit=local

@github-actions

Copy link
Copy Markdown
Contributor

@armru armru added do not backport This PR must not be backported - it will be in the next minor release and removed release-1.22 backport-requested ◀️ This pull request should be backported to all supported releases labels Jun 24, 2025
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement 🪄 New feature or request ok to merge 👌 This PR can be merged labels Jun 24, 2025
@leonardoce

Copy link
Copy Markdown
Contributor

A Kubernetes environment with the VolumeAttributeClass feature enabled is required to test this patch.
To enable it in the local development environment, you need to apply the following patch against setup-cluster.sh:

diff --git a/hack/setup-cluster.sh b/hack/setup-cluster.sh
index 6d8d008c3..9b69a4143 100755
--- a/hack/setup-cluster.sh
+++ b/hack/setup-cluster.sh
@@ -120,6 +120,15 @@ apiVersion: kind.x-k8s.io/v1alpha4
 networking:
   apiServerAddress: "0.0.0.0"

+featureGates:
+  # any feature gate can be enabled here with "Name": true
+  # or disabled here with "Name": false
+  # not all feature gates are tested, however
+  "VolumeAttributesClass": true
+
+runtimeConfig:
+  storage.k8s.io/v1beta1: "true"
+
 # add to the apiServer certSANs the name of the docker (dind) service in order to be able to reach the cluster through it
 kubeadmConfigPatchesJSON6902:
   - group: kubeadm.k8s.io

And then, the VolumeAttributeClass feature gate need to be enabled in the external-provisioner sidecar deployed by the hostpath CSI driver.
You can use the --feature-gates command line option in the csi-provisioner sidecar of the csi-hostpathplugin statefulset to do that:

      - args:
        - -v=5
        - --csi-address=/csi/csi.sock
        - --feature-gates=Topology=true,VolumeAttributesClass=true # <===
        image: registry.k8s.io/sig-storage/csi-provisioner:v5.2.0
        imagePullPolicy: IfNotPresent
        name: csi-provisioner
        resources: {}
        securityContext:
          privileged: true
        terminationMessagePath: /dev/termination-log
        terminationMessagePolicy: File
        volumeMounts:
        - mountPath: /csi
          name: socket-dir

After that, the ModifyVolume GRPC call must be enabled in the CSI driver with the following change:

      - args:
        - --drivername=hostpath.csi.k8s.io
        - --v=5
        - --endpoint=$(CSI_ENDPOINT)
        - --nodeid=$(KUBE_NODE_NAME)
        - --enable-controller-modify-volume=true  # <=====
        env:
        - name: CSI_ENDPOINT
          value: unix:///csi/csi.sock
        - name: KUBE_NODE_NAME
          valueFrom:
            fieldRef:
              apiVersion: v1
              fieldPath: spec.nodeName
        image: registry.k8s.io/sig-storage/hostpathplugin:v1.16.1
        imagePullPolicy: IfNotPresent
        livenessProbe:
          failureThreshold: 5
          httpGet:
            path: /healthz
            port: healthz
            scheme: HTTP
          initialDelaySeconds: 10
          periodSeconds: 2
          successThreshold: 1
          timeoutSeconds: 3
        name: hostpath

Having done that, VolumeAttributeClasses will be supported by the Kind cluster and the CSI hostpath driver.

This is a basic example of a VolumeAttributeClass:

apiVersion: storage.k8s.io/v1beta1
kind: VolumeAttributesClass
metadata:
  name: silver
driverName: hostpath.csi.k8s.io
parameters:
  provisioned-iops: "3000"
  provisioned-throughput: "50"

And can be referenced from the cluster with:

apiVersion: postgresql.cnpg.io/v1
kind: Cluster
metadata:
  name: cluster-example
spec:
  instances: 3
  imageName: ghcr.io/cloudnative-pg/postgresql:13

  storage:
    size: 1Gi
    storageClass: csi-hostpath-sc
    pvcTemplate:
      volumeAttributesClassName: silver

You can create multiple volume attribute classes, and when you change the PVC template in the cluster the volume attribute class name will be reconciled in the existing PVCs.

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jun 27, 2025
@gbartolini gbartolini changed the title feat(pvc): add VolumeAttributeClass reconciliation capability feat(pvc): support VolumeAttributesClass reconciliation Jul 9, 2025
Signed-off-by: Gabriele Bartolini <[email protected]>
@gbartolini
gbartolini requested a review from jsilvela as a code owner July 9, 2025 07:38
@gbartolini gbartolini changed the title feat(pvc): support VolumeAttributesClass reconciliation fix(pvc): support VolumeAttributesClass reconciliation Jul 9, 2025
@gbartolini gbartolini removed the enhancement 🪄 New feature or request label Jul 9, 2025
@gbartolini gbartolini added bug 🐛 Something isn't working backport-requested ◀️ This pull request should be backported to all supported releases release-1.25 and removed do not backport This PR must not be backported - it will be in the next minor release labels Jul 9, 2025
@gbartolini

Copy link
Copy Markdown
Contributor

After chatting with @armru, we believe that this is more a bug than a feature and should be backported. He made me reflect on the piece of documentation that I had added. When we talk about a PVC template, users expect us to reconcile what Kubernetes already provides. From this perspective, this is an operator "deficiency" and thus a bug. @leonardoce thoughts, given that you reviewed the patch?

@leonardoce

Copy link
Copy Markdown
Contributor

It is fine with me! Let's backport it.

@gbartolini
gbartolini merged commit 3b17eb1 into main Jul 9, 2025
@gbartolini
gbartolini deleted the dev/7800 branch July 9, 2025 08:21
cnpg-bot pushed a commit that referenced this pull request Jul 9, 2025
Add missing support for reconciling `VolumeAttributesClass` in
`pvcTemplate`, leveraging the feature promoted to beta in Kubernetes
1.31 (disabled by default).

A `VolumeAttributesClass` allows administrators (typically cloud
providers) to define mutable "classes" of storage, mapping to different
quality-of-service levels, while Kubernetes remains unopinionated about
their semantics.
See:
https://kubernetes.io/docs/concepts/storage/volume-attributes-classes/

This patch also refactors the PVC reconciliation logic to simplify
handling additional parameters.

Closes #7800

## Release notes

The operator now ensures that the `VolumeAttributesClassName` in PVCs
matches the configuration defined in the `pvcTemplate`.

Signed-off-by: Armando Ruocco <[email protected]>
(cherry picked from commit 3b17eb1)
cnpg-bot pushed a commit that referenced this pull request Jul 9, 2025
Add missing support for reconciling `VolumeAttributesClass` in
`pvcTemplate`, leveraging the feature promoted to beta in Kubernetes
1.31 (disabled by default).

A `VolumeAttributesClass` allows administrators (typically cloud
providers) to define mutable "classes" of storage, mapping to different
quality-of-service levels, while Kubernetes remains unopinionated about
their semantics.
See:
https://kubernetes.io/docs/concepts/storage/volume-attributes-classes/

This patch also refactors the PVC reconciliation logic to simplify
handling additional parameters.

Closes #7800

## Release notes

The operator now ensures that the `VolumeAttributesClassName` in PVCs
matches the configuration defined in the `pvcTemplate`.

Signed-off-by: Armando Ruocco <[email protected]>
(cherry picked from commit 3b17eb1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport-requested ◀️ This pull request should be backported to all supported releases bug 🐛 Something isn't working lgtm This PR has been approved by a maintainer ok to merge 👌 This PR can be merged size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Support Volume Attributes Classes

4 participants