namerctl icon indicating copy to clipboard operation
namerctl copied to clipboard

Standardize `namerctl dtab update` behaviour when a version is included in the dtab file

Open rmars opened this issue 8 years ago • 0 comments

We check the version of the dtab on namerctl dtab update if we send the dtab in json format (and do a versioned update), but we don't if the dtab is sent via yaml, where the version is included in a comment (i.e. we do a versionless update).

If you just have a json file without setting the version key, (or a yaml file with or without the version included as a comment) then both json and yaml behave the same, i.e. will do versionless updated unless a version is provided using the --version flag.

This is confusing for users (#21). We should standardize. i.e. when a version is included in json or yaml, we should use it in both cases.

Example

When you do a namerctl dtab get <dtab namespace>, namerctl prints the dtab string with the version as a yaml comment. The user can then make updates to the dtab they received and run a namerctl dtab update <dtab namespace> and the update will work:

$ namerctl dtab get default
# version AAAAAAAAAAQ=
/svc  => /#/io.l5d.fs ;

$ namerctl dtab get default > default.yaml

# update default.yaml without changing the version
$ namerctl dtab update default default.yaml
Updated default

# update default.yaml *again* without changing the version
$ namerctl dtab update default default.yaml
Updated default

However, if you do the same steps, but add --json, you'll get a unexpected response: 412 Precondition Failed because we do check the version if it's included in the json payload:

$ namerctl dtab get default --json
{"version":"AAAAAAAAAAg=","dtab":[{"prefix":"/svc","dst":"/#/io.l5d.fs"}]}

$ namerctl dtab get default --json > default.json

# update default.json without changing the version
$ namerctl dtab update default default.json
Updated default

# update default.json *again* without changing the version
$ namerctl dtab update default default.json
Error: unexpected response: 412 Precondition Failed

rmars avatar Oct 30 '17 23:10 rmars