kubernetes-csi / external-provisioner

Sidecar container that watches Kubernetes PersistentVolumeClaim objects and triggers CreateVolume/DeleteVolume against a CSI endpoint
Apache License 2.0
342 stars 332 forks source link

Add PVC Annotations + Labels to PV #760

Closed speedfl closed 1 year ago

speedfl commented 2 years ago

Problem

Correlate PV with a context is almost impossible. The only solution is to create StorageClass with Contextual Data (Cost Center / Customer / Environment) and then correlate the PV with the StorageClass. This results in a duplication of StorageClass while its purpose is the "how to store data" (Azure Disk, AWS EBS...) and not the "for who/what data are stored".

Proposal

We should have an elegant way to Add PVC / Labels annotations on PV such as Cost Center, Customer, Billing ID... https://github.com/kubernetes-csi/external-provisioner/blob/master/pkg/controller/controller.go

Possible Solution:

kind: StorageClass
apiVersion: storage.k8s.io/v1
metadata:
  name: ebs-sc
provisioner: some-provisionner
fromPVCToPV: # I am bad finding names :D 
  labels:
    - label-one
    - label-two
  annotations:
    - annotation-one
    - annotation-two
parameters:
pv := &v1.PersistentVolume{
    ObjectMeta: metav1.ObjectMeta{
        Name: pvName,
    },
    Spec: v1.PersistentVolumeSpec{
        AccessModes:  options.PVC.Spec.AccessModes,
        MountOptions: options.StorageClass.MountOptions,
        Capacity: v1.ResourceList{
            v1.ResourceName(v1.ResourceStorage): bytesToQuantity(respCap),
        },
        // TODO wait for CSI VolumeSource API
        PersistentVolumeSource: v1.PersistentVolumeSource{
            CSI: result.csiPVSource,
        },
    },
}

if options.StorageClass.fromPVCToPV != nil {
    options.StorageClass.fromPVCToPV.Annotations != nil {
        for _, key := range options.StorageClass.fromPVCToPV.Annotations {

            if options.PVC.ObjectMeta.Annotations != nil && val, ok := appSet.ObjectMeta.Annotations[key]; ok {
                metav1.SetMetaDataAnnotation(&pv.ObjectMeta, key, val)
            }
        }
    }
   // same for labels
}

Other

There is another issue to forward the Annotations/Labels to CreateVolumeRequest which goes in this direction: https://github.com/kubernetes-csi/external-provisioner/issues/86

k8s-triage-robot commented 2 years ago

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot commented 1 year ago

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

k8s-triage-robot commented 1 year ago

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

k8s-ci-robot commented 1 year ago

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to [this](https://github.com/kubernetes-csi/external-provisioner/issues/760#issuecomment-1364694476): >The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs. > >This bot triages issues according to the following rules: >- After 90d of inactivity, `lifecycle/stale` is applied >- After 30d of inactivity since `lifecycle/stale` was applied, `lifecycle/rotten` is applied >- After 30d of inactivity since `lifecycle/rotten` was applied, the issue is closed > >You can: >- Reopen this issue with `/reopen` >- Mark this issue as fresh with `/remove-lifecycle rotten` >- Offer to help out with [Issue Triage][1] > >Please send feedback to sig-contributor-experience at [kubernetes/community](https://github.com/kubernetes/community). > >/close not-planned > >[1]: https://www.kubernetes.dev/docs/guide/issue-triage/ 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/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
chr0n1x commented 3 months ago

@speedfl sorry for the necro-bump. Was there a reason the code snippet you proposed not in the form of a PR? asking because Im unaware of anyone else that has worked on this.

nick4fake commented 3 months ago

Same question, as I've assumed this being quite basic functionality

SCLogo commented 1 month ago

It would be a good idea. e.g. can exclude pv-s from backup using label.