Remove UpdateOptions.ShowConfig
The engine now unconditionally emits a new type of event, a PreludeEvent, which contains the configuration for a stack as well as an indication if the stack is being previewed or updated. The responsibility for interpreting the --show-config flag on the command line is now handled by the CLI, which uses this to decide if it should print the configuration or not, and then writes the "Previewing changes" or "Deploying chanages" header.
This commit is contained in:
parent
7e84a83f33
commit
4e2f94df95
|
@ -68,13 +68,13 @@ func newDestroyCmd() *cobra.Command {
|
|||
Analyzers: analyzers,
|
||||
DryRun: preview,
|
||||
Parallel: parallel,
|
||||
ShowConfig: showConfig,
|
||||
ShowReplacementSteps: showReplacementSteps,
|
||||
ShowSames: showSames,
|
||||
Summary: summary,
|
||||
Debug: debug,
|
||||
}, backend.DisplayOptions{
|
||||
Color: color.Colorization(),
|
||||
Color: color.Colorization(),
|
||||
ShowConfig: showConfig,
|
||||
})
|
||||
}),
|
||||
}
|
||||
|
|
|
@ -56,13 +56,13 @@ func newPreviewCmd() *cobra.Command {
|
|||
Analyzers: analyzers,
|
||||
DryRun: true,
|
||||
Parallel: parallel,
|
||||
ShowConfig: showConfig,
|
||||
ShowReplacementSteps: showReplacementSteps,
|
||||
ShowSames: showSames,
|
||||
Summary: summary,
|
||||
Debug: debug,
|
||||
}, backend.DisplayOptions{
|
||||
Color: color.Colorization(),
|
||||
Color: color.Colorization(),
|
||||
ShowConfig: showConfig,
|
||||
})
|
||||
}),
|
||||
}
|
||||
|
|
|
@ -64,13 +64,13 @@ func newUpdateCmd() *cobra.Command {
|
|||
Analyzers: analyzers,
|
||||
DryRun: preview,
|
||||
Parallel: parallel,
|
||||
ShowConfig: showConfig,
|
||||
ShowReplacementSteps: showReplacementSteps,
|
||||
ShowSames: showSames,
|
||||
Summary: summary,
|
||||
Debug: debug,
|
||||
}, backend.DisplayOptions{
|
||||
Color: color.Colorization(),
|
||||
Color: color.Colorization(),
|
||||
ShowConfig: showConfig,
|
||||
})
|
||||
}),
|
||||
}
|
||||
|
|
|
@ -589,7 +589,7 @@ func (b *cloudBackend) makeProgramUpdateRequest(stackName tokens.QName, proj *wo
|
|||
Color: colors.Raw, // force raw colorization, we handle colorization in the CLI
|
||||
DryRun: opts.DryRun,
|
||||
Parallel: opts.Parallel,
|
||||
ShowConfig: opts.ShowConfig,
|
||||
ShowConfig: false, // This is a legacy option now, the engine will always emit config information
|
||||
ShowReplacementSteps: opts.ShowReplacementSteps,
|
||||
ShowSames: opts.ShowSames,
|
||||
},
|
||||
|
|
|
@ -6,5 +6,6 @@ import "github.com/pulumi/pulumi/pkg/diag/colors"
|
|||
|
||||
// DisplayOptions controls how the output of events are rendered
|
||||
type DisplayOptions struct {
|
||||
Color colors.Colorization // colorization to apply to events
|
||||
Color colors.Colorization // colorization to apply to events
|
||||
ShowConfig bool // true if we should show configuration information before updating or previewing
|
||||
}
|
||||
|
|
|
@ -6,9 +6,11 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"sort"
|
||||
|
||||
"github.com/pulumi/pulumi/pkg/backend"
|
||||
"github.com/pulumi/pulumi/pkg/diag"
|
||||
"github.com/pulumi/pulumi/pkg/diag/colors"
|
||||
"github.com/pulumi/pulumi/pkg/engine"
|
||||
"github.com/pulumi/pulumi/pkg/util/cmdutil"
|
||||
"github.com/pulumi/pulumi/pkg/util/contract"
|
||||
|
@ -38,6 +40,8 @@ func displayEvents(action string,
|
|||
switch event.Type {
|
||||
case engine.CancelEvent:
|
||||
return
|
||||
case engine.PreludeEvent:
|
||||
displayPreludeEvent(os.Stdout, event.Payload.(engine.PreludeEventPayload), opts)
|
||||
case engine.StdoutColorEvent:
|
||||
payload := event.Payload.(engine.StdoutEventPayload)
|
||||
out = os.Stdout
|
||||
|
@ -62,3 +66,26 @@ func displayEvents(action string,
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// nolint: gas
|
||||
func displayPreludeEvent(out io.Writer, event engine.PreludeEventPayload, opts backend.DisplayOptions) {
|
||||
if opts.ShowConfig {
|
||||
fmt.Fprint(out, opts.Color.Colorize(fmt.Sprintf("%vConfiguration:%v\n", colors.SpecUnimportant, colors.Reset)))
|
||||
|
||||
var keys []string
|
||||
for key := range event.Config {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
for _, key := range keys {
|
||||
fmt.Fprintf(out, " %v: %v\n", key, event.Config[key])
|
||||
}
|
||||
}
|
||||
|
||||
action := "Previewing"
|
||||
if !event.IsPreview {
|
||||
action = "Performing"
|
||||
}
|
||||
|
||||
fmt.Fprint(out, opts.Color.Colorize(fmt.Sprintf("%v%v changes:%v\n", colors.SpecUnimportant, action, colors.Reset)))
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ type UpdateOptions struct {
|
|||
Analyzers []string // an optional set of analyzers to run as part of this deployment.
|
||||
DryRun bool // true if we should just print the plan without performing it.
|
||||
Parallel int // the degree of parallelism for resource operations (<=1 for serial).
|
||||
ShowConfig bool // true to show the configuration variables being used.
|
||||
ShowReplacementSteps bool // true to show the replacement steps in the plan.
|
||||
ShowSames bool // true to show the resources that aren't updated in addition to updates.
|
||||
Summary bool // true if we should only summarize resources and operations.
|
||||
|
@ -88,10 +87,7 @@ func deployLatest(info *planContext, opts deployOptions) (ResourceChanges, error
|
|||
}
|
||||
} else {
|
||||
// Otherwise, we will actually deploy the latest bits.
|
||||
var header bytes.Buffer
|
||||
printPrelude(&header, result, false)
|
||||
header.WriteString(fmt.Sprintf("%vPerforming changes:%v\n", colors.SpecUnimportant, colors.Reset))
|
||||
opts.Events <- stdOutEventWithColor(&header)
|
||||
opts.Events <- preludeEvent(opts.DryRun, result.Info.Update.GetTarget().Config)
|
||||
|
||||
// Walk the plan, reporting progress and executing the actual operations as we go.
|
||||
start := time.Now()
|
||||
|
|
|
@ -7,6 +7,8 @@ import (
|
|||
|
||||
"github.com/pulumi/pulumi/pkg/diag"
|
||||
"github.com/pulumi/pulumi/pkg/diag/colors"
|
||||
"github.com/pulumi/pulumi/pkg/resource/config"
|
||||
"github.com/pulumi/pulumi/pkg/util/contract"
|
||||
)
|
||||
|
||||
// Event represents an event generated by the engine during an operation. The underlying
|
||||
|
@ -23,6 +25,7 @@ const (
|
|||
CancelEvent EventType = "cancel"
|
||||
StdoutColorEvent EventType = "stdoutcolor"
|
||||
DiagEvent EventType = "diag"
|
||||
PreludeEvent EventType = "prelude"
|
||||
)
|
||||
|
||||
func cancelEvent() Event {
|
||||
|
@ -41,6 +44,29 @@ type StdoutEventPayload struct {
|
|||
Color colors.Colorization
|
||||
}
|
||||
|
||||
type PreludeEventPayload struct {
|
||||
IsPreview bool // true if this prelude is for a plan operation
|
||||
Config map[string]string // the keys and values for config. For encrypted config, the values may be blinded
|
||||
}
|
||||
|
||||
func preludeEvent(isPreview bool, cfg config.Map) Event {
|
||||
configStringMap := make(map[string]string, len(cfg))
|
||||
for k, v := range cfg {
|
||||
keyString := k.String()
|
||||
valueString, err := v.Value(config.NewBlindingDecrypter())
|
||||
contract.AssertNoError(err)
|
||||
configStringMap[keyString] = valueString
|
||||
}
|
||||
|
||||
return Event{
|
||||
Type: PreludeEvent,
|
||||
Payload: PreludeEventPayload{
|
||||
IsPreview: isPreview,
|
||||
Config: configStringMap,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func stdOutEventWithColor(s fmt.Stringer) Event {
|
||||
return Event{
|
||||
Type: StdoutColorEvent,
|
||||
|
|
|
@ -18,7 +18,6 @@ import (
|
|||
"github.com/pulumi/pulumi/pkg/diag"
|
||||
"github.com/pulumi/pulumi/pkg/diag/colors"
|
||||
"github.com/pulumi/pulumi/pkg/resource"
|
||||
"github.com/pulumi/pulumi/pkg/resource/config"
|
||||
"github.com/pulumi/pulumi/pkg/resource/deploy"
|
||||
"github.com/pulumi/pulumi/pkg/resource/plugin"
|
||||
"github.com/pulumi/pulumi/pkg/tokens"
|
||||
|
@ -184,14 +183,9 @@ func (res *planResult) Close() error {
|
|||
|
||||
// printPlan prints the plan's result to the plan's Options.Events stream.
|
||||
func printPlan(result *planResult) (ResourceChanges, error) {
|
||||
// First print config/unchanged/etc. if necessary.
|
||||
var prelude bytes.Buffer
|
||||
printPrelude(&prelude, result, true)
|
||||
|
||||
// Now walk the plan's steps and and pretty-print them out.
|
||||
prelude.WriteString(fmt.Sprintf("%vPreviewing changes:%v\n", colors.SpecUnimportant, colors.Reset))
|
||||
result.Options.Events <- stdOutEventWithColor(&prelude)
|
||||
result.Options.Events <- preludeEvent(result.Options.DryRun, result.Info.Update.GetTarget().Config)
|
||||
|
||||
// Walk the plan's steps and and pretty-print them out.
|
||||
actions := newPreviewActions(result.Options)
|
||||
_, _, _, err := result.Walk(actions, true)
|
||||
if err != nil {
|
||||
|
@ -237,29 +231,6 @@ func isRootStack(step deploy.Step) bool {
|
|||
return step.URN().Type() == resource.RootStackType
|
||||
}
|
||||
|
||||
func printPrelude(b *bytes.Buffer, result *planResult, planning bool) {
|
||||
// If there are configuration variables, show them.
|
||||
if result.Options.ShowConfig {
|
||||
printConfig(b, result.Info.Update.GetTarget().Config)
|
||||
}
|
||||
}
|
||||
|
||||
func printConfig(b *bytes.Buffer, cfg config.Map) {
|
||||
b.WriteString(fmt.Sprintf("%vConfiguration:%v\n", colors.SpecUnimportant, colors.Reset))
|
||||
if cfg != nil {
|
||||
var keys config.KeyArray
|
||||
for key := range cfg {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
sort.Sort(keys)
|
||||
for _, key := range keys {
|
||||
v, err := cfg[key].Value(config.NewBlindingDecrypter())
|
||||
contract.AssertNoError(err)
|
||||
b.WriteString(fmt.Sprintf(" %v: %v\n", key, v))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// printChangeSummary writes summary informatiom about the resoures changed to the provided buffer.
|
||||
// Returns the total number of resources changed regardless of operation type.
|
||||
func printChangeSummary(b *bytes.Buffer, changes ResourceChanges, preview bool) int {
|
||||
|
|
Loading…
Reference in a new issue