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

Fix dynamic providers not on $PATH #9396

Merged
merged 4 commits into from Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG_PENDING.md
Expand Up @@ -22,3 +22,6 @@

- [cli] - StackReferences will now correctly use the service bulk decryption end point.
[#9373](https://github.com/pulumi/pulumi/pull/9373)

- [cli/plugin] - Dynamic provider binaries will now be found even if pulumi/bin is not on $PATH.
[#9396](https://github.com/pulumi/pulumi/pull/9396)
1 change: 1 addition & 0 deletions pkg/testing/integration/command.go
Expand Up @@ -40,6 +40,7 @@ func RunCommand(t *testing.T, name string, args []string, wd string, opts *Progr
env = append(env, "PULUMI_DEBUG_COMMANDS=true")
env = append(env, "PULUMI_RETAIN_CHECKPOINTS=true")
env = append(env, "PULUMI_CONFIG_PASSPHRASE=correct horse battery staple")
env = append(env, "PULUMI_IGNORE_AMBIENT_PLUGINS=true")

cmd := exec.Cmd{
Path: path,
Expand Down
29 changes: 15 additions & 14 deletions sdk/go/common/workspace/plugins.go
Expand Up @@ -1040,17 +1040,17 @@ func getPlugins(dir string, skipMetadata bool) ([]PluginInfo, error) {
func GetPluginPath(kind PluginKind, name string, version *semver.Version) (string, string, error) {
var filename string

// We currently bundle some language plugins with "pulumi" and thus expect them to be next to the pulumi
// binary. We also always allow these language plugins to be picked up from PATH even if
// PULUMI_IGNORE_AMBIENT_PLUGINS is set. New languages will not be specially treated and will behave like
// any other plugin.
isBundledLangauge := kind == LanguagePlugin &&
(name == "dotnet" || name == "go" || name == "nodejs" || name == "python")
// We currently bundle some plugins with "pulumi" and thus expect them to be next to the pulumi binary. We
// also always allow these plugins to be picked up from PATH even if PULUMI_IGNORE_AMBIENT_PLUGINS is set.
// Eventually we want to fix this so new plugins are true plugins in the plugin cache.
isBundled := kind == LanguagePlugin ||
(kind == ResourcePlugin && name == "pulumi-nodejs") ||
(kind == ResourcePlugin && name == "pulumi-python")

// If we have a version of the plugin on its $PATH, use it, unless we have opted out of this behavior explicitly.
// This supports development scenarios.
optOut, isFound := os.LookupEnv("PULUMI_IGNORE_AMBIENT_PLUGINS")
includeAmbient := !(isFound && cmdutil.IsTruthy(optOut)) || isBundledLangauge
includeAmbient := !(isFound && cmdutil.IsTruthy(optOut)) || isBundled
if includeAmbient {
filename = (&PluginInfo{Kind: kind, Name: name, Version: version}).FilePrefix()
if path, err := exec.LookPath(filename); err == nil {
Expand All @@ -1059,13 +1059,14 @@ func GetPluginPath(kind PluginKind, name string, version *semver.Version) (strin
}
}

// At some point in the future, language plugins will be located in the plugin cache, just like regular plugins
// (see pulumi/pulumi#956 for some of the reasons why this isn't the case today). For now, they ship next to the
// `pulumi` binary. While we encourage this folder to be on the $PATH (and so the check above would have found
// the language plugin) it's possible someone is running `pulumi` with an explicit path on the command line or
// has done symlink magic such that `pulumi` is on the path, but the language plugins are not. So, if possible,
// look next to the instance of `pulumi` that is running to find this language plugin.
if isBundledLangauge {
// At some point in the future, bundled plugins will be located in the plugin cache, just like regular
// plugins (see pulumi/pulumi#956 for some of the reasons why this isn't the case today). For now, they
// ship next to the `pulumi` binary. While we encourage this folder to be on the $PATH (and so the check
// above would have found the plugin) it's possible someone is running `pulumi` with an explicit path on
// the command line or has done symlink magic such that `pulumi` is on the path, but the bundled plugins
// are not. So, if possible, look next to the instance of `pulumi` that is running to find this bundled
// plugin.
if isBundled {
exePath, exeErr := os.Executable()
if exeErr == nil {
fullPath, fullErr := filepath.EvalSymlinks(exePath)
Expand Down