Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snapshot tagging via VolumeSnapshotClass with string interpolation #1553

Closed
hanyuel opened this issue Mar 30, 2023 · 3 comments
Closed

Snapshot tagging via VolumeSnapshotClass with string interpolation #1553

hanyuel opened this issue Mar 30, 2023 · 3 comments
Assignees

Comments

@hanyuel
Copy link
Contributor

hanyuel commented Mar 30, 2023

Is your feature request related to a problem? Please describe.
Currently, EBS CSI Driver supports snapshot tagging via VolumeSnapshotClass.parameters. If you declare VolumeSnapshotClass with parameters using tagSpecification prefix like this

apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshotClass
metadata:
  name: csi-aws-vsc
driver: ebs.csi.aws.com
deletionPolicy: Delete
parameters:
  tagSpecification_1: "key1=value1"

The CSI Driver will add the key-value pair "key1=value1" as tag to the snapshot created using this VolumeSnapshotClass.

This "static" tagging has its limitations. For example, all snapshots created using the same VolumeSnapshotClass will have the same tags (from VolumeSnapshotClass.parameters).
Users have also expressed interests in adding tags from the snapshot-level such as snapshot name&namespace to EBS snapshots.

Describe the solution you'd like in detail
The CSI external-snapshotter (when the --extra-create-metadata flag set) exposes these parameters, snapshot name, namespace and VolumeSnapshotContent name to the CSI Driver, in CreateSnapshotRequest:

  • csi.storage.k8s.io/volumesnapshot/name
  • csi.storage.k8s.io/volumesnapshot/namespace
  • csi.storage.k8s.io/volumesnapshotcontent/name

These parameters are dynamically generated at runtime. Reference: https://kubernetes-csi.github.io/docs/external-snapshotter.html#volumesnapshot-and-volumesnapshotcontent-parameters

We will implement the support in CSI Driver to allow these VolumeSnapshot and VolumeSnapshotContent parameters to be added to snapshot tags, with runtime string interpolation , in a similar way to StorageClass tagging.

Example 1

apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshotClass
metadata:
  name: csi-aws-vsc
driver: ebs.csi.aws.com
deletionPolicy: Delete
parameters:
  tagSpecification_1: "key1={{ .VolumeSnapshotNamespace }}"
  tagSpecification_2: "key2={{ .VolumeSnapshotName }}"
  tagSpecification_3: "key3={{ .VolumeSnapshotContentName }}"

Create a snapshot with "default" namespace and "ebs-vs" name and from VolumeSnapshotContent name "ebs-vsc". The snapshot will have these tags

key1=default
key2=ebs-vs
key3=ebs-vsc

Example 2
More expressive tags w/ certain string interpolation functions:

apiVersion: snapshot.storage.k8s.io/v1
kind: VolumeSnapshotClass
metadata:
  name: csi-aws-vsc
driver: ebs.csi.aws.com
deletionPolicy: Delete
parameters:
  tagSpecification_1: "key1={{ .VolumeSnapshotNamespace | contains "prod" }}"
  tagSpecification_2: "key2={{ .VolumeSnapshotNamespace | field "-" 2 | toUpper }}"

If the VolumeSnapshot namespace is "prod-na-test", the snapshot will have these 2 tags:

key1=true
key2=TEST

Describe alternatives you've considered
None.

Additional context
Related issue: #1261 #1453

@hanyuel
Copy link
Contributor Author

hanyuel commented Mar 30, 2023

/assign

@torredil
Copy link
Member

/close

@k8s-ci-robot
Copy link
Contributor

@torredil: Closing this issue.

In response to this:

/close

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/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants