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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -168,6 +169,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 @@ -191,22 +194,29 @@ 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:
if 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)
} else if strings.HasPrefix(key, ModificationDeleteTag) {
options.modifyTagsOptions.TagsToDelete = append(options.modifyTagsOptions.TagsToDelete, value)
} else {
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