Skip to content

Commit 8814261

Browse files
authored
Supporting String Interpolation for Modifying Tags On Existing Volumes Through VAC (#2093)
* Supporting String Interpolation for Modifying Tags On Existing Volumes Through VAC * Bumped external resizer version * Bumped eks-distro versions to 1.32 * oc update + Making --extra-modify-metadata flag default * Ran make update * Removed extra parameter + Addressed doc feedback
1 parent 4f4c7b7 commit 8814261

File tree

8 files changed

+62
-15
lines changed

8 files changed

+62
-15
lines changed

charts/aws-ebs-csi-driver/templates/controller.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,9 @@ spec:
429429
{{- if not (regexMatch "(-timeout)" (join " " .Values.sidecars.resizer.additionalArgs)) }}
430430
- --timeout=60s
431431
{{- end }}
432+
{{- if .Values.controller.extraCreateMetadata }}
433+
- --extra-modify-metadata
434+
{{- end}}
432435
- --csi-address=$(ADDRESS)
433436
- --v={{ .Values.sidecars.resizer.logLevel }}
434437
- --handle-volume-inuse-error=false

charts/aws-ebs-csi-driver/values.schema.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@
258258
},
259259
"extraCreateMetadata": {
260260
"type": "boolean",
261-
"description": "If set, add pv/pvc metadata to plugin create requests as parameters.",
261+
"description": "If set, add pv/pvc metadata to plugin create and modify requests as parameters.",
262262
"default": true
263263
},
264264
"k8sTagClusterId": {

charts/aws-ebs-csi-driver/values.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ sidecars:
106106
image:
107107
pullPolicy: IfNotPresent
108108
repository: public.ecr.aws/eks-distro/kubernetes-csi/external-resizer
109-
tag: "v1.12.0-eks-1-31-11"
109+
tag: "v1.13.1-eks-1-32-5"
110110
# Tune leader lease election for csi-resizer.
111111
# Leader election is on by default.
112112
leaderElection:
@@ -220,7 +220,7 @@ controller:
220220
env: []
221221
# Use envFrom to reference ConfigMaps and Secrets across all containers in the deployment
222222
envFrom: []
223-
# If set, add pv/pvc metadata to plugin create requests as parameters.
223+
# If set, add pv/pvc metadata to plugin create and modify requests as parameters.
224224
extraCreateMetadata: true
225225
# Extra volume tags to attach to each dynamically provisioned volume.
226226
# ---

deploy/kubernetes/base/controller.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,11 @@ spec:
224224
seccompProfile:
225225
type: RuntimeDefault
226226
- name: csi-resizer
227-
image: public.ecr.aws/eks-distro/kubernetes-csi/external-resizer:v1.12.0-eks-1-31-11
227+
image: public.ecr.aws/eks-distro/kubernetes-csi/external-resizer:v1.13.1-eks-1-32-5
228228
imagePullPolicy: IfNotPresent
229229
args:
230230
- --timeout=60s
231+
- --extra-modify-metadata
231232
- --csi-address=$(ADDRESS)
232233
- --v=2
233234
- --handle-volume-inuse-error=false

deploy/kubernetes/overlays/stable/gcr/kustomization.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ images:
1919
newTag: v8.2.0
2020
- name: public.ecr.aws/eks-distro/kubernetes-csi/external-resizer
2121
newName: registry.k8s.io/sig-storage/csi-resizer
22-
newTag: v1.12.0
22+
newTag: v1.13.1
2323
- name: public.ecr.aws/eks-distro/kubernetes-csi/node-driver-registrar
2424
newName: registry.k8s.io/sig-storage/csi-node-driver-registrar
2525
newTag: v2.13.0

docs/tagging.md

+27-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ To help manage volumes in the aws account, CSI driver will automatically add tag
1111

1212
# StorageClass Tagging
1313

14-
The AWS EBS CSI Driver supports tagging through `StorageClass.parameters` (in v1.6.0 and later).
14+
The AWS EBS CSI Driver supports tagging through `StorageClass.parameters`.
1515

1616
If a key has the prefix `tagSpecification`, the CSI driver will treat the value as a key-value pair to be applied to the dynamically provisioned volume as tags.
1717

@@ -97,8 +97,26 @@ billingID=ABCDEF
9797
```
9898

9999
# Adding, Modifying, and Deleting Tags Of Existing Volumes
100-
The AWS EBS CSI Driver supports the modifying of tags of existing volumes through `VolumeAttributesClass.parameters` the examples below show the syntax for addition, modification, and deletion of tags within the `VolumeAttributesClass.parameters`. For a walkthrough on how to apply these modifications to a volume follow the [walkthrough for Volume Modification via VolumeAttributeClass](../examples/kubernetes/modify-volume)
101-
100+
The AWS EBS CSI Driver supports the modifying of tags of existing volumes through `VolumeAttributesClass.parameters` the examples below show the syntax for addition, modification, and deletion of tags within the `VolumeAttributesClass.parameters`. The driver also supports runtime string interpolation on tag values for a volume upon modification, which allows the specification of placeholder values for the PVC namespace, PVC name, and PV name, which will then be dynamically computed at runtime.
101+
102+
**Note: Interpolated tags require the `--extra-modify-metadata` flag to be enabled on the `external-resizer` sidecar. To modify Amazon EBS resource tags through VACs, ensure that you attach the following IAM Policy to the role used by your Amazon EBS CSI driver:**
103+
```
104+
{
105+
"Version": "2012-10-17",
106+
"Statement": [
107+
{
108+
"Effect": "Allow",
109+
"Action": [
110+
"ec2:CreateTags"
111+
],
112+
"Resource": [
113+
"arn:aws:ec2:*:*:volume/*",
114+
"arn:aws:ec2:*:*:snapshot/*"
115+
]
116+
}
117+
]
118+
}
119+
```
102120
**Syntax for Adding or Modifying a Tag**
103121

104122
If a key has the prefix `tagSpecification`, the CSI driver will treat the value as a key-value pair to be added to the existing volume. If there is already an existing tag with the specified key, the CSI driver will overwrite the value of that tag with the new value specified.
@@ -111,6 +129,12 @@ driverName: ebs.csi.aws.com
111129
parameters:
112130
tagSpecification_1: "location=Seattle"
113131
tagSpecification_2: "cost-center=" // If the value is left blank, tag is created with an empty value
132+
# Interpolated tag
133+
tagSpecification_3: "PVC-Name={{ .PVCName }}"
134+
tagSpecification_4: "PVC-Namespace={{ .PVCNamespace }}"
135+
tagSpecification_5: "PV-Name={{ .PVName }}"
136+
# Interpolated tag w/ function
137+
tagSpecification_6: 'key6={{ .PVCNamespace | contains "prod" }}'
114138
```
115139
**Syntax for Deleting a Tag**
116140

pkg/driver/controller_modify_volume.go

+16-6
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/awslabs/volume-modifier-for-k8s/pkg/rpc"
2929
"github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/cloud"
3030
"github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/coalescer"
31+
"github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/util/template"
3132
"google.golang.org/grpc/codes"
3233
"google.golang.org/grpc/status"
3334
"k8s.io/klog/v2"
@@ -170,6 +171,8 @@ func parseModifyVolumeParameters(params map[string]string) (*modifyVolumeRequest
170171
TagsToDelete: make([]string, 0),
171172
},
172173
}
174+
var rawTagsToAdd []string
175+
tProps := new(template.PVProps)
173176
for key, value := range params {
174177
switch key {
175178
case ModificationKeyIOPS:
@@ -193,23 +196,30 @@ func parseModifyVolumeParameters(params map[string]string) (*modifyVolumeRequest
193196
options.modifyDiskOptions.VolumeType = value
194197
case ModificationKeyVolumeType:
195198
options.modifyDiskOptions.VolumeType = value
199+
case PVCNameKey:
200+
tProps.PVCName = value
201+
case PVCNamespaceKey:
202+
tProps.PVCNamespace = value
203+
case PVNameKey:
204+
tProps.PVName = value
196205
default:
197206
switch {
198207
case strings.HasPrefix(key, ModificationAddTag):
199-
st := strings.SplitN(value, "=", 2)
200-
if len(st) < 2 {
201-
return nil, status.Errorf(codes.InvalidArgument, "Invalid tag specification: %v", st)
202-
}
203-
options.modifyTagsOptions.TagsToAdd[st[0]] = st[1]
208+
rawTagsToAdd = append(rawTagsToAdd, value)
204209
case strings.HasPrefix(key, ModificationDeleteTag):
205210
options.modifyTagsOptions.TagsToDelete = append(options.modifyTagsOptions.TagsToDelete, value)
206211
default:
207212
return nil, status.Errorf(codes.InvalidArgument, "Invalid mutable parameter key: %s", key)
208213
}
209214
}
210215
}
211-
if err := validateExtraTags(options.modifyTagsOptions.TagsToAdd, false); err != nil {
216+
addTags, err := template.Evaluate(rawTagsToAdd, tProps, false)
217+
if err != nil {
218+
return nil, status.Errorf(codes.InvalidArgument, "Error interpolating the tag value: %v", err)
219+
}
220+
if err := validateExtraTags(addTags, false); err != nil {
212221
return nil, status.Errorf(codes.InvalidArgument, "Invalid tag value: %v", err)
213222
}
223+
options.modifyTagsOptions.TagsToAdd = addTags
214224
return &options, nil
215225
}

pkg/driver/controller_modify_volume_test.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,14 @@ func TestParseModifyVolumeParameters(t *testing.T) {
154154
ModificationKeyVolumeType: validType,
155155
ModificationKeyIOPS: validIops,
156156
ModificationKeyThroughput: validThroughput,
157-
ModificationAddTag: validTagSpecificationInput,
157+
ModificationAddTag + "_1": validTagSpecificationInput,
158+
ModificationAddTag + "_2": "key2={{ .PVCName }}",
159+
ModificationAddTag + "_3": "key3={{ .PVCNamespace }}",
160+
ModificationAddTag + "_4": "key4={{ .PVName }}",
158161
ModificationDeleteTag: validTagDeletion,
162+
PVCNameKey: "ebs-claim",
163+
PVCNamespaceKey: "test-namespace",
164+
PVNameKey: "testPV-Name",
159165
},
160166
expectedOptions: &modifyVolumeRequest{
161167
modifyDiskOptions: cloud.ModifyDiskOptions{
@@ -166,6 +172,9 @@ func TestParseModifyVolumeParameters(t *testing.T) {
166172
modifyTagsOptions: cloud.ModifyTagsOptions{
167173
TagsToAdd: map[string]string{
168174
"key1": "tag1",
175+
"key2": "ebs-claim",
176+
"key3": "test-namespace",
177+
"key4": "testPV-Name",
169178
},
170179
TagsToDelete: []string{
171180
"key2",

0 commit comments

Comments
 (0)