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

feat: plugin.yaml support platformHooks (closes #7117) #10126

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dimabru
Copy link

@dimabru dimabru commented Sep 14, 2021

What this PR does / why we need it:
This pr adds platformHook behavior for plugin installations. This is mainly to support plugin installation for windows, since at this point, helm plugins are not able to run on windows.
Usage is very similar to current platformCommand. The user can specify specific os to run hooks on, and if missing, default to root hooks key in plugin yaml

closes #7117

Special notes for your reviewer:
For env vars, there was an issue with using built-in os.ExpandEnv function on windows.
Hence, there's no support for $var in windows scripts. What is working though is windows env var syntax %VAR% - mainly used for %HELM_PLUGIN_DIR%

If applicable:

  • this PR contains documentation
  • this PR contains unit tests
  • this PR has been tested for backwards compatibility

@helm-bot helm-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Sep 14, 2021
@dimabru
Copy link
Author

dimabru commented Sep 14, 2021

closes #7117

@dimabru dimabru changed the title WIP: plugin install platformHooks feat: plugin install platformHooks (closes #7117) Sep 14, 2021
Signed-off-by: Dima Brusilovsky <dimabru@gmail.com>
@dimabru dimabru marked this pull request as ready for review September 14, 2021 14:39
@dimabru dimabru changed the title feat: plugin install platformHooks (closes #7117) feat: plugin.yaml support platformHooks (closes #7117) Sep 14, 2021
@dimabru
Copy link
Author

dimabru commented Sep 19, 2021

Hi @bacongobbler, any chance you can have a look at the code?
Thanks a lot :)

@TBBle
Copy link
Contributor

TBBle commented Sep 26, 2021

With a quick look, this also changes the behaviour of hooks, which I don't think is desirable, as it will break existing working setups, e.g. running helm plugin install under MSYS2 which is the work-around I've used for #7117.

since at this point, helm plugins are not able to run on windows.

Helm plugins run on Windows, as long as their installer bash script recognises Windows and installs a Windows binary as, e.g., https://github.com/helm/helm-2to3/blob/main/scripts/install_plugin.sh, does.

Also, it continues to hard-code a per-platform shell. At least, by my suggestion in #7117, platformHooks would be up to the platform hook itself to specify sh -c or cmd /c or whatever the appropriate shell is, e.g. on Windows, PowerShell would be a reasonable choice for hook implementation. This would mean that the existing hooks are equivalent to a "default" platformHook of sh -c <existing content> which is reasonably non-surprising.

I'm not sure if I'd group the platform hooks by OS as done here, or by event as the current hooks are. That's assuming I'm reading this correctly: lack of tests means I have to imagine what the config file looks like with these changes.

It might even be handy to prepare a draft PR against a plugin or two (that already support WIndows) to see how your changes look in the real world, or ask the maintainers of those plugins to do so. That would be important ecosystem feedback anyway.

@dimabru
Copy link
Author

dimabru commented Sep 26, 2021

Hi @TBBle
Thanks a lot for the detailed comment.

In your suggestion in #7117 (comment) you suggest to deprecate hooks and keep only the new platformHooks behavior. Why is that? Why not keep hooks and use sh -c as fallback for backwards compatibility? Also, I think its not far-fetched to assume that helm defaults to shell executable in case platformHook is missing.

I think I understand what you mean when you say this change will break existing behavior. I will change the script to not assume exec script by checking os, but rather add an option for the user to explicitly declare the preffered way of execution.

As you suggested, I will add unit-tests and a draft pr in another plugin to give a clear example on how this behavior might look.

@TBBle
Copy link
Contributor

TBBle commented Sep 26, 2021

Deprecating hooks would in-effect be keeping it as backwards-compat behaviour: Existing plugins would install exactly as they do now, including assuming sh -c and hence not working on Windows outside a specific user setup. That's also the reason to deprecate it, because it assumes something that isn't a great assumption across platforms, so people shouldn't be writing new install hooks using it. If they mean to only support Linux, they can do that explicitly in platformHooks (and then Helm would be able to detect that and refuse to install the plugin, rather than failing mysteriously as it does now).

Basically, I was mirroring the behaviour of platformCommand, and that does not prepend a shell in the command. I think having platformHooks act differently to platformCommand in this regard would be a surprising mistake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Windows support for Helm plugin installers
3 participants