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

Running on Windows fails #214

Closed
sherifkayad opened this issue Apr 21, 2022 · 37 comments · Fixed by #217
Closed

Running on Windows fails #214

sherifkayad opened this issue Apr 21, 2022 · 37 comments · Fixed by #217
Labels
bug Something isn't working

Comments

@sherifkayad
Copy link

Current Behavior

When I install the plugin using Helm on Windows (using a MINGW terminal) and I attempt to run my helm command, there's an error as follows:

Error: fork/exec C:\Users\MY_USER\AppData\Roaming\helm\plugins\helm-secrets\scripts\run.sh: %1 is not a valid Win32 application.

My Helm command after installing the plugin was something like:

helm upgrade --install some-release --namespace=whatever -f my-values.yaml -f secrets://secrets.yaml chart --version="x.y.z" --dry-run

Unfortunately the command terminates with the error message mentioned at the beginning.

To install the plugin I used:

helm plugin install https://github.com/jkroepke/helm-secrets --version v3.13.0

I even tried the manual way like:

curl -LsSf https://github.com/jkroepke/helm-secrets/releases/latest/download/helm-secrets.tar.gz | tar -C "/c/Users/MY_USER/AppData/Roaming/helm/plugins" -xzf-

In both cases the installation seemed successfull and I could validate the plugin using e.g.:

$ helm plugin list
NAME    VERSION DESCRIPTION
secrets 3.13.0  This plugin provides secrets values encryption for Helm charts secure storing

Expected Behavior

The plugin would work as expected!

Steps To Reproduce

No response

Environment

  • Helm Version: version.BuildInfo{Version:"v3.8.2", GitCommit:"6e3701edea09e5d55a8ca2aae03a68917630e91b", GitTreeState:"clean", GoVersion:"go1.17.5"}
  • Helm Secrets Version: 3.13.0
  • OS: Windows
  • Shell: MINGW

Anything else?

No response

@sherifkayad sherifkayad added the bug Something isn't working label Apr 21, 2022
@jkroepke
Copy link
Owner

jkroepke commented Apr 21, 2022

Hi,

can you confirm, the environment variable HELM_SECRETS_WINDOWS_SHELL is not set?

Can you modify this line

to

@echo on

and re-run helm secrets, post the output here.

@sherifkayad
Copy link
Author

sherifkayad commented Apr 21, 2022

@jkroepke the env variable HELM_SECRETS_WINDOWS_SHELL is not set .. I could validate that by getting an empty result for echo $HELM_SECRETS_WINDOWS_SHELL

After performing the change you suggested, unfortunately the result is exactly the same like before:

Release "some-release" does not exist. Installing it now.
Error: fork/exec C:\Users\MY_USER\AppData\Roaming\helm\plugins\helm-secrets\scripts\run.sh: %1 is not a valid Win32 application.

@jkroepke
Copy link
Owner

Based in the result you provided, it feels like helm does not execute the platformCommand for windows, instead just running the command.

command: "$HELM_PLUGIN_DIR/scripts/run.sh"
platformCommand:
- os: windows
command: "cmd /c $HELM_PLUGIN_DIR\\scripts\\wrapper\\sh.cmd $HELM_PLUGIN_DIR\\scripts\\run.sh"

What happens, if you modify the plugin.yaml from

command: "$HELM_PLUGIN_DIR/scripts/run.sh" 
platformCommand: 
  - os: windows 
    command: "cmd /c $HELM_PLUGIN_DIR\\scripts\\wrapper\\sh.cmd $HELM_PLUGIN_DIR\\scripts\\run.sh" 

to

command: "echo linux" 
platformCommand: 
  - os: windows 
    command: "cmd /c echo windows" 

And post the output here?

@sherifkayad
Copy link
Author

also same result .. I believe the issue is in the downloader part .. when I changed the downloader to:

downloaders:
  - command: "echo downloader"

I got a different error as follows:

Release "some-release" does not exist. Installing it now.
Error: exec: "C:\\Users\\MY_USER\\AppData\\Roaming\\helm\\plugins\\helm-secrets\\echo": file does not exist

