vcluster icon indicating copy to clipboard operation
vcluster copied to clipboard

[CLI] 'vcluster create' fails when the working dir has a file called 'vcluster'

Open enisoc opened this issue 2 years ago • 5 comments

I got a strange error when I tried to run vcluster create:

$ vcluster create test -n test
[info]   execute command: helm upgrade test vcluster --repo https://charts.loft.sh --version 0.4.4 --kubeconfig /tmp/284868977 --namespace test --install --repository-config='' --values /tmp/863399452
[fatal]  error executing helm upgrade test vcluster --repo https://charts.loft.sh --version 0.4.4 --kubeconfig /tmp/284868977 --namespace test --install --repository-config='' --values /tmp/863399452: Release "test" does not exist. Installing it now.
Error: file '/home/enisoc/bin/vcluster' does not appear to be a gzipped archive; got 'application/octet-stream'

It turned out this is because I was running vcluster from the working directory that contained the vcluster binary itself. It seems that Helm prefers the local file if it exists, instead of treating vcluster as referring to a chart within the charts.loft.sh repo. Helm then tries to load the vcluster file as if it's a chart archive.

Here is a minimal reproduction case:

cd /tmp
touch vcluster
vcluster create test -n test

A directory called vcluster causes a similar but slightly different error:

/tmp$ rm vcluster
/tmp$ mkdir vcluster
/tmp$ vcluster create test -n test
[info]   execute command: helm upgrade test vcluster --repo https://charts.loft.sh --version 0.4.4 --kubeconfig /tmp/732744325 --namespace test --install --repository-config='' --values /tmp/002659872
[fatal]  error executing helm upgrade test vcluster --repo https://charts.loft.sh --version 0.4.4 --kubeconfig /tmp/732744325 --namespace test --install --repository-config='' --values /tmp/002659872: Release "test" does not exist. Installing it now.
Error: Chart.yaml file is missing

enisoc avatar Nov 17 '21 03:11 enisoc

Thanks for reporting this. Your assumptions about the reason for this issue are correct: https://github.com/helm/helm/issues/7862

I wish more folks would link to this issue, so Helm maintainers may understand that this is not what users expect at all.

LukasGentele avatar Nov 17 '21 04:11 LukasGentele

Perhaps as a workaround, vcluster could execute helm with its working dir set to a temp dir whose contents are known?

enisoc avatar Nov 17 '21 16:11 enisoc

@enisoc yes thats true, we could do that

FabianKramm avatar Nov 18 '21 13:11 FabianKramm

@enisoc If you want to contribute this improvement, take a look how I did the same thing over here: https://github.com/loft-sh/loftctl/blob/master/pkg/clihelper/clihelper.go#L687

Note that --values files need to be rewritten to absolute paths first.

LukasGentele avatar Nov 18 '21 16:11 LukasGentele

Changing the working directory might cause other issues, e.g. relative paths in the env vars such as KUBECONFIG, etc. I am not sure what's the best way to solve this. As an immediate improvement, we can print a helpful error message that should make it easy for the user to work around this problem. :) The new error message is added in this PR - #285, and it looks like this:

[fatal] Aborting vcluster creation. Current working directory contains a file or a directory with the name equal to the vcluster chart name - "vcluster". Please execute vcluster create command from a directory that doesn't contain a file or directory named "vcluster".

matskiv avatar Jan 10 '22 16:01 matskiv