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

Export incorrectly squashes the env path #682

Open
sbienkow-ninja opened this issue Mar 17, 2022 · 2 comments
Open

Export incorrectly squashes the env path #682

sbienkow-ninja opened this issue Mar 17, 2022 · 2 comments
Labels
kind/bug Something isn't working

Comments

@sbienkow-ninja
Copy link

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
#!/usr/bin/env bash
set -euo pipefail

TMP_PATH="/tmp/tanka_export_path"
MAIN="$(cat - <<EOF
{
  "namespace": {
    "apiVersion": "v1",
    "kind": "Namespace",
    "metadata": {
      "labels": {
        "kubernetes.io/metadata.name": "default"
      },
      "name": "default"
    }
  }
}
EOF
)"

if [ -e "${TMP_PATH}" ]; then
  echo "The TMP Path already exist at ${TMP_PATH}" >&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
./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
Copy link

stale bot commented Apr 17, 2022

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
Copy link
Contributor

zerok commented May 27, 2024

Can still reproduce 🙂

@zerok zerok added the kind/bug Something isn't working label May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
Status: Backlog
Development

No branches or pull requests

3 participants