Elide diffs in internal properties (#2543)

Various providers use properties that begin with "__" to represent
internal metadata that should not be presented to the user. These
changes look for such properties and elide them when displaying diffs.
This commit is contained in:
Pat Gavlin 2019-03-11 18:01:48 -07:00 committed by GitHub
parent 06d4268137
commit d14f47b162
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 9 deletions

View file

@ -10,6 +10,7 @@
Instead, instructions are printed indicating that `pulumi up` can be used to deploy the project.
- Differences between the state of a refreshed resource and the state described in a Pulumi program are now properly
detected when using newer providers.
- Differences between a resource's provider-internal properties are no longer displayed in the CLI.
## 0.17.1 (Released March 6, 2019)

View file

@ -31,6 +31,12 @@ import (
"github.com/pulumi/pulumi/pkg/util/contract"
)
// IsInternalPropertyKey returns true if the given property key is an internal key that should not be displayed to
// users.
func IsInternalPropertyKey(key resource.PropertyKey) bool {
return strings.HasPrefix(string(key), "__")
}
// GetIndent computes a step's parent indentation.
func GetIndent(step StepEventMetadata, seen map[resource.URN]StepEventMetadata) int {
indent := 0
@ -224,7 +230,7 @@ func printObject(
// Now print out the values intelligently based on the type.
for _, k := range keys {
if v := props[k]; shouldPrintPropertyValue(v, planning) {
if v := props[k]; !IsInternalPropertyKey(k) && shouldPrintPropertyValue(v, planning) {
printPropertyTitle(b, string(k), maxkey, indent, op, prefix)
printPropertyValue(b, v, planning, indent, op, prefix, debug)
}
@ -273,7 +279,7 @@ func GetResourceOutputsPropertiesString(
// the new outputs, we want to print the diffs.
var outputDiff *resource.ObjectDiff
if step.Old != nil && step.Old.Outputs != nil {
outputDiff = step.Old.Outputs.Diff(outs)
outputDiff = step.Old.Outputs.Diff(outs, IsInternalPropertyKey)
}
var keys []resource.PropertyKey
@ -292,10 +298,10 @@ func GetResourceOutputsPropertiesString(
// - a property with the same key is not present in the inputs
// - the property that is present in the inputs is different
// - we are doing a refresh, in which case we always want to show state differences
if outputDiff != nil || shouldPrintPropertyValue(out, true) {
if outputDiff != nil || (!IsInternalPropertyKey(k) && shouldPrintPropertyValue(out, true)) {
print := true
if in, has := ins[k]; has && !refresh {
print = (out.Diff(in) != nil)
print = (out.Diff(in, IsInternalPropertyKey) != nil)
}
if print {
@ -451,7 +457,7 @@ func printOldNewDiffs(
planning bool, indent int, op deploy.StepOp, summary bool, debug bool) {
// Get the full diff structure between the two, and print it (recursively).
if diff := olds.Diff(news); diff != nil {
if diff := olds.Diff(news, IsInternalPropertyKey); diff != nil {
printObjectDiff(b, *diff, include, planning, indent, summary, debug)
} else {
// If there's no diff, report the op as Same - there's no diff to render

View file

@ -116,20 +116,36 @@ func (diff *ArrayDiff) Len() int {
return len
}
// IgnoreKeyFunc is the callback type for Diff's ignore option.
type IgnoreKeyFunc func(key PropertyKey) bool
// Diff returns a diffset by comparing the property map to another; it returns nil if there are no diffs.
func (props PropertyMap) Diff(other PropertyMap) *ObjectDiff {
func (props PropertyMap) Diff(other PropertyMap, ignoreKeys ...IgnoreKeyFunc) *ObjectDiff {
adds := make(PropertyMap)
deletes := make(PropertyMap)
sames := make(PropertyMap)
updates := make(map[PropertyKey]ValueDiff)
ignore := func(key PropertyKey) bool {
for _, ikf := range ignoreKeys {
if ikf(key) {
return true
}
}
return false
}
// First find any updates or deletes.
for k, old := range props {
if ignore(k) {
continue
}
if new, has := other[k]; has {
// If a new exists, use it; for output properties, however, ignore differences.
if new.IsOutput() {
sames[k] = old
} else if diff := old.Diff(new); diff != nil {
} else if diff := old.Diff(new, ignoreKeys...); diff != nil {
if !old.HasValue() {
adds[k] = new
} else if !new.HasValue() {
@ -148,6 +164,10 @@ func (props PropertyMap) Diff(other PropertyMap) *ObjectDiff {
// Next find any additions not in the old map.
for k, new := range other {
if ignore(k) {
continue
}
if _, has := props[k]; !has && new.HasValue() {
adds[k] = new
}
@ -166,7 +186,7 @@ func (props PropertyMap) Diff(other PropertyMap) *ObjectDiff {
}
// Diff returns a diff by comparing a single property value to another; it returns nil if there are no diffs.
func (v PropertyValue) Diff(other PropertyValue) *ValueDiff {
func (v PropertyValue) Diff(other PropertyValue, ignoreKeys ...IgnoreKeyFunc) *ValueDiff {
if v.IsArray() && other.IsArray() {
old := v.ArrayValue()
new := other.ArrayValue()
@ -208,7 +228,7 @@ func (v PropertyValue) Diff(other PropertyValue) *ValueDiff {
if v.IsObject() && other.IsObject() {
old := v.ObjectValue()
new := other.ObjectValue()
if diff := old.Diff(new); diff != nil {
if diff := old.Diff(new, ignoreKeys...); diff != nil {
return &ValueDiff{
Old: v,
New: other,