@sherifkayad
Copy link
Author

@jkroepke any idea?

@jkroepke
Copy link
Owner

Using the wrapper instead the scheme based approach should work for you here.

helm secrets upgrade --install some-release --namespace=whatever -f my-values.yaml -f secrets.yaml chart --version="x.y.z" --dry-run

Something like

downloaders:
  - command: "$HELM_PLUGIN_DIR/scripts/wrapper/run.cmd $HELM_PLUGIN_DIR/scripts/run.sh"

could be an alternative.

@sherifkayad
Copy link
Author

sherifkayad commented Apr 21, 2022

Unfortunately neither the wrapper nor the change in the downloaders worked for me!

Could that be related that my userfolder is containing a space? e.g. My User

Using the wrapper:

'C:\Users\My' is not recognized as an internal or external command,
operable program or batch file.
Error: plugin "secrets" exited with error

Changing the downloaders:

Error: exec: "C:\\Users\\My User\\AppData\\Roaming\\helm\\plugins\\helm-secrets\\$HELM_PLUGIN_DIR\\scripts\\wrapper\\run.cmd": file does not exist

@sherifkayad
Copy link
Author

sherifkayad commented Apr 21, 2022

@jkroepke I came across the comment here zendesk/helm-secrets#114 (comment) .. should I try that or is that a very old issue that now should be working fine in your updated fork of the project?

Update: even that didn't help.

@jkroepke
Copy link
Owner

jkroepke commented Apr 22, 2022

Error: exec: "C:\Users\My User\AppData\Roaming\helm\plugins\helm-secrets\$HELM_PLUGIN_DIR\scripts\wrapper\run.cmd": file does not exist

Try

downloaders:
  - command: "scripts/wrapper/run.cmd $HELM_PLUGIN_DIR/scripts/run.sh"

Could that be related that my userfolder is containing a space? e.g. My User

Yes, but this is an error on our side. If you could add @echo on again and rerun the wrapper, this could help me.

@sherifkayad
Copy link
Author

Error: exec: "C:\Users\My User\AppData\Roaming\helm\plugins\helm-secrets$HELM_PLUGIN_DIR\scripts\wrapper\run.cmd": file does not exist

Try

downloaders:
  - command: "scripts/wrapper/run.cmd $HELM_PLUGIN_DIR/scripts/run.sh"

Trying that gave me:

  • Using protocol e.g. -f secrets://secrets.yaml
'C:\Users\My' is not recognized as an internal or external command,
operable program or batch file.
Error: plugin "scripts/wrapper/run.cmd $HELM_PLUGIN_DIR/scripts/run.sh" exited with error
  • Using wrapper helm secrets upgrade:
'C:\Users\My' is not recognized as an internal or external command,
operable program or batch file.
Error: plugin "secrets" exited with error

@jkroepke
Copy link
Owner

With @echo on? it should give some debug infos

@sherifkayad
Copy link
Author

with @echo on in both the sh.cmd and run.cmd I didn't get any additional info. Exactly like above.

@jkroepke
Copy link
Owner

jkroepke commented Apr 22, 2022

Sorry, I'm currently on a Mac. Reading https://stackoverflow.com/questions/6376113/how-do-i-use-spaces-in-the-command-prompt could help

platformCommand: 
  - os: windows 
    command: 'cmd /c "$HELM_PLUGIN_DIR\\scripts\\wrapper\\sh.cmd" "$HELM_PLUGIN_DIR\\scripts\\run.sh"'

OR

platformCommand: 
  - os: windows 
    command: "cmd /c \"$HELM_PLUGIN_DIR\\scripts\\wrapper\\sh.cmd\" \"$HELM_PLUGIN_DIR\\scripts\\run.sh\""

@sherifkayad
Copy link
Author

The second one looked better but still ..

'\"C:\Users\My User\AppData\Roaming\helm\plugins\helm-secrets\scripts\wrapper\sh.cmd\"' is not recognized as an internal or external command,
operable program or batch file.
Error: plugin "secrets" exited with error

