carvel-dev / carvel-dev/ytt

Provide way to escape "." in key name when using --data-value options.

Open
#671 1 comment 2 reactions 0 assignees View on GitHub
breaking change carvel accepted enhancement priority/important-longterm
Dominant language
Go
Stars
1.9k
Forks
167
PR merge metrics
No merged PRs in 30d

Description

**Describe the problem/challenge you have**

I want to use `--data-value` to set a key where the key name includes a ".".

Trying with various possible conventions used by other tools there currently appears to be no way of doing this:

```
~$ ytt -v 'data."file.yaml"=a:b' --data-values-inspect
data:
'"file':
yaml": a:b

~$ ytt -v 'data["file.yaml"]=a:b' --data-values-inspect
data["file:
yaml"]: a:b

~$ ytt -v 'data['file.yaml']=a:b' --data-values-inspect
data[file:
yaml]: a:b

~$ ytt -v "data.file\.yaml=a:b" --data-values-inspect
data:
file\:
yaml: a:b
```

This means that if a data value schema uses a "." in a key name, eg. "file.yaml", "tls.crt" or "tls.key", there is no way to set it from the command line and one has to use a data values file as input.

Note that I know you can do something like:

```
~$ ytt --data-value-yaml 'data={"file.yaml":"a:b"}' --data-values-inspect
data:
file.yaml: a:b
```

But this only helps in case where can set the whole of `data` in one go. It doesn't help if a schema or default values already had data with other key/values in it, as setting like this would overwrite everything.

```
~$ ytt -v data.key=1 --data-value-yaml 'data={"file.yaml":"a:b"}' --data-values-inspect
data:
file.yaml: a:b
```

So it has to be additive to what exists already.

**Describe the solution you'd like**

The `yq` tool provides one example of an escaping mechanism which could be used:

```
echo 'a:
b.c: 2' | yq e '.a."b.c"' -
```

If adopted this convention then would expect:

```
~$ ytt -v 'data."file.yaml"=a:b' --data-values-inspect
data:
file.yaml: a:b
```

In implementing this approach one would have to consider the likelihood that anyone is already using double quotes in a key name such that using the escaping mechanism as the default would change how it works for those existing users. A gut feel says it would be unlikely anyone was using quotes in key names as it would be an anti pattern for YAML in general, especially not when using `ytt` `--data-value` options via the command line.

**Anything else you would like to add:**

@jtigger on Slack (in [the #carvel channel](https://kubernetes.slack.com/archives/CH8KCCKA5/p1652490778676379)) pointed at the following relevant code where changes would be required.

* https://github.com/vmware-tanzu/carvel-ytt/blob/develop/pkg/cmd/template/data_values_flags.go#L251
* https://github.com/vmware-tanzu/carvel-ytt/blob/develop/pkg/cmd/template/data_values_flags.go#L280

---

_(this next section added by @pivotaljohn)_

### Implementation Notes

When we pick this work up:
1. be consistent within Carvel: just like https://github.com/vmware-tanzu/carvel-kapp-controller/pull/744, we'll allow for escaping using the `\` character.
2. evaluate the breaking change impact: we believe that while this is a change in behavior and therefore technically a breaking change, that the impact will be small or none. Let's verify by soliciting from the community whether anyone is deliberately expecting a trailing slash in their data values' keys (see in the description of this issue, the output from the fourth option).
3. when we do implement, let's be as close as possible to the `kapp-controller` behavior.
4. when we deliver, we need to explicitly call out that this is a breaking change and note the results of our "research" from step 2.

---
Vote on this request

This is an invitation to the community to vote on issues, to help us prioritize our backlog. Use the "smiley face" up to the right of this comment to vote.

👍 "I would like to see this addressed as soon as possible"
👎 "There are other more important things to focus on right now"

We are also happy to receive and review Pull Requests if you want to help working on this issue.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.