Commit graph

2578 commits

Author SHA1 Message Date
Sean Gillespie 91c550f1e0
Send structured errors across RPC boundaries (#1072)
* Send structured errors across RPC boundaries

This brings us closer to gRPC best practices where we send structured
errors with error codes across RPC endpoints. The new "rpcerrors"
package can wrap errors from RPC endpoints, so RPC servers can attach
some additional context as to why a request failed.

* Code review feedback:

1. Rename rpcerrors -> rpcerror, better package name
2. Rename RPCError -> Error, RPCErrorCause -> ErrorCause, names
suggested by gometalinter to improve their package-qualified names
3. Fix import organization in rpcerror.go
2018-03-28 17:07:35 -07:00
Pat Gavlin 713a38dcb6
Merge pull request #1083 from pulumi/GetStack
Remove some calls to `...repo/project/stacks`.
2018-03-28 15:48:33 -07:00
Pat Gavlin 7fb48b7658 Fix the local implementation of GetStack. 2018-03-28 15:22:13 -07:00
Joe Duffy 7a9c557a50
Merge pull request #1082 from pulumi/1081_refresh_prep
General prep work for refresh
2018-03-28 13:41:51 -07:00
Pat Gavlin 4c527410a3 Remove some calls to ...repo/project/stacks.
This endpoint is relatively expensive, as it returns a large amount of
data for each stack (essentially the stack's entire checkpoint). We
currently call this endpoint in a few places that really just need
information about a single stack. In these places we should simply
interact with that stack directly.

After these changes, there is only one call to the `stacks` endpoint on
the startup path: `upgradeConfigurationFiles` loops over all of the
stacks in each backend and attempts to upgrade each stack's
configuration. Once we no longer need to do this we will not be hitting
the `stacks` endpoint on each CLI invocation.
2018-03-28 12:47:12 -07:00
joeduffy 16e45dc92a Remove some outdated comments 2018-03-28 07:56:35 -07:00
joeduffy 8b5874dab5 General prep work for refresh
This change includes a bunch of refactorings I made in prep for
doing refresh (first, the command, see pulumi/pulumi#1081):

* The primary change is to change the way the engine's core update
  functionality works with respect to deploy.Source.  This is the
  way we can plug in new sources of resource information during
  planning (and, soon, diffing).  The way I intend to model refresh
  is by having a new kind of source, deploy.RefreshSource, which
  will let us do virtually everything about an update/diff the same
  way with refreshes, which avoid otherwise duplicative effort.

  This includes changing the planOptions (nee deployOptions) to
  take a new SourceFunc callback, which is responsible for creating
  a source specific to the kind of plan being requested.

  Preview, Update, and Destroy now are primarily differentiated by
  the kind of deploy.Source that they return, rather than sprinkling
  things like `if Destroying` throughout.  This tidies up some logic
  and, more importantly, gives us precisely the refresh hook we need.

* Originally, we used the deploy.NullSource for Destroy operations.
  This simply returns nothing, which is how Destroy works.  For some
  reason, we were no longer doing this, and instead had some
  `if Destroying` cases sprinkled throughout the deploy.EvalSource.
  I think this is a vestige of some old way we did configuration, at
  least judging by a comment, which is apparently no longer relevant.

* Move diff and diff-printing logic within the engine into its own
  pkg/engine/diff.go file, to prepare for upcoming work.

* I keep noticing benign diffs anytime I regenerate protobufs.  I
  suspect this is because we're also on different versions.  I changed
  generate.sh to also dump the version into grpc_version.txt.  At
  least we can understand where the diffs are coming from, decide
  whether to take them (i.e., a newer version), and ensure that as
  a team we are monotonically increasing, and not going backwards.

* I also tidied up some tiny things I noticed while in there, like
  comments, incorrect types, lint suppressions, and so on.
2018-03-28 07:45:23 -07:00
Pat Gavlin 528e07477b
Merge pull request #1079 from pulumi/ManagedStackLogs
Enable logs for managed stacks.
2018-03-27 15:29:10 -07:00
Pat Gavlin 75d75a41c0 Enable logs for managed stacks.
Simply fetch the checkpoint and use the local config to process logs.

Fixes #1078.
2018-03-27 14:29:10 -07:00
joeduffy 2ae8d4cc36 Tidy up the README ever-so-slightly 2018-03-25 15:14:30 -07:00
Luke Hoban 8c0d1698b0
Upgrade to latest gRPC (#1071)
We previously locked our dependency on google.golang.org/grpc to 1.7.2 due to issues we had seen on 1.8.x as noted in #701. However, this has prevented us using some other dependencies which require newer grpc. A test in this repo and AWS showed no problems with the latest 1.10.x versions of the library in our tests.

We'll go ahead and remove this constraint and allow grpc to float forward. If we see issues again, we'll use that repro case to investigate an alternative fix in our code.

Resolves #701.
2018-03-22 16:27:28 -07:00
Pat Gavlin 58300f9ee7
Add support for service-managed stacks. (#1067)
These changes add the API types and cloud backend code necessary to
interact with service-managed stacks (i.e. stacks that do not have
PPC-managed deployments). The bulk of these changes are unremarkable:
the API types are straightforward, as are most of the interactions with
the new APIs. The trickiest bits are token and log management.

During an update to a managed stack, the CLI must continually renew the
token used to authorize the operations on that stack that comprise the
update. Once a token has been renewed, the old token should be
discarded. The CLI supports this by running a goroutine that is
responsible for both periodically renewing the token for an update and
servicing requests for the token itself from the rest of the backend.

In addition to token renewal, log output must be captured and uploaded
to the service during an update to a managed stack. Implementing this in
a reasonable fashion required a bit of refactoring in order to reuse
what already exists for the local backend. Each event-specific `Display`
function was replaced with an equivalent `Render` function that returns
a string rather than writing to a stream. This approach was chosen
primarily to avoid dealing with sheared colorization tags, which would
otherwise require clients to fuse log lines before colorizing. We could
take that approach in the future.
2018-03-22 10:42:43 -07:00
Pat Gavlin 7941062d4e
Merge pull request #1070 from pulumi/CloudClient
Extract a Pulumi API client.
2018-03-21 19:16:39 -07:00
Pat Gavlin e884c63104 Extract a Pulumi API client.
These changes refactor direct interactions with the Pulumi API out of
the cloud backend and into a subpackage, `pkg/backend/cloud/client`.
This package exposes a slightly higher-level API that takes care of
calculating paths, performing HTTP calls, and occasionally wrapping
multiple physical calls into a single logical call (notably the creation
of an update and the upload of its program).

This is primarily intended as preparation for some of the changes
suggested in the feedback for #1067.
2018-03-21 16:45:54 -07:00
Pat Gavlin a23b10a9bf
Update the copyright end date to 2018. (#1068)
Just what it says on the tin.
2018-03-21 12:43:21 -07:00
Chris Smith 3d8b7d8e44
Update updates.go (#1061)
We needed to have two types of `UpdateProgramRequest` to serve both newer shapes of Pulumi configuration values as well as the older, untyped version. (The original change was supporting the `ConfigValue` type, which had a flag to indiciate if the configuration value was encrypted or not.)

Now that LM has been migrated to the M10 bits https://github.com/pulumi/home/issues/168 , we can remove this type. (The PR to remove existing references in the `pulumi-service` repo is https://github.com/pulumi/pulumi-service/pull/957.)
2018-03-20 12:06:26 -07:00
joeduffy 7162f6ea52 Publish proper pre-release PyPI packages
The semantic versions we were using for pre-release PyPI packages wasn't
quite right.  We had been using local version identifiers, a la +, rather
than proper pre-release tags, which means that version specifications like
`pulumi==0.11.0` will match `0.11.0+dev.1521506136.g7f043fd.dirty`, in
addition to just `0.11.0`.  This is clearly not what we want.

This change moves us over to proper alpha and release candidate versions,
as specified in https://www.python.org/dev/peps/pep-0440/#pre-releases.
Namely, any `x.y.z-dev-123456789-abcdef` version will get translated into
an alpha `x.y.za12345679-abcdef`, and any `x.y.z-rc1` will get translated
into a proper release candidate `x.y.zrc1` version number.
2018-03-19 18:18:25 -07:00
joeduffy c50899aca3 Add some TODO refs to pulumi/pulumi#1063 2018-03-19 18:17:57 -07:00
Matt Ellis a3369d3cbc Fix make_release.sh when run from outside scripts directory 2018-03-19 14:24:52 -07:00
Matt Ellis 38ec631753
Merge pull request #1056 from pulumi/change-version-number
Adopt new version strategy
2018-03-19 13:25:12 -07:00
Joe Duffy abbac13655
Assume --remote when --cloud-url is set (#1060)
If you use --cloud-url, as in

    $ pulumi stack init foo --cloud-url https://x.io

we would silently fall back to logic that creates local stacks.

I realize all of this will get better with the new stack identity
model, however in the meantime, let's infer that the user wanted
--remote when --cloud-url is non-"".
2018-03-18 12:44:00 -07:00
CyrusNajmabadi d719e7966e
Only avoid running transformations on outputs we truly do not have values for. (#921) 2018-03-18 00:15:22 -07:00
joeduffy 094c877e32 Add Python language host to the SDK 2018-03-17 10:41:37 -07:00
Matt Ellis e46a665ce4 Add get-version.cmd and use it
Port the .sh script to powershell and use it on Windows.
2018-03-16 16:36:27 -07:00
Matt Ellis 642ee91065 Advise about --plaintext in config warning message
When run without a `--plaintext` or `--secret` argument, `pulumi
config` warns that the value is stored unecrypted and that you can
pass `--secret` to encrypt it. Now, we also mention that `--plaintext`
can be pased explicity on the command line to avoid the warning.

Fixes #752
2018-03-16 12:07:03 -07:00
Joe Duffy 1a475aeb38
Implement Python invoke RPC (#1054)
Implement Python invoke RPC

This change implements the invoke function for resource provider
RPCs.  This is required to support a customer scenario.

There are a few other minor updates:

* Rename pulumi.export to pulumi.output.

* Change register_resource to, like invoke, return the resulting
  object/dictionary, instead of the set_outputs function.

* Initialize the monitor/engine RPC connections to None when not
  attached to the engine, thus ensuring good error messages.

* Fix Python project/stack metadata
2018-03-16 08:39:24 -07:00
Matt Ellis 5c4a31f692 Adopt new version strategy
Our previous strategy of just using `git describe --tags --dirty` to
compute a version caused issues. The major one was that since version
sort lexigrapically, git's strategy of having a commit count without
leading zeros lead to cases where 0.11.0-dev-9 was "newer than"
0.11.0-dev-10 which is not what you want at all.

With this change, we compute a version by first seeing if the commit
is tagged, and if so, we use that tag. Otherwise, we take the closest
tag and to it append the unix timestamp of the commit and then append
a git hash.

Because we use the commit timestamp, things will sort correctly again.

Part of pulumi/home#174
2018-03-15 18:06:04 -07:00
Chris Smith 441f4566c7
Fix panic when getting logs for older stacks (#1053)
* Fix panic when getting logs for older stacks

* Make GetChild return a tuple

* Update tests; add test
2018-03-15 13:26:43 -07:00
Matt Ellis cd64462a9d Export display helper functions
This allows some upstack components that need to consume engine events
use the common display logic we have here.
2018-03-14 14:02:30 -07:00
Joe Duffy 41127c55e9
Add basic config tests (#1049)
This adds a basic config test, for both Node.js and Python runtimes,
that simply reads back and checks configuration and secret values.
2018-03-14 12:24:49 -07:00
Justin Van Patten 31d572e4db
Remove unnecessary os.Stat call (#1048)
Just a nit: It's possible (though, unlikely) that the repo file is
deleted between the call to `os.Stat` and `ioutil.ReadFile`. Instead,
just try to read the file -- if the file doesn't exist,
`ioutil.ReadFile` will return an error that works the same with
`os.IsNotExist(err)` as the error returned from `os.Stat`.
2018-03-14 10:00:15 -07:00
Matt Ellis 05d90a244c Pass legacy config mapping from nodejs langhost
We need to support the current version of the nodejs language host
running programs that use older version of @pulumi/pulumi where the
runtime expected config keys to look like
`<package>:config:<name>`. In the language host we actually did the
transformation from the new format to the old one, for compatability
reasons but we then droped the transfomed value on the floor.
2018-03-13 23:16:38 -07:00
Justin Van Patten c7985ed296
Support offline template descriptions (#1044)
Note: This is a minor issue that I didn't get to for M11 that isn't
required for M11 and would be fine merging for post-M11.

When you specify a template name explicitly (e.g.
`pulumi new typescript`), we'll try to download the template tarball
without first downloading the JSON list of available templates. The JSON
includes a description used when replacing the `${DESCRIPTION}` string
in template files. Since we didn't download the JSON, we won't have a
description, so we fallback to a default value (`"A Pulumi project."`).
This also happens when specifying `--offline` to use an existing
template under `~/.pulumi/templates`; we won't have a description for
the template, so we fallback to a default description. The fallback
value happens to be the same as the description for each of our current
templates, so noone will currently notice an issue.

For M11, I included initial support for a template manifest file where
the description (and any future metadata) could be stored, but didn't go
as far as actually reading the file.

This change makes it so the CLI actually reads the description from the
manifest file (if it exists), otherwise falling back to the default
value as is done currently. Some minor related cleanup is included in
this change.
2018-03-13 16:09:25 -07:00
CyrusNajmabadi 134941dd22
Improve error text when lambda functions are involved. (#1046) 2018-03-13 13:21:07 -07:00
CyrusNajmabadi 304af9cdf1
Split closure serialization into separate files containing the different concerns. (#1045)
The four concerns are:

    parsing a v8 function string so we can figure out captured variables.
    walkgin the function/object graph producing the graph we will serialize.
    rewriting constructors and methods so that 'super' works.
    serializing graph to text.
2018-03-12 18:12:49 -07:00
Joe Duffy 5924f6b8c3
Ensure destroy plugins are present (#1043)
This change uses the prior checkpoint's deployment manifest to pre-
populate all plugins required to complete the destroy operation.  This
allows for subsequent attempts to load a resource's plugin to match the
already-loaded version.  This approach obviously doesn't work in a
hypothetical future world where plugins for the same resource provider
are loaded side-by-side, but we already know that.
2018-03-12 16:27:39 -07:00
CyrusNajmabadi 5b244dbdb1
Use a class for Output serialization to ensure that .apply exists on it. (#1040)
Also, rename/cleanup a bunch of serialization code.

Also, generate better environment names in the serialized closure code. Thsi code should be much easier to make sense of as hte names will better track to the original names in the user code.

Also, dedupe simple non-capturing functions. This helps ensure we don't spit out N copies of __awaiter (one per file it is declared in).
2018-03-12 16:27:00 -07:00
Joe Duffy fc3908b853
Fix two DST bugs in logs test (#1042)
This fixes two different DST bugs in the logs test, one of which
led to the failure in pulumi/pulumi#1041:

1) The assertion was using ANSIC formatting, which does not contain
   a time-zone, and because we are now in DST, the resulting time
   didn't parse and format in a round-trippable way.  Instead, let's
   use RFC3339, and let's be explicit about the timezone.

2) The parseSince("1m30s") would in theory fail if the DST changed
   at just the right moment, since the reference time could end up
   different from the reference time that the test is using.  Let's
   expose the reference time to the caller, so that they may decide
   how to deal with these situations, and let's use UTC here.
2018-03-12 15:49:52 -07:00
CyrusNajmabadi 4e651b0428
Do not hardcode specialized knowledge about resources in closure serialization. (#1039) 2018-03-12 13:47:13 -07:00
Justin Van Patten aa940b40dc
Cleanup pulumi new flag descriptions (#1036)
- Use `templates` instead of `releases`
- Fix typo
2018-03-12 11:22:32 -07:00
CyrusNajmabadi 7e14a09b3b
Do not build sidebranch. (#1033) 2018-03-11 00:28:00 -08:00
CyrusNajmabadi 850130e30f
Capture modules through normal value capture. (#1030) 2018-03-11 00:11:53 -08:00
Matt Ellis dc57119206 Only replace secret text if it is longer than 2 characters
This is inline with what Travis does. Otherwise, for very short
secrets our regex based approach will throw `[secret]` all over the
place.
2018-03-10 13:03:46 -08:00
Matt Ellis 936cab0c22 Add a version property to checkpoints
This takes the existing `apitype.Checkpoint` type and renames it to
`apitype.CheckpointV1` locking in the shape. In addition, we introduce
a `apitype.VersionedCheckpoint` type, which holds a version number and
a json document representing a checkpoint at that version. Now, when
reading a checkpoint, the CLI can determine if it's in a format it
understands, and fail gracefully if it is not.

While the CLI understands the older checkpoint version, it always
writes the newest version format, meaning that if you manage a
fire-and-forget stack with this version of the CLI, it will be
un-readable by previous versions.

Stacks managed by Pulumi.com are not impacted by this change.

Fixes: #887
2018-03-10 13:03:05 -08:00
Sean Gillespie 703a954839
Improve error messages output by the CLI (#1011)
* Improve error messages output by the CLI

This fixes a couple known issues with the way that we present errors
from the Pulumi CLI:
    1. Any errors from RPC endpoints were bubbling up as they were to
    the top-level, which was unfortunate because they contained
    RPC-specific noise that we don't want to present to the user. This
    commit unwraps errors from resource providers.
    2. The "catastrophic error" message often got printed twice
    3. Fatal errors are often printed twice, because our CLI top-level
    prints out the fatal error that it receives before exiting. A lot of
    the time this error has already been printed.
    4. Errors were prefixed by PU####.

* Feedback: Omit the 'catastrophic' error message and use a less verbose error message as the final error

* Code review feedback: interpretRPCError -> resourceStateAndError

* Code review feedback: deleting some commented-out code, error capitalization

* Cleanup after rebase
2018-03-09 15:43:16 -08:00
Justin Van Patten 8906731315
Adds a pulumi new command to scaffold a project (#1008)
This adds a `pulumi new` command which makes it easy to quickly
automatically create the handful of needed files to get started building
an empty Pulumi project.

Usage:

```
$ pulumi new typescript
```

Or you can leave off the template name, and it will ask you to choose
one:

```
$ pulumi new
Please choose a template:
> javascript
  python
  typescript
```
2018-03-09 15:27:55 -08:00
joeduffy f071329238 Update PyPI publish source 2018-03-09 15:27:16 -08:00
Matt Ellis 344d9b4424
Merge pull request #1025 from pulumi/SerializePluginLoads
Serialize plugin loads.
2018-03-09 15:20:42 -08:00
Joe Duffy 98aaf12cdf
Reenable Pylint (#1024)
This change uses virtualenv to insulate us from platform differences
in our building of the Python SDK, and to create an isolated Python 2
environment.  This includes meaning we don't need to worry about the
specific location and behavior of Pylint.  I *think* this will work
no matter whether it's Mac, Ubuntu, ArchLinux, Windows, and so on.

We do install to the --user directory in the install target using
`pip install -e`, however, which enables the machine-wide symlinking
that we need to support various workflows.

This fixes pulumi/pulumi#1007.
2018-03-09 15:11:37 -08:00
Matt Ellis c1a06b14cc
Merge pull request #1002 from pulumi/more-display-refactoring
Make events a little richer; hide secrets from the output
2018-03-09 14:39:42 -08:00