@jkroepke
Copy link
Owner

Whats wrong with first?

@sherifkayad
Copy link
Author

has double backward slashes \\ e.g.:

'\"C:\Users\My User\AppData\Roaming\helm\plugins\helm-secrets\\scripts\\wrapper\\sh.cmd"' is not recognized as an internal or external command,
operable program or batch file.
Error: plugin "secrets" exited with error

@jkroepke
Copy link
Owner

What about

platformCommand:
  - os: windows
    command: 'cmd /c "$HELM_PLUGIN_DIR/scripts/wrapper/sh.cmd" "$HELM_PLUGIN_DIR/scripts/run.sh"'
platformCommand:
  - os: windows
    command: 'cmd /c "$HELM_PLUGIN_DIR\scripts\wrapper\sh.cmd" "$HELM_PLUGIN_DIR\scripts\run.sh"'
platformCommand:
  - os: windows
    command: >-
      cmd /c "$HELM_PLUGIN_DIR/scripts/wrapper/sh.cmd" "$HELM_PLUGIN_DIR/scripts/run.sh"
platformCommand:
  - os: windows
    command: >-
      cmd /c "$HELM_PLUGIN_DIR\\scripts\\wrapper\\sh.cmd" "$HELM_PLUGIN_DIR\\scripts\\run.sh"
platformCommand:
  - os: windows
    command: >-
      cmd /c "$HELM_PLUGIN_DIR\scripts\wrapper\sh.cmd" "$HELM_PLUGIN_DIR\scripts\run.sh"

@jkroepke
Copy link
Owner

jkroepke commented Apr 22, 2022

In meantime, here is the reason, why the space in the directory is the problem here:

https://github.com/helm/helm/blob/699ea6dcef302d7ded608bc8a1ab6c404de81685/pkg/plugin/plugin.go#L152

Helm splits the plugin command by space. None helm plugins will work, if the plugin path contains spaces here.

This problem does also exists on linux, it's not a windows specific issue here.

@jkroepke
Copy link
Owner

I looked also into the source code, while the wrapper approach would never work if the dir contains a spaces, I'm not sure why the

this is my last idea

41132a2 in combination with the helm downloader

@sherifkayad
Copy link
Author

@jkroepke I tried to apply the last changes you did in the commit, no luck unfortunately .. error:

'C:\Users\My' is not recognized as an internal or external command,
operable program or batch file.
Error: plugin "scripts/wrapper/run.cmd scripts/run.sh downloader" exited with error

@jkroepke
Copy link
Owner

jkroepke commented Apr 22, 2022

Are you include the changes from the run.cmd? If yes, there is no chance from helm-secrets side do workaround this.

@sherifkayad
Copy link
Author

yes I did and no it didn't work.

Now I need something completely different and crazy .. I renamed my user to avoid spaces!! .. and then re-installed the plugin to have a fresh start.

Real good news => the wrapper works perfectly fine e.g. helm secrets upgrade ... -f secrets.yaml

Question => How can I get the protocol way secrets:// to work? .. right now I also face the original issue:

Error: fork/exec C:\Users\sherif\AppData\Roaming\helm\plugins\helm-secrets\scripts\run.sh: %1 is not a valid Win32 application.

@jkroepke
Copy link
Owner

The wrapper works here, because helm provides a method to configure different command for different platforms.

But this is not the case for downloader command.

I guess, for windows, the

downloaders:
  - command: "scripts/wrapper/run.cmd $HELM_PLUGIN_DIR/scripts/run.sh"

is still needed.

What I did not test is register the .sh extension with the git bash.

image

@sherifkayad
Copy link
Author

well .. I got a different error this time

sh: $HELM_PLUGIN_DIR/scripts/run.sh: No such file or directory
Error: plugin "scripts/wrapper/run.cmd $HELM_PLUGIN_DIR/scripts/run.sh" exited with error

@sherifkayad
Copy link
Author

sherifkayad commented Apr 22, 2022

@jkroepke I finally got it to work!

