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

declare: -A: invalid option on macOS #13

Open
gangadharjannu opened this issue Aug 11, 2022 · 3 comments
Open

declare: -A: invalid option on macOS #13

gangadharjannu opened this issue Aug 11, 2022 · 3 comments
Labels
bug Something isn't working

Comments

@gangadharjannu
Copy link
Contributor

gangadharjannu commented Aug 11, 2022

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

rtpro commented Aug 12, 2022

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.

@rtpro rtpro added the bug Something isn't working label Aug 12, 2022
@rtpro
Copy link
Contributor

rtpro commented Aug 14, 2022

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

mtbdeano commented Jun 4, 2024

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!

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

When branches are created from issues, their pull requests are automatically linked.

3 participants