JovianX / helm-release-plugin

Helm3 plugin that pulls(re-creates) helm Charts from deployed releases, and updates values of deployed releases without the chart.
Apache License 2.0
97 stars 12 forks source link

declare: -A: invalid option on macOS #13

Open gangadharjannu opened 2 years ago

gangadharjannu commented 2 years ago

@jovianx-dev I want to thank you for your efforts in developing this plugin. I used this plugin to pull the helm charts from deployed helm releases and it worked on my macOS machine, however there are 2 issues I want to highlight

While running helm release pull on macOS, I am getting below errors related to

user@usersmac> helm release pull nodejs-sample -n my-test-namespace

/Users/user/Library/helm/plugins/helm-release-plugin/lib/main.sh: line 12: declare: -A: invalid option
declare: usage: declare [-afFirtx] [-p] [name[=value] ...]
error: [ /Users/user/Library/helm/plugins/helm-release-plugin/lib/main.sh at line 7 ]
/Users/user/Library/helm/plugins/helm-release-plugin/lib/api/helm-ops.sh: line 78: /Users/user/Library/helm/plugins/helm-release-plugin/lib/yq: No such file or directory
/Users/user/Library/helm/plugins/helm-release-plugin/lib/api/helm-ops.sh: line 79: /Users/user/Library/helm/plugins/helm-release-plugin/lib/yq: No such file or directory
Chart saved to nodejs-sample-0.0.1
  1. declare: -A is not supported on macOS and the reason is explained in https://stackoverflow.com/questions/27002192/bash-declare-a-does-not-work-on-macos. Summary is declare -A (associative arrays) are a bash 4+ feature and the macOS bash is likely 3.X.

  2. yq is also a dependency for your script, so I had to create symlink for yq to /Users/user/Library/helm/plugins/helm-release-plugin/lib/yq location.

For Issue 1: We can mention in readme to upgrade bash on macOS to version 4. For Issue 2: I created symlink and it worked and created values.yaml files (before that values.yaml file was empty)

How can we resolve this issues ?

I am happy to contribute anyway.

EDIT: The issue with yq could be related to installation using wget on line 23. Since wget is not available by default on macOS, it is not able to get yq and because of that it is throwing errors.

rtpro commented 2 years ago

Hey @gangadharjannu, thank you for reporting this.

The plugin was developed on Linux machines, and we would be happy to add support for macOS.

  1. declare -A issue: as you mentioned, macOS is shipped with Bash 3.x, I think we should find an alternative implementation for associative arrays(declare -A). Maybe this would work https://stackoverflow.com/questions/11776468/create-associative-array-in-bash-3#:~:text=A%20common%20method%20to,myarray%5B%24key%5D%7D%2C%20write.

  2. yq issue: The plugin pulls the Linux yq binary on plugin installation (see code here), we should add OS detection and pull the correct binary for the OS. We could use the $OSTYPE environment variable for that (example here).

  3. I also created issue #14 as it comes built-in with more systems, including macOS.

We are happy to get code contributions for any of these. Please let me know if you'd like to work on them.

rtpro commented 2 years ago

Hey @gangadharjannu, thank you for reporting this.

The plugin was developed on Linux machines, and we would be happy to add support for macOS.

  1. declare -A issue: as you mentioned, macOS is shipped with Bash 3.x, I think we should find an alternative implementation for associative arrays(declare -A). Maybe this would work https://stackoverflow.com/questions/11776468/create-associative-array-in-bash-3#:~:text=A%20common%20method%20to,myarray%5B%24key%5D%7D%2C%20write.
  2. yq issue: The plugin pulls the Linux yq binary on plugin installation (see code here), we should add OS detection and pull the correct binary for the OS. We could use the $OSTYPE environment variable for that (example here).
  3. I also created issue Replace wget with curl #14 as it comes built-in with more systems, including macOS.

We are happy to get code contributions for any of these. Please let me know if you'd like to work on them.

Issues 2, and 3 were addressed in PR #15 , thank you @gangadharjannu !

mtbdeano commented 5 months ago

here's a quick Mac fix for number 1 above:

brew install bash       # should get you bash v5+ at time of writing
/opt/homebrew/bin/bash  # drops you into a subshell with the correct version
helm release pull -n <yadda yadda> <release-you-need-a-chart-for>

this works because the plugin dev (thanks @jovianx-dev !) used the #!/usr/bin/env bash construct which looks in your current shell environment first (see this answer for why/how).

By dropping yourself into version 4+ of bash you get all the associative array goodness that @jovianx-dev is using to make the plugin scripts nice and clean.

Happy helming!