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
293 stars 177 forks source link

Implement event handler for case when CnsVolumeInfo CR is updated #2961

Closed vdkotkar closed 1 month ago

vdkotkar commented 1 month ago

What this PR does / why we need it: This PR takes care of following changes:

  1. Take following actions when CnsVolumeInfo CR is updated - Update the VolumeSnapshot StoragePolicyUsage CR in the following ways: i. Update “Used” based on the previous and current CnsVolumeInfo ii. Add annotation “csi.vsphere.missing-snapshot-aggregated-capacity: true” if there is no valid aggregated snapshot size.

  2. Mixed host reconciliation logic related to storage quota feature is moved from CSI layer to CNS layer, hence there is no need to watch on AvailabilityZone CRs. Removed relevant code from syncer.

  3. Added go.mod and go.sum changes generated after running go mod tidy

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: Initial StoragePolicyUsage CR for Snapshot:

# k describe storagepolicyusages.cns.vmware.com wcpglobal-storage-profile-snapshot-usage -n test-ns-1
Name:         wcpglobal-storage-profile-snapshot-usage
Namespace:    test-ns-1
Labels:       <none>
Annotations:  <none>
API Version:  cns.vmware.com/v1alpha2
Kind:         StoragePolicyUsage
Metadata:
  Creation Timestamp:  2024-07-16T08:47:02Z
  Generation:          2
  Resource Version:    3691983
  UID:                 6ef9207c-766a-4dd8-8b7a-7498410a84f0
Spec:
  Resource API Group:       snapshot.storage.k8s.io
  Resource Extension Name:  snapshot.cns.vsphere.vmware.com
  Resource Kind:            VolumeSnapshot
  Storage Class Name:       wcpglobal-storage-profile
  Storage Policy Id:        dab83433-db12-4740-b326-24847a9ff0b2
Status:
  Quota Usage:
    Used:  10Mi
Events:    <none>

Manually updated CnsVolumeInfo, increased aggregatedsnapshotsize by 20Mi.

Updated StoragePolicyUsage CR for Snapshot:

# k describe storagepolicyusages.cns.vmware.com wcpglobal-storage-profile-snapshot-usage -n test-ns-1
Name:         wcpglobal-storage-profile-snapshot-usage
Namespace:    test-ns-1
...
Status:
  Quota Usage:
    Used:  30Mi    <<< increased by 20Mi
Events:    <none>

Manually updated CnsVolumeInfo, decreased aggregatedsnapshotsize by 5Mi.

Updated StoragePolicyUsage CR for Snapshot:

# k describe storagepolicyusages.cns.vmware.com wcpglobal-storage-profile-snapshot-usage -n test-ns-1
Name:         wcpglobal-storage-profile-snapshot-usage
Namespace:    test-ns-1
...
Status:
  Quota Usage:
    Used:  25Mi     <<< decreased by 5 Mi
Events:    <none>

Manually updated CnsVolumeInfo, changed validaggregatedsnapshotsize flag to false.

Updated StoragePolicyUsage CR for Snapshot:

# k describe storagepolicyusages.cns.vmware.com wcpglobal-storage-profile-snapshot-usage -n test-ns-1
Name:         wcpglobal-storage-profile-snapshot-usage
Namespace:    test-ns-1
Labels:       <none>
Annotations:  csi.vsphere.missing-snapshot-aggregated-capacity: true.    <<<< Annotation added
...
Status:
  Quota Usage:
    Used:  25Mi
Events:    <none>

Special notes for your reviewer:

Release note:

Implement event handler for case when CnsVolumeInfo CR is updated
k8s-ci-robot commented 1 month ago

Hi @vdkotkar. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes-sigs/prow](https://github.com/kubernetes-sigs/prow/issues/new?title=Prow%20issue:) repository.
deepakkinni commented 1 month ago

/ok-to-test

deepakkinni commented 1 month ago

/approve

xing-yang commented 1 month ago

Please rebase.

akankshapanse commented 1 month ago

/approve

deepakkinni commented 1 month ago

/approve /lgtm

k8s-ci-robot commented 1 month ago

[APPROVALNOTIFIER] This PR is APPROVED

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

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)~~ [akankshapanse,deepakkinni] Approvers can indicate their approval by writing `/approve` in a comment Approvers can cancel approval by writing `/approve cancel` in a comment