kubernetes-sigs / vsphere-csi-driver

vSphere storage Container Storage Interface (CSI) plugin
https://docs.vmware.com/en/VMware-vSphere-Container-Storage-Plug-in/index.html
Apache License 2.0
296 stars 179 forks source link

Create/delete StoragePolicyUsage CR for VolumeSnapshot resource kind on create/delete of StoragePolicyQuota CR #2866

Closed akankshapanse closed 5 months ago

akankshapanse commented 5 months ago

What this PR does / why we need it: This PR creates/deletes StoragePolicyUsage CR for VolumeSnapshot resource kind on event of create or delete of StoragePolicyQuota CR in syncer, if StorageQuotaM2 FSS is enabled. If StorageQuotaM2 FSS is disabled, syncer creates/deletes only PVC specific StoragePolicyUsage CR after StoragePolicyQuota CR gets created/deleted.

Which issue this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close that issue when PR gets merged): fixes #

Testing done:

Verified StoragePolicyUsage CR for VolumeSnapshot created on assigning policy to namespace if StorageQuotaM2 FSS is enabled

root@420bc997e27955b098ab2b5241b87781 [ ~ ]# kubectl get configmaps -n vmware-system-csi csi-feature-states -o yaml
apiVersion: v1
data:
  async-query-volume: "true"
  block-volume-snapshot: "true"
  cnsmgr-suspend-create-volume: "true"
  csi-sv-feature-states-replication: "true"
  fake-attach: "true"
  file-volume: "true"
  improved-csi-idempotency: "true"
  list-volumes: "true"
  listview-tasks: "true"
  online-volume-extend: "true"
  sibling-replica-bound-pvc-check: "true"
  storage-quota-m2: "true"                                        <<<<
  tkgs-ha: "true"
  trigger-csi-fullsync: "false"
  volume-extend: "true"
  volume-health: "true"
kind: ConfigMap
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","data":{"async-query-volume":"true","block-volume-snapshot":"true","cnsmgr-suspend-create-volume":"true","csi-sv-feature-states-replication":"true","fake-attach":"true","file-volume":"true","improved-csi-idempotency":"true","list-volumes":"true","listview-tasks":"true","online-volume-extend":"true","sibling-replica-bound-pvc-check":"true","tkgs-ha":"true","trigger-csi-fullsync":"false","volume-extend":"true","volume-health":"true"},"kind":"ConfigMap","metadata":{"annotations":{},"name":"csi-feature-states","namespace":"vmware-system-csi"}}
  creationTimestamp: "2024-04-11T08:44:52Z"
  name: csi-feature-states
  namespace: vmware-system-csi
  resourceVersion: "12436299"
  uid: 3bc08c5b-c04e-49ae-abe5-b4042f7d9ea2
root@420bc997e27955b098ab2b5241b87781 [ ~ ]#

root@420bc997e27955b098ab2b5241b87781 [ ~ ]# kubectl get storagepolicyquota -n storage-policy-test
No resources found in storage-policy-test namespace.
root@420bc997e27955b098ab2b5241b87781 [ ~ ]#
root@420bc997e27955b098ab2b5241b87781 [ ~ ]#
root@420bc997e27955b098ab2b5241b87781 [ ~ ]# kubectl get storagepolicyusage -n storage-policy-test
No resources found in storage-policy-test namespace.

root@420bc997e27955b098ab2b5241b87781 [ ~ ]# ## New policy assigned to namespace
root@420bc997e27955b098ab2b5241b87781 [ ~ ]# kubectl get storagepolicyquota -n storage-policy-test
NAME                                        AGE
wcp-profile-35qriuwxd4-storagepolicyquota   18s

root@420bc997e27955b098ab2b5241b87781 [ ~ ]#
root@420bc997e27955b098ab2b5241b87781 [ ~ ]# kubectl get storagepolicyusage -n storage-policy-test
NAME                                                AGE
wcp-profile-35qriuwxd4-latebinding-pvc-usage        23s
wcp-profile-35qriuwxd4-latebinding-snapshot-usage   23s      <<< 
wcp-profile-35qriuwxd4-pvc-usage                    23s
wcp-profile-35qriuwxd4-snapshot-usage               23s               <<< snapshot storagepolicyusage created as storage-quota-m2 FSS is enabled
root@420bc997e27955b098ab2b5241b87781 [ ~ ]#

root@420bc997e27955b098ab2b5241b87781 [ ~ ]# kubectl get storagepolicyquota -n storage-policy-test  -o yaml
...
- apiVersion: cns.vmware.com/v1alpha1
  kind: StoragePolicyQuota
  metadata:
    creationTimestamp: "2024-04-24T07:44:45Z"
    generation: 1
    name: wcp-profile-35qriuwxd4-storagepolicyquota
    namespace: storage-policy-test
    resourceVersion: "12490066"
    uid: c7b29f92-d536-4dd3-8117-8710b502b9a9
  spec:
    limit: "9223372036854775807"
    storagePolicyId: 87dfdf16-b563-46b8-9ef2-383526984406
...

