grafana / tanka

Flexible, reusable and concise configuration for Kubernetes
https://tanka.dev
Apache License 2.0
2.41k stars 166 forks source link

Export incorrectly squashes the env path #682

Open sbienkow-ninja opened 2 years ago

sbienkow-ninja commented 2 years ago

It appears as though some commands, like tk export, try to wrongly make the path absolute, by squashing ../<something>/ into ./, which is not correct. Most other commands, like show, do work.

Env info

Using tanka v0.20.0 (latest at the time of writing)

Reproduction script

Reproduction script ```bash #!/usr/bin/env bash set -euo pipefail TMP_PATH="/tmp/tanka_export_path" MAIN="$(cat - <&2 echo "Please delete it to run the script again" >&2 exit 1 fi mkdir "${TMP_PATH}" cd "${TMP_PATH}" set -x mkdir something cd something echo "##### Preparing env #####" >&2 tk init cat - <<<"${MAIN}" >| environments/default/main.jsonnet echo "##### Showing from something dir #####" >&2 tk show environments/default --dangerous-allow-redirect | cat - echo "##### Showing export from something dir #####" >&2 tk export ../something_export environments/default ls ../something_export cat ../something_export/*.yaml mkdir ../other cd ../other echo "##### Showing from other dir #####" >&2 tk show ../something/environments/default --dangerous-allow-redirect | cat - echo "##### Showing export from other dir #####" >&2 tk export ../other_export ../something/environments/default ls ../other_export cat ../other_export/*.yaml echo "##### DONE #####" >&2 ```
Reproduction script logs ```bash ./reproduce.sh + mkdir something + cd something + echo '##### Preparing env #####' ##### Preparing env ##### + tk init GET https://github.com/grafana/jsonnet-libs/archive/98c3060877aa178f6bdfc6ac618fbe0043fc3de7.tar.gz 200 GET https://github.com/jsonnet-libs/k8s-libsonnet/archive/4be83346f2c5b06a03cb8ee726ec66aab33a60bb.tar.gz 200 Directory structure set up! Remember to configure the API endpoint: `tk env set environments/default --server=https://127.0.0.1:6443` + cat - + echo '##### Showing from something dir #####' ##### Showing from something dir ##### + tk show environments/default --dangerous-allow-redirect + cat - apiVersion: v1 kind: Namespace metadata: labels: kubernetes.io/metadata.name: default name: default + echo '##### Showing export from something dir #####' ##### Showing export from something dir ##### + tk export ../something_export environments/default Loading environments/default from /tmp/tanka_export_path/something/environments/default/main.jsonnet Loaded environments/default from /tmp/tanka_export_path/something/environments/default/main.jsonnet, time elapsed: 5.195276ms + ls ../something_export manifest.json v1.Namespace-default.yaml + cat ../something_export/v1.Namespace-default.yaml apiVersion: v1 kind: Namespace metadata: labels: kubernetes.io/metadata.name: default name: default + mkdir ../other + cd ../other + echo '##### Showing from other dir #####' ##### Showing from other dir ##### + tk show ../something/environments/default --dangerous-allow-redirect + cat - apiVersion: v1 kind: Namespace metadata: labels: kubernetes.io/metadata.name: default name: default + echo '##### Showing export from other dir #####' ##### Showing export from other dir ##### + tk export ../other_export ../something/environments/default Error: finding root: stat /tmp/tanka_export_path/other/environments/default/main.jsonnet: no such file or directory ```

Reproduction description

To reproduce, simply create tanka environment, then create a new, empty folder and from within it try to export your environment.

Having following structure:

$ tree . -L 2
.
├── other
└── something
    ├── environments
    ├── jsonnetfile.json
    ├── jsonnetfile.lock.json
    ├── lib
    └── vendor

5 directories, 2 files

Running the tk export from something works as expected, but running tk export exportdir ../something/environments/default results in tanka trying to export $PWD/environments/default (as if ../ caused ../something/ to be deleted and appended to $PWD).:

Exporting from something:

$ tk export ../something_export environments/default
Loading environments/default from /tmp/tanka_export_path/something/environments/default/main.jsonnet
Loaded environments/default from /tmp/tanka_export_path/something/environments/default/main.jsonnet, time elapsed: 5.195276ms

Exporting from other:

$ tk export ../other_export ../something/environments/default
Error: finding root: stat /tmp/tanka_export_path/other/environments/default/main.jsonnet: no such file or directory
stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

zerok commented 6 months ago

Can still reproduce 🙂