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

Allow using escaped commas in tag values #1810

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

RomanBednar
Copy link
Contributor

@RomanBednar RomanBednar commented Aug 19, 2024

What type of PR is this?

/kind bug

What this PR does / why we need it:

Allows using commas in tag values; commas are allowed according to documentation.

Which issue(s) this PR fixes:

Fixes #1809

Special notes for your reviewer:

Tested with unit tests and manually as shown below:

Escaped commas with a backslash (\):

$ oc -n openshift-cluster-csi-drivers get deployment.apps/gcp-pd-csi-driver-controller -o json | jq '.spec.template.spec.containers[0].args[-1]'
"--extra-tags=openshift-gce-devel/rbednar-test-tag1/rbednar-test-value1,openshift-gce-devel/rbednar-test-tag2/value\\,with\\,comma"

CSI Driver created volume successfully:

I0819 13:12:36.831245       1 utils.go:69] /csi.v1.Controller/CreateVolume called with request: name:"pvc-6c6a18fc-e37e-4cae-8f7b-63042bbfc664" capacity_range:<required_bytes:2147483648 > volume_capabilities:<mount:<fs_type:"ext4" > access_mode:<mode:SINGLE_NODE_WRITER > > parameters:<key:"csi.storage.k8s.io/pv/name" value:"pvc-6c6a18fc-e37e-4cae-8f7b-63042bbfc664" > parameters:<key:"csi.storage.k8s.io/pvc/name" value:"pvc-2" > parameters:<key:"csi.storage.k8s.io/pvc/namespace" value:"default" > parameters:<key:"replication-type" value:"none" > parameters:<key:"type" value:"pd-standard" > accessibility_requirements:<requisite:<segments:<key:"topology.gke.io/zone" value:"us-central1-a" > > requisite:<segments:<key:"topology.gke.io/zone" value:"us-central1-b" > > requisite:<segments:<key:"topology.gke.io/zone" value:"us-central1-c" > > preferred:<segments:<key:"topology.gke.io/zone" value:"us-central1-c" > > preferred:<segments:<key:"topology.gke.io/zone" value:"us-central1-a" > > preferred:<segments:<key:"topology.gke.io/zone" value:"us-central1-b" > > >
...
I0819 13:12:40.728527       1 controller.go:715] CreateVolume succeeded for disk Key{"pvc-6c6a18fc-e37e-4cae-8f7b-63042bbfc664", zone: "us-central1-c"}

Tag has been added correctly to provisioned disk:

Screenshot 2024-08-19 at 15 32 09

Does this PR introduce a user-facing change?:

Driver now allows users to include commas (,) in tag values. If used, commas must be escaped with a backslash (\).

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/bug Categorizes issue or PR as related to a bug. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 19, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: RomanBednar
Once this PR has been reviewed and has the lgtm label, please assign leiyiz for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

for _, r := range s {
switch {
case escaped:
if r == delim {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we just do
case escaped:
if r != escape {
buf.WriteRune(r)
escaped = false
}

I think the current code will do the wrong thing on foo,,bar.

also I think both versions of the code do the wrong thing on foo\,bar, usually that would escape the backslash and not escape the comma, but here this is turned into an escaped comma?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattcary You're right, it can be simplified as suggested. As for the behavior of escaping, what do you think the correct behavior should be? Or which unit test is wrong specifically?

In case of foo,,bar input splitWithEscape will output "foo", "", "bar" which will later fail validation as it's not a valid format for a tag here:

return nil, fmt.Errorf("tag %q is invalid, correct format: 'parent_id1/key1/value1,parent_id2/key2/value2'", parentIDkeyValueString)

here this is turned into an escaped comma?

I think you could say that, it's actually the intention of this change to allow users escaping the commas somehow so they can be used in tag value (as documented). Maybe there's a better solution?

@RomanBednar RomanBednar changed the title Allow using escaped comas in tag values Allow using escaped commas in tag values Sep 23, 2024
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Dec 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

driver can not parse tag values containing a coma
4 participants