root@420bc997e27955b098ab2b5241b87781 [ ~ ]# kubectl get storagepolicyusage -n storage-policy-test -o yaml
...
- apiVersion: cns.vmware.com/v1alpha1
  kind: StoragePolicyUsage
  metadata:
    creationTimestamp: "2024-04-24T07:44:45Z"
    generation: 1
    name: wcp-profile-35qriuwxd4-latebinding-snapshot-usage
    namespace: storage-policy-test
    resourceVersion: "12490061"
    uid: e17b3f8d-2c14-4d52-a260-e48fec7f8999
  spec:
    resourceApiGroup: snapshot.storage.k8s.io
    resourceExtensionName: snapshot.cns.vsphere.vmware.com
    resourceKind: VolumeSnapshot
    storageClassName: wcp-profile-35qriuwxd4-latebinding
    storagePolicyId: 87dfdf16-b563-46b8-9ef2-383526984406
  status: {}
  ....

Verified StoragePolicyUsage CR for VolumeSnapshot does not get created on assigning policy to namespace if StorageQuotaM2 FSS is disabled.

root@420bc997e27955b098ab2b5241b87781 [ ~ ]# kubectl get configmaps -n vmware-system-csi csi-feature-states -o yaml
apiVersion: v1
data:
  async-query-volume: "true"
  block-volume-snapshot: "true"
  cnsmgr-suspend-create-volume: "true"
  csi-sv-feature-states-replication: "true"
  fake-attach: "true"
  file-volume: "true"
  improved-csi-idempotency: "true"
  list-volumes: "true"
  listview-tasks: "true"
  online-volume-extend: "true"
  sibling-replica-bound-pvc-check: "true"
  storage-quota-m2: "false"                                <<<
  tkgs-ha: "true"
  trigger-csi-fullsync: "false"
  volume-extend: "true"
  volume-health: "true"
kind: ConfigMap
metadata:
  annotations:
    kubectl.kubernetes.io/last-applied-configuration: |
      {"apiVersion":"v1","data":{"async-query-volume":"true","block-volume-snapshot":"true","cnsmgr-suspend-create-volume":"true","csi-sv-feature-states-replication":"true","fake-attach":"true","file-volume":"true","improved-csi-idempotency":"true","list-volumes":"true","listview-tasks":"true","online-volume-extend":"true","sibling-replica-bound-pvc-check":"true","tkgs-ha":"true","trigger-csi-fullsync":"false","volume-extend":"true","volume-health":"true"},"kind":"ConfigMap","metadata":{"annotations":{},"name":"csi-feature-states","namespace":"vmware-system-csi"}}
  creationTimestamp: "2024-04-11T08:44:52Z"
  name: csi-feature-states
  namespace: vmware-system-csi
  resourceVersion: "12491428"
  uid: 3bc08c5b-c04e-49ae-abe5-b4042f7d9ea2
root@420bc997e27955b098ab2b5241b87781 [ ~ ]#

root@420bc997e27955b098ab2b5241b87781 [ ~ ]# kubectl get storagepolicyquota -n storage-policy-test
NAME                                        AGE
wcp-profile-35qriuwxd4-storagepolicyquota   26s
root@420bc997e27955b098ab2b5241b87781 [ ~ ]#
root@420bc997e27955b098ab2b5241b87781 [ ~ ]#
root@420bc997e27955b098ab2b5241b87781 [ ~ ]# kubectl get storagepolicyusage -n storage-policy-test
NAME                                           AGE
wcp-profile-35qriuwxd4-latebinding-pvc-usage   32s
wcp-profile-35qriuwxd4-pvc-usage               32s                    <<< no snapshot storagepolicyusage created as storage-quota-m2 FSS is disabled
root@420bc997e27955b098ab2b5241b87781 [ ~ ]#

Special notes for your reviewer:

Release note:

akankshapanse commented 5 months ago

WCP precheck-in pipeline result with StorageQuotaM2 FSS disabled:

PR 2866
Ran 13 of 848 Specs in 2460.365 seconds
SUCCESS! -- 13 Passed | 0 Failed | 0 Pending | 835 Skipped
PASS Ginkgo ran 1 suite in 42m4.560294692s
Test Suite Passed make: Leaving directory `/home/worker/workspace/csi-wcp-precheckin/Results/1400/vsphere-csi-driver'
akankshapanse commented 5 months ago

WCP precheck-in pipeline result with StorageQuotaM2 FSS enabled:

PR 2866
Ran 13 of 848 Specs in 2571.066 seconds 
SUCCESS! -- 13 Passed | 0 Failed | 0 Pending | 835 Skipped
PASS Ginkgo ran 1 suite in 44m12.552365877s 
Test Suite Passed 
make: Leaving directory `/home/worker/workspace/csi-wcp-precheckin/Results/1401/vsphere-csi-driver'
xing-yang commented 5 months ago

/approve

deepakkinni commented 5 months ago

/ok-to-test

deepakkinni commented 5 months ago

/approve /lgtm

k8s-ci-robot commented 5 months ago

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: akankshapanse, deepakkinni, xing-yang

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

The pull request process is described here

Needs approval from an approver in each of these files: - ~~[OWNERS](https://github.com/kubernetes-sigs/vsphere-csi-driver/blob/master/OWNERS)~~ [deepakkinni,xing-yang] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment