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

Supporting String Interpolation for Modifying Tags On Existing Volumes Through VAC #2093

Merged
Merged
2 changes: 1 addition & 1 deletion charts/aws-ebs-csi-driver/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ sidecars:
image:
pullPolicy: IfNotPresent
repository: public.ecr.aws/eks-distro/kubernetes-csi/external-resizer
tag: "v1.12.0-eks-1-31-11"
tag: "v1.13.1-eks-1-32-5"
# Tune leader lease election for csi-resizer.
# Leader election is on by default.
leaderElection:
Expand Down
2 changes: 1 addition & 1 deletion deploy/kubernetes/base/controller.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ spec:
seccompProfile:
type: RuntimeDefault
- name: csi-resizer
image: public.ecr.aws/eks-distro/kubernetes-csi/external-resizer:v1.12.0-eks-1-31-11
image: public.ecr.aws/eks-distro/kubernetes-csi/external-resizer:v1.13.1-eks-1-32-5
imagePullPolicy: IfNotPresent
args:
- --timeout=60s
Expand Down
2 changes: 1 addition & 1 deletion deploy/kubernetes/overlays/stable/gcr/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ images:
newTag: v8.2.0
- name: public.ecr.aws/eks-distro/kubernetes-csi/external-resizer
newName: registry.k8s.io/sig-storage/csi-resizer
newTag: v1.12.0
newTag: v1.13.1
- name: public.ecr.aws/eks-distro/kubernetes-csi/node-driver-registrar
newName: registry.k8s.io/sig-storage/csi-node-driver-registrar
newTag: v2.13.0
22 changes: 16 additions & 6 deletions pkg/driver/controller_modify_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/awslabs/volume-modifier-for-k8s/pkg/rpc"
"github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/cloud"
"github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/coalescer"
"github.com/kubernetes-sigs/aws-ebs-csi-driver/pkg/util/template"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"k8s.io/klog/v2"
Expand Down Expand Up @@ -170,6 +171,8 @@ func parseModifyVolumeParameters(params map[string]string) (*modifyVolumeRequest
TagsToDelete: make([]string, 0),
},
}
var rawTagsToAdd []string
tProps := new(template.PVProps)
for key, value := range params {
switch key {
case ModificationKeyIOPS:
Expand All @@ -193,23 +196,30 @@ func parseModifyVolumeParameters(params map[string]string) (*modifyVolumeRequest
options.modifyDiskOptions.VolumeType = value
case ModificationKeyVolumeType:
options.modifyDiskOptions.VolumeType = value
case PVCNameKey:
tProps.PVCName = value
case PVCNamespaceKey:
tProps.PVCNamespace = value
case PVNameKey:
tProps.PVName = value
default:
switch {
case strings.HasPrefix(key, ModificationAddTag):
st := strings.SplitN(value, "=", 2)
if len(st) < 2 {
return nil, status.Errorf(codes.InvalidArgument, "Invalid tag specification: %v", st)
}
options.modifyTagsOptions.TagsToAdd[st[0]] = st[1]
rawTagsToAdd = append(rawTagsToAdd, value)
case strings.HasPrefix(key, ModificationDeleteTag):
options.modifyTagsOptions.TagsToDelete = append(options.modifyTagsOptions.TagsToDelete, value)
default:
return nil, status.Errorf(codes.InvalidArgument, "Invalid mutable parameter key: %s", key)
}
}
}
if err := validateExtraTags(options.modifyTagsOptions.TagsToAdd, false); err != nil {
addTags, err := template.Evaluate(rawTagsToAdd, tProps, false)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "Error interpolating the tag value: %v", err)
}
if err := validateExtraTags(addTags, false); err != nil {
return nil, status.Errorf(codes.InvalidArgument, "Invalid tag value: %v", err)
}
options.modifyTagsOptions.TagsToAdd = addTags
return &options, nil
}
11 changes: 10 additions & 1 deletion pkg/driver/controller_modify_volume_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,14 @@ func TestParseModifyVolumeParameters(t *testing.T) {
ModificationKeyVolumeType: validType,
ModificationKeyIOPS: validIops,
ModificationKeyThroughput: validThroughput,
ModificationAddTag: validTagSpecificationInput,
ModificationAddTag + "_1": validTagSpecificationInput,
ModificationAddTag + "_2": "key2={{ .PVCName }}",
ModificationAddTag + "_3": "key3={{ .PVCNamespace }}",
ModificationAddTag + "_4": "key4={{ .PVName }}",
ModificationDeleteTag: validTagDeletion,
PVCNameKey: "ebs-claim",
PVCNamespaceKey: "test-namespace",
PVNameKey: "testPV-Name",
},
expectedOptions: &modifyVolumeRequest{
modifyDiskOptions: cloud.ModifyDiskOptions{
Expand All @@ -166,6 +172,9 @@ func TestParseModifyVolumeParameters(t *testing.T) {
modifyTagsOptions: cloud.ModifyTagsOptions{
TagsToAdd: map[string]string{
"key1": "tag1",
"key2": "ebs-claim",
"key3": "test-namespace",
"key4": "testPV-Name",
},
TagsToDelete: []string{
"key2",
Expand Down