red888
red888

Reputation: 31550

How do I propagate resource labels to my GKE application's GCE disks backing its PVCs?

I use the standard-rwo storage class for persistent and ephemeral volumes for my applications. So there are GCE disks backing my k8s volumes. I want to do cost allocation of these and track the storage usage of my GKE applications using these volumes, but I cannot figure out how to propagate resource labels to them.

For example:

  volumes:
    - name: scratch-volume
      ephemeral:
        volumeClaimTemplate:
          metadata:
            # Apply these labels to the GCE disk
            labels:
              app: my-app-name
          spec:
            accessModes: [ "ReadWriteOnce" ]
            storageClassName: "standard-rwo"
            resources:
              requests:
                storage: 1Gi

The only label I see on the actual GCE disks is goog-gke-volume.

I'm having trouble finding docs saying this is or is not supported. The docs for the driver make zero mention of this, not even to say if it's supported by any means or not: https://cloud.google.com/kubernetes-engine/docs/how-to/persistent-volumes/gce-pd-csi-driver

Edit

Per answer this is the related Github Issue.

I asked about this and a contributor explained where this feature would need to be implemented.

The issue was raised on the external-provisioner, as that would be the right kubernetes layer to do this (the pd csi driver doesn't see the k8s objects so can't see annotations).

kubernetes-csi/external-provisioner#760.

Looks like it got auto-closed but I'm sure if you're interested in working on it it could be re-opened.

Upvotes: 0

Views: 527

Answers (2)

Ivan Ruski
Ivan Ruski

Reputation: 1270

You can create another storage class which will attach labels of your choice to each disk.

Copy the standard-rwo definition and create a new one like this:

allowVolumeExpansion: true
apiVersion: storage.k8s.io/v1
kind: StorageClass
metadata:
  name: standard-rwo-with-labels
parameters:
  type: pd-balanced
  labels: app=my-app <---- this is the new thing
provisioner: pd.csi.storage.gke.io
reclaimPolicy: Delete
volumeBindingMode: WaitForFirstConsumer

According to this documentation, you can add multiple labels, separating them with comma e.g. key1=value1,key2=value2

Upvotes: 0

boredabdel
boredabdel

Reputation: 2130

Unfortunately that's not supported by the driver. There is an issue open with the driver to support this https://github.com/kubernetes-sigs/gcp-compute-persistent-disk-csi-driver/issues/1018

Upvotes: 1

Related Questions