.NET: Report plugin install errors during pulumi new (#5760)

The way `pulumi new` installs dependencies for .NET projects is slightly different from other languages. For Node.js, Python, and Go, `pulumi new` runs the appropriate command to install project dependencies (e.g. `npm install`, `pip install`, or `go mod download`). For .NET, it calls the same routine used during `preview|up` to ensure required plugins are installed. For .NET, this ends up running `dotnet build` which implicitly installs Nuget packages, builds the project, and also attempts to determine and install the needed Pulumi plugins. When this operation runs during `preview|up`, and there are failures installing a plugin, the error is logged, but deliberately not returned, because an error will be shown for missing plugins later on during the `preview|up` operation. However, during `pulumi new`, we should show any plugin install errors.
This commit is contained in:
Justin Van Patten 2020-11-16 21:56:13 -08:00 committed by GitHub
parent 6a68914fed
commit bfe4969f35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 7 deletions

View file

@ -33,6 +33,9 @@ CHANGELOG
- Fix plugin install failures on Windows.
[#5759](https://github.com/pulumi/pulumi/pull/5759)
- .NET: Report plugin install errors during `pulumi new`.
[#5760](https://github.com/pulumi/pulumi/pull/5760)
## 2.13.2 (2020-11-06)
- Fix a bug that was causing errors when (de)serializing custom resources.

View file

@ -167,7 +167,8 @@ func plan(ctx *Context, info *planContext, opts planOptions, dryRun bool) (*plan
plan, err = deploy.NewPlan(
plugctx, target, target.Snapshot, source, localPolicyPackPaths, dryRun, ctx.BackendClient)
} else {
_, defaultProviderVersions, pluginErr := installPlugins(proj, pwd, main, target, plugctx)
_, defaultProviderVersions, pluginErr := installPlugins(proj, pwd, main, target, plugctx,
false /*returnInstallErrors*/)
if pluginErr != nil {
return nil, pluginErr
}

View file

@ -19,6 +19,7 @@ import (
"sort"
"github.com/blang/semver"
"github.com/pkg/errors"
"golang.org/x/sync/errgroup"
"github.com/pulumi/pulumi/pkg/v2/resource/deploy"
@ -181,7 +182,8 @@ func installPlugin(plugin workspace.PluginInfo) error {
logging.V(preparePluginVerboseLog).Infof(
"installPlugin(%s, %s): extracting tarball to installation directory", plugin.Name, plugin.Version)
if err := plugin.Install(stream); err != nil {
return err
return errors.Wrapf(err, "installing plugin; run `pulumi plugin install %s %s v%s` to retry manually",
plugin.Kind, plugin.Name, plugin.Version)
}
logging.V(7).Infof("installPlugin(%s, %s): successfully installed", plugin.Name, plugin.Version)

View file

@ -93,7 +93,7 @@ func newQuerySource(cancel context.Context, client deploy.BackendClient, q Query
opts QueryOptions) (deploy.QuerySource, error) {
allPlugins, defaultProviderVersions, err := installPlugins(q.GetProject(), opts.pwd, opts.main,
nil, opts.plugctx)
nil, opts.plugctx, false /*returnInstallErrors*/)
if err != nil {
return nil, err
}

View file

@ -189,13 +189,13 @@ func Update(u UpdateInfo, ctx *Context, opts UpdateOptions, dryRun bool) (Resour
// RunInstallPlugins calls installPlugins and just returns the error (avoids having to export pluginSet).
func RunInstallPlugins(
proj *workspace.Project, pwd, main string, target *deploy.Target, plugctx *plugin.Context) error {
_, _, err := installPlugins(proj, pwd, main, target, plugctx)
_, _, err := installPlugins(proj, pwd, main, target, plugctx, true /*returnInstallErrors*/)
return err
}
func installPlugins(
proj *workspace.Project, pwd, main string, target *deploy.Target,
plugctx *plugin.Context) (pluginSet, map[tokens.Package]*semver.Version, error) {
plugctx *plugin.Context, returnInstallErrors bool) (pluginSet, map[tokens.Package]*semver.Version, error) {
// Before launching the source, ensure that we have all of the plugins that we need in order to proceed.
//
@ -227,8 +227,12 @@ func installPlugins(
// If there are any plugins that are not available, we can attempt to install them here.
//
// Note that this is purely a best-effort thing. If we can't install missing plugins, just proceed; we'll fail later
// with an error message indicating exactly what plugins are missing.
// with an error message indicating exactly what plugins are missing. If `returnInstallErrors` is set, then return
// the error.
if err := ensurePluginsAreInstalled(allPlugins); err != nil {
if returnInstallErrors {
return nil, nil, err
}
logging.V(7).Infof("newUpdateSource(): failed to install missing plugins: %v", err)
}
@ -356,7 +360,7 @@ func newUpdateSource(
//
allPlugins, defaultProviderVersions, err := installPlugins(proj, pwd, main, target,
plugctx)
plugctx, false /*returnInstallErrors*/)
if err != nil {
return nil, err
}