* Add a list of in-flight operations to the deployment This commit augments 'DeploymentV2' with a list of operations that are currently in flight. This information is used by the engine to keep track of whether or not a particular deployment is in a valid state. The SnapshotManager is responsible for inserting and removing operations from the in-flight operation list. When the engine registers an intent to perform an operation, SnapshotManager inserts an Operation into this list and saves it to the snapshot. When an operation completes, the SnapshotManager removes it from the snapshot. From this, the engine can infer that if it ever sees a deployment with pending operations, the Pulumi CLI must have crashed or otherwise abnormally terminated before seeing whether or not an operation completed successfully. To remedy this state, this commit also adds code to 'pulumi stack import' that clears all pending operations from a deployment, as well as code to plan generation that will reject any deployments that have pending operations present. At the CLI level, if we see that we are in a state where pending operations were in-flight when the engine died, we'll issue a human-friendly error message that indicates which resources are in a bad state and how to recover their stack. * CR: Multi-line string literals, renaming in-flight -> pending * CR: Add enum to apitype for operation type, also name status -> type for clarity * Fix the yaml type * Fix missed renames * Add implementation for lifecycle_test.go * Rebase against master
60 lines
2 KiB
Go
60 lines
2 KiB
Go
package cmd
|
|
|
|
import (
|
|
"bufio"
|
|
"bytes"
|
|
"fmt"
|
|
"io"
|
|
|
|
"github.com/pulumi/pulumi/pkg/diag"
|
|
"github.com/pulumi/pulumi/pkg/resource/deploy"
|
|
"github.com/pulumi/pulumi/pkg/util/cmdutil"
|
|
"github.com/pulumi/pulumi/pkg/util/contract"
|
|
)
|
|
|
|
// PrintEngineError optionally provides a place for the CLI to provide human-friendly error
|
|
// messages for messages that can happen during normal engine operation.
|
|
func PrintEngineError(err error) error {
|
|
if err == nil {
|
|
return nil
|
|
}
|
|
|
|
switch e := err.(type) {
|
|
case deploy.PlanPendingOperationsError:
|
|
printPendingOperationsError(e)
|
|
return fmt.Errorf("refusing to proceed")
|
|
default:
|
|
return err
|
|
}
|
|
}
|
|
|
|
func printPendingOperationsError(e deploy.PlanPendingOperationsError) {
|
|
var buf bytes.Buffer
|
|
writer := bufio.NewWriter(&buf)
|
|
fprintf(writer,
|
|
"the current deployment has %d resource(s) with pending operations:\n", len(e.Operations))
|
|
|
|
for _, op := range e.Operations {
|
|
fprintf(writer, " * %s, interrupted while %s\n", op.Resource.URN, op.Type)
|
|
}
|
|
|
|
fprintf(writer, `
|
|
These resources are in an unknown state because the Pulumi CLI was interrupted while
|
|
waiting for changes to these resources to complete. You should confirm whether or not the
|
|
operations listed completed successfully by checking the state of the appropriate provider.
|
|
For example, if you are using AWS, you can confirm using the AWS Console.
|
|
|
|
Once you have confirmed the status of the interrupted operations, you can repair your stack
|
|
using 'pulumi stack export' to export your stack to a file. For each operation that succeeded,
|
|
remove that operation from the "pending_operations" section of the file. Once this is complete,
|
|
use 'pulumi stack import' to import the repaired stack.`)
|
|
contract.IgnoreError(writer.Flush())
|
|
|
|
cmdutil.Diag().Errorf(diag.RawMessage("" /*urn*/, buf.String()))
|
|
}
|
|
|
|
// Quick and dirty utility function for printing to writers that we know will never fail.
|
|
func fprintf(writer io.Writer, msg string, args ...interface{}) {
|
|
_, err := fmt.Fprintf(writer, msg, args...)
|
|
contract.IgnoreError(err)
|
|
}
|