The downloaders command should be: "scripts/wrapper/run.cmd ~/AppData/Roaming/helm/plugins/helm-secrets/scripts/run.sh downloader"

So to sum the solution up:

  • The plugin would never work with user directories containing a space on Windows => must be changed by the user or use WSL2 terminals!
  • From MingW terminals to use the protocol secrets:// one would need to change the downloaders command as mentioned above.
  • The wrapper commands e.g. helm secrets update .. would work fine and there's no tuning needed

Do you probably want to add some docs about that?

@jkroepke
Copy link
Owner

Can you at least try this 41132a2 ?

Inside run.cmd, I added a cd command, which should change the working directory to ~/AppData/Roaming/helm/plugins/helm-secrets/, then the scripts/run.sh path should work.

$HELM_PLUGIN_DIR is wrong here. Because the env expandsion only works for command, not for downloaders.command

@sherifkayad
Copy link
Author

I tried your commit now .. again good news and bad news ..

bad news first: trying something like helm upgrade --install ... -f values.yaml -f secrets://secret.yaml gives the following error:

[helm-secrets] File does not exist: secrets.yml
Error: plugin "scripts/wrapper/run.cmd scripts/run.sh downloader" exited with error

good news: when I do something like helm upgrade --install ... -f values.yaml -f secrets:///full/path/to/secret.yaml that works like a charm!

@jkroepke
Copy link
Owner

I see, change directory leads to unexpected behaivors...

Can you check this? https://github.com/jkroepke/helm-secrets/pull/217/files

@sherifkayad
Copy link
Author

Tried your PR results ..

Error: failed to parse secrets://secrets.yml: error converting YAML to JSON: yaml: line 7: mapping values are not allowed in this context

I don't even have a line 7 .. seems like my Yaml file got mixed up with something ..

@jkroepke
Copy link
Owner

Running helm with --debug give you more info.

@sherifkayad
Copy link
Author

nothing useful at all :(

history.go:56: [debug] getting history for release my-release
Error: failed to parse secrets://secrets.yml: error converting YAML to JSON: yaml: line 7: mapping values are not allowed in this context
helm.go:84: [debug] error converting YAML to JSON: yaml: line 7: mapping values are not allowed in this context
failed to parse secrets://logging/loki/sbx/secrets.yml
helm.sh/helm/v3/pkg/cli/values.(*Options).MergeValues
        helm.sh/helm/v3/pkg/cli/values/options.go:54
main.newUpgradeCmd.func2
        helm.sh/helm/v3/cmd/helm/upgrade.go:141
github.com/spf13/cobra.(*Command).execute
        github.com/spf13/[email protected]/command.go:856
github.com/spf13/cobra.(*Command).ExecuteC
        github.com/spf13/[email protected]/command.go:974
github.com/spf13/cobra.(*Command).Execute
        github.com/spf13/[email protected]/command.go:902
main.main
        helm.sh/helm/v3/cmd/helm/helm.go:83
runtime.main
        runtime/proc.go:255
runtime.goexit
        runtime/asm_amd64.s:1581

@jkroepke
Copy link
Owner

I update once again the .cmd files. Can you re-check it?

You can install the version by

helm.exe plugin install https://github.com/jkroepke/helm-secrets.git --version space-plugin-dir

@sherifkayad
Copy link
Author

sherifkayad commented Apr 22, 2022

@jkroepke 🥳 🥳 great work! now working like a charm!! .. Thanks so much. Would you merge this PR? It wouldn't affect the currently working Linux versions, would it?

@jkroepke
Copy link
Owner

It currently would breaks non windows setups

@sherifkayad
Copy link
Author

Hmmm .. no chance to have a separate build for Windows or to have a way that's compatible with both?

@jkroepke
Copy link
Owner

since there is only one entrypoint for both platforms, it must a one the could be parse by bash and cmd at the at the same time, including a unix shebang line....

I guess this does not exists

@jkroepke
Copy link
Owner

#214 introduce a new command called helm secrets patch windows. This command patches the local plugin.yaml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants