Skip to content

[WIP] feat: support changing cachingMode through VolumeAttributeClass#3584

Open
andyzhangx wants to merge 2 commits intokubernetes-sigs:masterfrom
andyzhangx:feat/support-cachingmode-in-modify-volume
Open

[WIP] feat: support changing cachingMode through VolumeAttributeClass#3584
andyzhangx wants to merge 2 commits intokubernetes-sigs:masterfrom
andyzhangx:feat/support-cachingmode-in-modify-volume

Conversation

@andyzhangx
Copy link
Copy Markdown
Member

@andyzhangx andyzhangx commented Apr 11, 2026

What type of PR is this?

/kind feature

What this PR does / why we need it:

Adds support for changing cachingMode via VolumeAttributeClass by validating the parameter in ControllerModifyVolume and updating the disk's caching mode on the VM in-place.

How it works

cachingMode is a VM-level data disk attachment property. When modified via VolumeAttributeClass:

  1. ControllerModifyVolume validates the new cachingMode value
  2. Enforces constraints: disks >= 4 TiB only support None; PremiumV2_LRS only supports None
  3. If the disk is currently attached to a VM, calls UpdateDiskCachingMode which:
    • Finds the node the disk is attached to via disk.ManagedBy
    • Gets the disk's current LUN
    • Issues an AttachDisk call with the existing LUN and new cachingMode to update the VM
  4. If the disk is not attached, the update is a no-op — the new cachingMode will be applied on next attach via PV volumeAttributes

Changes

  • azure_controller_common.go: Added UpdateDiskCachingMode method on controllerCommon
  • controllerserver.go: Added cachingMode validation and update logic in ControllerModifyVolume
  • controllerserver_test.go: Added 4 unit test cases (3 valid modes + 1 invalid)

Example VolumeAttributeClass

apiVersion: storage.k8s.io/v1beta1
kind: VolumeAttributesClass
metadata:
  name: caching-readonly
driverName: disk.csi.azure.com
parameters:
  cachingMode: ReadOnly

Which issue(s) this PR fixes:

Fixes #3471

Special notes for your reviewer:

  • Supported cachingMode values: None, ReadOnly, ReadWrite
  • For attached disks, the change is applied in-place via VM update (no pod restart required)
  • For unattached disks, the new cachingMode takes effect on next attach

@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Apr 11, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: andyzhangx

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 11, 2026
@andyzhangx andyzhangx force-pushed the feat/support-cachingmode-in-modify-volume branch from 53abd35 to 5af5d6f Compare April 11, 2026 09:30
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Apr 11, 2026
@andyzhangx andyzhangx force-pushed the feat/support-cachingmode-in-modify-volume branch 2 times, most recently from 5f0ea93 to 9c1c857 Compare April 11, 2026 13:45
@andyzhangx andyzhangx changed the title feat: support changing cachingMode through VolumeAttributeClass [WIP] feat: support changing cachingMode through VolumeAttributeClass Apr 11, 2026
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 11, 2026
In ControllerModifyVolume:
- Validate the cachingMode parameter
- Enforce caching limits (disks >= 4 TiB support only None)
- Enforce PremiumV2_LRS constraint (only None)
- Pass cachingMode to ModifyDisk via ManagedDiskOptions

In ModifyDisk:
- Accept CachingMode in ManagedDiskOptions
- Log cachingMode update (applied on next ControllerPublishVolume attach)

Note: cachingMode is a VM-level data disk attachment property, not a disk
resource property. The new value is persisted in PV volumeAttributes via
VolumeAttributeClass and takes effect on next ControllerPublishVolume.

Fixes: kubernetes-sigs#3471
@andyzhangx andyzhangx force-pushed the feat/support-cachingmode-in-modify-volume branch from 9c1c857 to 0048abf Compare April 11, 2026 13:58
@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 11, 2026
Add modify-volume-params.yaml with cachingmode: ReadOnly and pass
--csi.testvolumemutableparameters to csi-sanity so ModifyVolume tests
exercise the real cachingMode code path instead of empty parameters.
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

@andyzhangx: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-azuredisk-csi-driver-e2e-capz 7d82151 link true /test pull-azuredisk-csi-driver-e2e-capz

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/feature Categorizes issue or PR as related to a new feature. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support changing cachingMode through VolumeAttributeClass

2 participants