Always render PPs even if there are diagnostic events (#3796)

This commit is contained in:
Erin Krengel 2020-01-24 14:33:31 -08:00 committed by GitHub
parent bf3dc1cd0c
commit f0172990b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 30 deletions

View file

@ -8,6 +8,8 @@ CHANGELOG
- Fix a buggy assertion in the Go SDK.
[#3794](https://github.com/pulumi/pulumi/pull/3794)
- Fix rendering of Policy Packs to ensure they are always displayed.
## 1.9.0 (2020-01-22)
- Publish python types for PEP 561
[#3704](https://github.com/pulumi/pulumi/pull/3704)

View file

@ -98,7 +98,7 @@ func RenderDiffEvent(action apitype.UpdateKind, event engine.Event,
case engine.PreludeEvent:
return renderPreludeEvent(event.Payload.(engine.PreludeEventPayload), opts)
case engine.SummaryEvent:
return renderSummaryEvent(action, event.Payload.(engine.SummaryEventPayload), opts)
return renderSummaryEvent(action, event.Payload.(engine.SummaryEventPayload), false /* wroteDiagnosticHeader */, opts)
case engine.StdoutColorEvent:
return renderStdoutColorEvent(event.Payload.(engine.StdoutEventPayload), opts)
@ -137,10 +137,20 @@ func renderStdoutColorEvent(payload engine.StdoutEventPayload, opts Options) str
return opts.Color.Colorize(payload.Message)
}
func renderSummaryEvent(action apitype.UpdateKind, event engine.SummaryEventPayload, opts Options) string {
func renderSummaryEvent(action apitype.UpdateKind, event engine.SummaryEventPayload,
wroteDiagnosticHeader bool, opts Options) string {
changes := event.ResourceChanges
out := &bytes.Buffer{}
// If this is a failed preview, we only render the Policy Packs that ran. This is because rendering the summary
// for a failed preview may be surprising/misleading, as it does not describe the totality of the proposed changes
// (as the preview may have aborted when the error occurred).
if event.IsPreview && wroteDiagnosticHeader {
renderPolicyPacks(out, event.PolicyPacks, opts)
return out.String()
}
fprintIgnoreError(out, opts.Color.Colorize(
fmt.Sprintf("%sResources:%s\n", colors.SpecHeadline, colors.Reset)))
@ -183,29 +193,7 @@ func renderSummaryEvent(action apitype.UpdateKind, event engine.SummaryEventPayl
}
// Print policy packs loaded. Data is rendered as a table of {policy-pack-name, version}.
if len(event.PolicyPacks) > 0 {
fprintIgnoreError(out, opts.Color.Colorize(fmt.Sprintf("\n%sPolicy Packs run:%s\n",
colors.SpecHeadline, colors.Reset)))
// Calculate column width for the `name` column
const nameColHeader = "Name"
maxNameLen := len(nameColHeader)
for pp := range event.PolicyPacks {
if l := len(pp); l > maxNameLen {
maxNameLen = l
}
}
// Print the column headers and the policy packs.
fprintIgnoreError(out, opts.Color.Colorize(
fmt.Sprintf(" %s%s%s\n",
columnHeader(nameColHeader), messagePadding(nameColHeader, maxNameLen, 2),
columnHeader("Version"))))
for pp, ver := range event.PolicyPacks {
fprintIgnoreError(out, opts.Color.Colorize(
fmt.Sprintf(" %s%s%s\n", pp, messagePadding(pp, maxNameLen, 2), ver)))
}
}
renderPolicyPacks(out, event.PolicyPacks, opts)
summaryPieces := []string{}
if changeKindCount >= 2 {
@ -247,6 +235,33 @@ func renderSummaryEvent(action apitype.UpdateKind, event engine.SummaryEventPayl
return out.String()
}
func renderPolicyPacks(out io.Writer, policyPacks map[string]string, opts Options) {
if len(policyPacks) == 0 {
return
}
fprintIgnoreError(out, opts.Color.Colorize(fmt.Sprintf("\n%sPolicy Packs run:%s\n",
colors.SpecHeadline, colors.Reset)))
// Calculate column width for the `name` column
const nameColHeader = "Name"
maxNameLen := len(nameColHeader)
for pp := range policyPacks {
if l := len(pp); l > maxNameLen {
maxNameLen = l
}
}
// Print the column headers and the policy packs.
fprintIgnoreError(out, opts.Color.Colorize(
fmt.Sprintf(" %s%s%s\n",
columnHeader(nameColHeader), messagePadding(nameColHeader, maxNameLen, 2),
columnHeader("Version"))))
for pp, ver := range policyPacks {
fprintIgnoreError(out, opts.Color.Colorize(
fmt.Sprintf(" %s%s%s\n", pp, messagePadding(pp, maxNameLen, 2), ver)))
}
}
func renderPreludeEvent(event engine.PreludeEventPayload, opts Options) string {
// Only if we have been instructed to show configuration values will we print anything during the prelude.
if !opts.ShowConfig {

View file

@ -751,7 +751,7 @@ func (display *ProgressDisplay) processEndSteps() {
display.writeBlankLine()
}
msg := renderSummaryEvent(display.action, *display.summaryEventPayload, display.opts)
msg := renderSummaryEvent(display.action, *display.summaryEventPayload, wroteDiagnosticHeader, display.opts)
display.writeSimpleMessage(msg)
}
}

View file

@ -225,7 +225,14 @@ func printPlan(ctx *Context, planResult *planResult, dryRun bool, policies map[s
// Walk the plan's steps and and pretty-print them out.
actions := newPlanActions(planResult.Options)
if res := planResult.Walk(ctx, actions, true); res != nil {
res := planResult.Walk(ctx, actions, true)
// Emit an event with a summary of operation counts.
changes := ResourceChanges(actions.Ops)
planResult.Options.Events.previewSummaryEvent(changes, policies)
if res != nil {
if res.IsBail() {
return nil, res
}
@ -233,9 +240,6 @@ func printPlan(ctx *Context, planResult *planResult, dryRun bool, policies map[s
return nil, result.Error("an error occurred while advancing the preview")
}
// Emit an event with a summary of operation counts.
changes := ResourceChanges(actions.Ops)
planResult.Options.Events.previewSummaryEvent(changes, policies)
return changes, nil
}