-
Notifications
You must be signed in to change notification settings - Fork 829
Adding Proper Handling of VAC and Controller Tags On Volume Creation #2470
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -213,7 +213,7 @@ func (d *ControllerService) CreateVolume(ctx context.Context, req *csi.CreateVol | |||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
modifyOptions, err := parseModifyVolumeParameters(req.GetMutableParameters()) | ||||||||||||||||||||||||||
modifyOptions, err := parseCreateRequestMutableParameters(req.GetMutableParameters(), d.options.ExtraTags, *tProps) | ||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||
return nil, status.Errorf(codes.InvalidArgument, "Invalid mutable parameter: %v", err) | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
@@ -301,9 +301,6 @@ func (d *ControllerService) CreateVolume(ctx context.Context, req *csi.CreateVol | |||||||||||||||||||||||||
volumeTags[NameTag] = d.options.KubernetesClusterID + "-dynamic-" + volName | ||||||||||||||||||||||||||
volumeTags[KubernetesClusterTag] = d.options.KubernetesClusterID | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
for k, v := range d.options.ExtraTags { | ||||||||||||||||||||||||||
volumeTags[k] = v | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
addTags, err := template.Evaluate(scTags, tProps, d.options.WarnOnInvalidTag) | ||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||
|
@@ -318,6 +315,10 @@ func (d *ControllerService) CreateVolume(ctx context.Context, req *csi.CreateVol | |||||||||||||||||||||||||
volumeTags[k] = v | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
for k, v := range modifyOptions.modifyTagsOptions.TagsToAdd { | ||||||||||||||||||||||||||
volumeTags[k] = v | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
opts := &cloud.DiskOptions{ | ||||||||||||||||||||||||||
CapacityBytes: volSizeBytes, | ||||||||||||||||||||||||||
Tags: volumeTags, | ||||||||||||||||||||||||||
|
@@ -352,6 +353,63 @@ func (d *ControllerService) CreateVolume(ctx context.Context, req *csi.CreateVol | |||||||||||||||||||||||||
return newCreateVolumeResponse(disk, responseCtx), nil | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
func parseCreateRequestMutableParameters(params map[string]string, extraTags map[string]string, tProps template.PVProps) (*modifyVolumeRequest, error) { | ||||||||||||||||||||||||||
options := modifyVolumeRequest{ | ||||||||||||||||||||||||||
modifyTagsOptions: cloud.ModifyTagsOptions{ | ||||||||||||||||||||||||||
TagsToAdd: make(map[string]string), | ||||||||||||||||||||||||||
TagsToDelete: make([]string, 0), | ||||||||||||||||||||||||||
}, | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
rawTagsToAdd := []string{} | ||||||||||||||||||||||||||
for key, value := range params { | ||||||||||||||||||||||||||
switch key { | ||||||||||||||||||||||||||
case ModificationKeyIOPS: | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit worried at the amount code duplication we have for validating parameters that can be specified in either the SC versus mutable_parameters from VAC. Can we consolidate the logic? Before this PR there are 2 separate functions that validate parameters shared between SC and VAC like IOPS:
This PR adds a third place we copy paste same exact code. (Which means there are three separate places to forget about when dealing with new parameters) One possible solution for the create path would be to overwrite SC parameters with values from VAC mutable_parameters BEFORE validating them. They share the same parameter key anyway, and can be validated within the existing loop + switch statement. This is in line with CSI Spec:
Alternatively we can refactor the switch statement + for loop into a shared validate function used in Create and Modify paths. |
||||||||||||||||||||||||||
iops, err := strconv.ParseInt(value, 10, 32) | ||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||
return nil, status.Errorf(codes.InvalidArgument, "Could not parse IOPS: %q", value) | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
options.modifyDiskOptions.IOPS = int32(iops) | ||||||||||||||||||||||||||
case ModificationKeyThroughput: | ||||||||||||||||||||||||||
throughput, err := strconv.ParseInt(value, 10, 32) | ||||||||||||||||||||||||||
if err != nil { | ||||||||||||||||||||||||||
return nil, status.Errorf(codes.InvalidArgument, "Could not parse throughput: %q", value) | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
options.modifyDiskOptions.Throughput = int32(throughput) | ||||||||||||||||||||||||||
case DeprecatedModificationKeyVolumeType: | ||||||||||||||||||||||||||
if _, ok := params[ModificationKeyVolumeType]; ok { | ||||||||||||||||||||||||||
klog.Infof("Ignoring deprecated key `volumeType` because preferred key `type` is present") | ||||||||||||||||||||||||||
continue | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
klog.InfoS("Key `volumeType` is deprecated, please use `type` instead") | ||||||||||||||||||||||||||
options.modifyDiskOptions.VolumeType = value | ||||||||||||||||||||||||||
case ModificationKeyVolumeType: | ||||||||||||||||||||||||||
options.modifyDiskOptions.VolumeType = value | ||||||||||||||||||||||||||
default: | ||||||||||||||||||||||||||
switch { | ||||||||||||||||||||||||||
case strings.HasPrefix(key, ModificationAddTag): | ||||||||||||||||||||||||||
rawTagsToAdd = append(rawTagsToAdd, value) | ||||||||||||||||||||||||||
default: | ||||||||||||||||||||||||||
return nil, status.Errorf(codes.InvalidArgument, "Invalid mutable parameter key: %s", key) | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
for k, v := range extraTags { | ||||||||||||||||||||||||||
rawTagsToAdd = append(rawTagsToAdd, k+"="+v) | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
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 | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. General comment: Should we add a unit test that ensures all tags get evaluated for string interpolation to prevent regressions? (SCTags, VACTags, and Extra tags can be tested in the same unit test) |
||||||||||||||||||||||||||
func validateCreateVolumeRequest(req *csi.CreateVolumeRequest) error { | ||||||||||||||||||||||||||
volName := req.GetName() | ||||||||||||||||||||||||||
if len(volName) == 0 { | ||||||||||||||||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason why VAC and 'extra' tags being evaluated and validated separately from SCTags? (But lines 402-409 are duplicate of 308-315?)
A smell here is that tags specified via extra-tags option would wind up in the unrelated struct
modifyOptions.modifyTagOptions.TagsToAdd
.Have you considered instead:
tagsToEvaluate
template.Evaluate
andvalidateExtraTags
That way all tags, no matter their source, go through a clear set of steps? Bonus points if these steps are located near each other so it's easy to see how all tags are processed.