2018-05-22 19:43:36 +00:00
|
|
|
// Copyright 2016-2018, Pulumi Corporation.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
2017-02-24 03:03:22 +00:00
|
|
|
|
|
|
|
package resource
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sort"
|
2023-06-28 16:02:04 +00:00
|
|
|
|
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/common/slice"
|
2017-02-24 03:03:22 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ObjectDiff holds the results of diffing two object property maps.
|
|
|
|
type ObjectDiff struct {
|
|
|
|
Adds PropertyMap // properties in this map are created in the new.
|
|
|
|
Deletes PropertyMap // properties in this map are deleted from the new.
|
|
|
|
Sames PropertyMap // properties in this map are the same.
|
|
|
|
Updates map[PropertyKey]ValueDiff // properties in this map are changed in the new.
|
|
|
|
}
|
|
|
|
|
2017-03-03 00:16:18 +00:00
|
|
|
// Added returns true if the property 'k' has been added in the new property set.
|
|
|
|
func (diff *ObjectDiff) Added(k PropertyKey) bool {
|
2017-02-27 21:33:08 +00:00
|
|
|
_, has := diff.Adds[k]
|
|
|
|
return has
|
|
|
|
}
|
|
|
|
|
2017-03-03 00:16:18 +00:00
|
|
|
// Deleted returns true if the property 'k' has been deleted from the new property set.
|
|
|
|
func (diff *ObjectDiff) Deleted(k PropertyKey) bool {
|
2017-02-27 21:33:08 +00:00
|
|
|
_, has := diff.Deletes[k]
|
|
|
|
return has
|
|
|
|
}
|
|
|
|
|
2017-03-03 00:16:18 +00:00
|
|
|
// Updated returns true if the property 'k' has been changed between new and old property sets.
|
|
|
|
func (diff *ObjectDiff) Updated(k PropertyKey) bool {
|
2017-02-27 21:33:08 +00:00
|
|
|
_, has := diff.Updates[k]
|
|
|
|
return has
|
|
|
|
}
|
|
|
|
|
2017-03-03 00:16:18 +00:00
|
|
|
// Changed returns true if the property 'k' is known to be different between old and new.
|
|
|
|
func (diff *ObjectDiff) Changed(k PropertyKey) bool {
|
|
|
|
return diff.Added(k) || diff.Deleted(k) || diff.Updated(k)
|
2017-02-27 21:33:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Same returns true if the property 'k' is *not* known to be different; note that this isn't the same as looking up in
|
|
|
|
// the Sames map, because it is possible the key is simply missing altogether (as is the case for nulls).
|
|
|
|
func (diff *ObjectDiff) Same(k PropertyKey) bool {
|
2017-03-03 00:16:18 +00:00
|
|
|
return !diff.Changed(k)
|
2017-02-27 21:33:08 +00:00
|
|
|
}
|
|
|
|
|
2023-02-21 10:32:09 +00:00
|
|
|
// AnyChanges returns true if there are any changes (adds, deletes, updates) in the diff. Otherwise returns false.
|
2021-11-30 20:25:27 +00:00
|
|
|
func (diff *ObjectDiff) AnyChanges() bool {
|
|
|
|
return diff != nil && len(diff.Adds)+len(diff.Deletes)+len(diff.Updates) > 0
|
|
|
|
}
|
|
|
|
|
2017-02-24 03:03:22 +00:00
|
|
|
// Keys returns a stable snapshot of all keys known to this object, across adds, deletes, sames, and updates.
|
|
|
|
func (diff *ObjectDiff) Keys() []PropertyKey {
|
2023-03-03 16:36:39 +00:00
|
|
|
bufferSize := len(diff.Adds) + len(diff.Deletes) + len(diff.Sames) + len(diff.Updates)
|
2023-06-28 16:02:04 +00:00
|
|
|
ks := slice.Prealloc[PropertyKey](bufferSize)
|
2017-02-24 03:03:22 +00:00
|
|
|
for k := range diff.Adds {
|
|
|
|
ks = append(ks, k)
|
|
|
|
}
|
|
|
|
for k := range diff.Deletes {
|
|
|
|
ks = append(ks, k)
|
|
|
|
}
|
|
|
|
for k := range diff.Sames {
|
|
|
|
ks = append(ks, k)
|
|
|
|
}
|
|
|
|
for k := range diff.Updates {
|
|
|
|
ks = append(ks, k)
|
|
|
|
}
|
Make more progress on the new deployment model
This change restructures a lot more pertaining to deployments, snapshots,
environments, and the like.
The most notable change is that the notion of a deploy.Source is introduced,
which splits the responsibility between the deploy.Plan -- which simply
understands how to compute and carry out deployment plans -- and the idea
of something that can produce new objects on-demand during deployment.
The primary such implementation is evalSource, which encapsulates an
interpreter and takes a package, args, and config map, and proceeds to run
the interpreter in a distinct goroutine. It synchronizes as needed to
poke and prod the interpreter along its path to create new resource objects.
There are two other sources, however. First, a nullSource, which simply
refuses to create new objects. This can be handy when writing isolated
tests but is also used to simulate the "empty" environment as necessary to
do a complete teardown of the target environment. Second, a fixedSource,
which takes a pre-computed array of objects, and hands those, in order, to
the planning engine; this is mostly useful as a testing technique.
Boatloads of code is now changed and updated in the various CLI commands.
This further chugs along towards pulumi/lumi#90. The end is in sight.
2017-06-10 18:50:47 +00:00
|
|
|
sort.Slice(ks, func(i, j int) bool { return ks[i] < ks[j] })
|
2017-02-24 03:03:22 +00:00
|
|
|
return ks
|
|
|
|
}
|
|
|
|
|
2021-11-30 20:25:27 +00:00
|
|
|
// All keys where Changed(k) = true.
|
|
|
|
func (diff *ObjectDiff) ChangedKeys() []PropertyKey {
|
|
|
|
var ks []PropertyKey
|
|
|
|
if diff != nil {
|
|
|
|
for _, k := range diff.Keys() {
|
|
|
|
if diff.Changed(k) {
|
|
|
|
ks = append(ks, k)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ks
|
|
|
|
}
|
|
|
|
|
2017-02-24 03:03:22 +00:00
|
|
|
// ValueDiff holds the results of diffing two property values.
|
|
|
|
type ValueDiff struct {
|
|
|
|
Old PropertyValue // the old value.
|
|
|
|
New PropertyValue // the new value.
|
|
|
|
Array *ArrayDiff // the array's detailed diffs (only for arrays).
|
|
|
|
Object *ObjectDiff // the object's detailed diffs (only for objects).
|
|
|
|
}
|
|
|
|
|
|
|
|
// ArrayDiff holds the results of diffing two arrays of property values.
|
|
|
|
type ArrayDiff struct {
|
|
|
|
Adds map[int]PropertyValue // elements added in the new.
|
|
|
|
Deletes map[int]PropertyValue // elements deleted in the new.
|
|
|
|
Sames map[int]PropertyValue // elements the same in both.
|
|
|
|
Updates map[int]ValueDiff // elements that have changed in the new.
|
|
|
|
}
|
|
|
|
|
|
|
|
// Len computes the length of this array, taking into account adds, deletes, sames, and updates.
|
|
|
|
func (diff *ArrayDiff) Len() int {
|
all: Fix revive issues
Fixes the following issues found by revive
included in the latest release of golangci-lint.
Full list of issues:
**pkg**
```
backend/display/object_diff.go:47:10: superfluous-else: if block ends with a break statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
backend/display/object_diff.go:716:12: redefines-builtin-id: redefinition of the built-in function delete (revive)
backend/display/object_diff.go:742:14: redefines-builtin-id: redefinition of the built-in function delete (revive)
backend/display/object_diff.go:983:10: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (revive)
backend/httpstate/backend.go:1814:4: redefines-builtin-id: redefinition of the built-in function cap (revive)
backend/httpstate/backend.go:1824:5: redefines-builtin-id: redefinition of the built-in function cap (revive)
backend/httpstate/client/client.go:444:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
backend/httpstate/client/client.go:455:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
cmd/pulumi/org.go:113:4: if-return: redundant if ...; err != nil check, just return error instead. (revive)
cmd/pulumi/util.go:216:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
codegen/docs/gen.go:428:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
codegen/hcl2/model/expression.go:2151:5: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:151:2: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:329:3: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:381:5: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/nodejs/gen.go:1367:5: redefines-builtin-id: redefinition of the built-in function copy (revive)
codegen/python/gen_program_expressions.go:136:2: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/python/gen_program_expressions.go:142:3: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/report/report.go:126:6: redefines-builtin-id: redefinition of the built-in function panic (revive)
codegen/schema/docs_test.go:210:10: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
codegen/schema/schema.go:790:2: redefines-builtin-id: redefinition of the built-in type any (revive)
codegen/schema/schema.go:793:4: redefines-builtin-id: redefinition of the built-in type any (revive)
resource/deploy/plan.go:506:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
resource/deploy/snapshot_test.go:59:3: redefines-builtin-id: redefinition of the built-in function copy (revive)
resource/deploy/state_builder.go:108:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
```
**sdk**
```
go/common/resource/plugin/context.go:142:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
go/common/resource/plugin/plugin.go:142:12: superfluous-else: if block ends with a break statement, so drop this else and outdent its block (revive)
go/common/resource/properties_diff.go:114:2: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:117:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:122:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:127:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:132:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/util/deepcopy/copy.go:30:1: redefines-builtin-id: redefinition of the built-in function copy (revive)
go/common/workspace/creds.go:242:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi-language-go/main.go:569:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi-language-go/main.go:706:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi/run_test.go:925:2: redefines-builtin-id: redefinition of the built-in type any (revive)
go/pulumi/run_test.go:933:3: redefines-builtin-id: redefinition of the built-in type any (revive)
nodejs/cmd/pulumi-language-nodejs/main.go:778:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/cmd/pulumi-language-python/main.go:1011:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/cmd/pulumi-language-python/main.go:863:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/python.go:230:2: redefines-builtin-id: redefinition of the built-in function print (revive)
```
**tests**
```
integration/integration_util_test.go:282:11: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
```
2023-03-20 23:48:02 +00:00
|
|
|
length := 0
|
2017-02-24 03:03:22 +00:00
|
|
|
for i := range diff.Adds {
|
all: Fix revive issues
Fixes the following issues found by revive
included in the latest release of golangci-lint.
Full list of issues:
**pkg**
```
backend/display/object_diff.go:47:10: superfluous-else: if block ends with a break statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
backend/display/object_diff.go:716:12: redefines-builtin-id: redefinition of the built-in function delete (revive)
backend/display/object_diff.go:742:14: redefines-builtin-id: redefinition of the built-in function delete (revive)
backend/display/object_diff.go:983:10: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (revive)
backend/httpstate/backend.go:1814:4: redefines-builtin-id: redefinition of the built-in function cap (revive)
backend/httpstate/backend.go:1824:5: redefines-builtin-id: redefinition of the built-in function cap (revive)
backend/httpstate/client/client.go:444:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
backend/httpstate/client/client.go:455:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
cmd/pulumi/org.go:113:4: if-return: redundant if ...; err != nil check, just return error instead. (revive)
cmd/pulumi/util.go:216:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
codegen/docs/gen.go:428:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
codegen/hcl2/model/expression.go:2151:5: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:151:2: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:329:3: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:381:5: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/nodejs/gen.go:1367:5: redefines-builtin-id: redefinition of the built-in function copy (revive)
codegen/python/gen_program_expressions.go:136:2: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/python/gen_program_expressions.go:142:3: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/report/report.go:126:6: redefines-builtin-id: redefinition of the built-in function panic (revive)
codegen/schema/docs_test.go:210:10: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
codegen/schema/schema.go:790:2: redefines-builtin-id: redefinition of the built-in type any (revive)
codegen/schema/schema.go:793:4: redefines-builtin-id: redefinition of the built-in type any (revive)
resource/deploy/plan.go:506:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
resource/deploy/snapshot_test.go:59:3: redefines-builtin-id: redefinition of the built-in function copy (revive)
resource/deploy/state_builder.go:108:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
```
**sdk**
```
go/common/resource/plugin/context.go:142:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
go/common/resource/plugin/plugin.go:142:12: superfluous-else: if block ends with a break statement, so drop this else and outdent its block (revive)
go/common/resource/properties_diff.go:114:2: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:117:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:122:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:127:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:132:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/util/deepcopy/copy.go:30:1: redefines-builtin-id: redefinition of the built-in function copy (revive)
go/common/workspace/creds.go:242:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi-language-go/main.go:569:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi-language-go/main.go:706:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi/run_test.go:925:2: redefines-builtin-id: redefinition of the built-in type any (revive)
go/pulumi/run_test.go:933:3: redefines-builtin-id: redefinition of the built-in type any (revive)
nodejs/cmd/pulumi-language-nodejs/main.go:778:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/cmd/pulumi-language-python/main.go:1011:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/cmd/pulumi-language-python/main.go:863:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/python.go:230:2: redefines-builtin-id: redefinition of the built-in function print (revive)
```
**tests**
```
integration/integration_util_test.go:282:11: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
```
2023-03-20 23:48:02 +00:00
|
|
|
if i+1 > length {
|
|
|
|
length = i + 1
|
2017-02-24 03:03:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for i := range diff.Deletes {
|
all: Fix revive issues
Fixes the following issues found by revive
included in the latest release of golangci-lint.
Full list of issues:
**pkg**
```
backend/display/object_diff.go:47:10: superfluous-else: if block ends with a break statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
backend/display/object_diff.go:716:12: redefines-builtin-id: redefinition of the built-in function delete (revive)
backend/display/object_diff.go:742:14: redefines-builtin-id: redefinition of the built-in function delete (revive)
backend/display/object_diff.go:983:10: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (revive)
backend/httpstate/backend.go:1814:4: redefines-builtin-id: redefinition of the built-in function cap (revive)
backend/httpstate/backend.go:1824:5: redefines-builtin-id: redefinition of the built-in function cap (revive)
backend/httpstate/client/client.go:444:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
backend/httpstate/client/client.go:455:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
cmd/pulumi/org.go:113:4: if-return: redundant if ...; err != nil check, just return error instead. (revive)
cmd/pulumi/util.go:216:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
codegen/docs/gen.go:428:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
codegen/hcl2/model/expression.go:2151:5: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:151:2: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:329:3: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:381:5: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/nodejs/gen.go:1367:5: redefines-builtin-id: redefinition of the built-in function copy (revive)
codegen/python/gen_program_expressions.go:136:2: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/python/gen_program_expressions.go:142:3: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/report/report.go:126:6: redefines-builtin-id: redefinition of the built-in function panic (revive)
codegen/schema/docs_test.go:210:10: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
codegen/schema/schema.go:790:2: redefines-builtin-id: redefinition of the built-in type any (revive)
codegen/schema/schema.go:793:4: redefines-builtin-id: redefinition of the built-in type any (revive)
resource/deploy/plan.go:506:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
resource/deploy/snapshot_test.go:59:3: redefines-builtin-id: redefinition of the built-in function copy (revive)
resource/deploy/state_builder.go:108:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
```
**sdk**
```
go/common/resource/plugin/context.go:142:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
go/common/resource/plugin/plugin.go:142:12: superfluous-else: if block ends with a break statement, so drop this else and outdent its block (revive)
go/common/resource/properties_diff.go:114:2: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:117:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:122:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:127:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:132:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/util/deepcopy/copy.go:30:1: redefines-builtin-id: redefinition of the built-in function copy (revive)
go/common/workspace/creds.go:242:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi-language-go/main.go:569:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi-language-go/main.go:706:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi/run_test.go:925:2: redefines-builtin-id: redefinition of the built-in type any (revive)
go/pulumi/run_test.go:933:3: redefines-builtin-id: redefinition of the built-in type any (revive)
nodejs/cmd/pulumi-language-nodejs/main.go:778:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/cmd/pulumi-language-python/main.go:1011:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/cmd/pulumi-language-python/main.go:863:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/python.go:230:2: redefines-builtin-id: redefinition of the built-in function print (revive)
```
**tests**
```
integration/integration_util_test.go:282:11: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
```
2023-03-20 23:48:02 +00:00
|
|
|
if i+1 > length {
|
|
|
|
length = i + 1
|
2017-02-24 03:03:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for i := range diff.Sames {
|
all: Fix revive issues
Fixes the following issues found by revive
included in the latest release of golangci-lint.
Full list of issues:
**pkg**
```
backend/display/object_diff.go:47:10: superfluous-else: if block ends with a break statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
backend/display/object_diff.go:716:12: redefines-builtin-id: redefinition of the built-in function delete (revive)
backend/display/object_diff.go:742:14: redefines-builtin-id: redefinition of the built-in function delete (revive)
backend/display/object_diff.go:983:10: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (revive)
backend/httpstate/backend.go:1814:4: redefines-builtin-id: redefinition of the built-in function cap (revive)
backend/httpstate/backend.go:1824:5: redefines-builtin-id: redefinition of the built-in function cap (revive)
backend/httpstate/client/client.go:444:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
backend/httpstate/client/client.go:455:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
cmd/pulumi/org.go:113:4: if-return: redundant if ...; err != nil check, just return error instead. (revive)
cmd/pulumi/util.go:216:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
codegen/docs/gen.go:428:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
codegen/hcl2/model/expression.go:2151:5: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:151:2: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:329:3: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:381:5: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/nodejs/gen.go:1367:5: redefines-builtin-id: redefinition of the built-in function copy (revive)
codegen/python/gen_program_expressions.go:136:2: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/python/gen_program_expressions.go:142:3: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/report/report.go:126:6: redefines-builtin-id: redefinition of the built-in function panic (revive)
codegen/schema/docs_test.go:210:10: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
codegen/schema/schema.go:790:2: redefines-builtin-id: redefinition of the built-in type any (revive)
codegen/schema/schema.go:793:4: redefines-builtin-id: redefinition of the built-in type any (revive)
resource/deploy/plan.go:506:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
resource/deploy/snapshot_test.go:59:3: redefines-builtin-id: redefinition of the built-in function copy (revive)
resource/deploy/state_builder.go:108:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
```
**sdk**
```
go/common/resource/plugin/context.go:142:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
go/common/resource/plugin/plugin.go:142:12: superfluous-else: if block ends with a break statement, so drop this else and outdent its block (revive)
go/common/resource/properties_diff.go:114:2: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:117:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:122:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:127:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:132:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/util/deepcopy/copy.go:30:1: redefines-builtin-id: redefinition of the built-in function copy (revive)
go/common/workspace/creds.go:242:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi-language-go/main.go:569:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi-language-go/main.go:706:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi/run_test.go:925:2: redefines-builtin-id: redefinition of the built-in type any (revive)
go/pulumi/run_test.go:933:3: redefines-builtin-id: redefinition of the built-in type any (revive)
nodejs/cmd/pulumi-language-nodejs/main.go:778:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/cmd/pulumi-language-python/main.go:1011:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/cmd/pulumi-language-python/main.go:863:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/python.go:230:2: redefines-builtin-id: redefinition of the built-in function print (revive)
```
**tests**
```
integration/integration_util_test.go:282:11: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
```
2023-03-20 23:48:02 +00:00
|
|
|
if i+1 > length {
|
|
|
|
length = i + 1
|
2017-02-24 03:03:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for i := range diff.Updates {
|
all: Fix revive issues
Fixes the following issues found by revive
included in the latest release of golangci-lint.
Full list of issues:
**pkg**
```
backend/display/object_diff.go:47:10: superfluous-else: if block ends with a break statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
backend/display/object_diff.go:716:12: redefines-builtin-id: redefinition of the built-in function delete (revive)
backend/display/object_diff.go:742:14: redefines-builtin-id: redefinition of the built-in function delete (revive)
backend/display/object_diff.go:983:10: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (revive)
backend/httpstate/backend.go:1814:4: redefines-builtin-id: redefinition of the built-in function cap (revive)
backend/httpstate/backend.go:1824:5: redefines-builtin-id: redefinition of the built-in function cap (revive)
backend/httpstate/client/client.go:444:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
backend/httpstate/client/client.go:455:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
cmd/pulumi/org.go:113:4: if-return: redundant if ...; err != nil check, just return error instead. (revive)
cmd/pulumi/util.go:216:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
codegen/docs/gen.go:428:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
codegen/hcl2/model/expression.go:2151:5: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:151:2: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:329:3: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:381:5: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/nodejs/gen.go:1367:5: redefines-builtin-id: redefinition of the built-in function copy (revive)
codegen/python/gen_program_expressions.go:136:2: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/python/gen_program_expressions.go:142:3: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/report/report.go:126:6: redefines-builtin-id: redefinition of the built-in function panic (revive)
codegen/schema/docs_test.go:210:10: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
codegen/schema/schema.go:790:2: redefines-builtin-id: redefinition of the built-in type any (revive)
codegen/schema/schema.go:793:4: redefines-builtin-id: redefinition of the built-in type any (revive)
resource/deploy/plan.go:506:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
resource/deploy/snapshot_test.go:59:3: redefines-builtin-id: redefinition of the built-in function copy (revive)
resource/deploy/state_builder.go:108:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
```
**sdk**
```
go/common/resource/plugin/context.go:142:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
go/common/resource/plugin/plugin.go:142:12: superfluous-else: if block ends with a break statement, so drop this else and outdent its block (revive)
go/common/resource/properties_diff.go:114:2: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:117:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:122:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:127:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:132:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/util/deepcopy/copy.go:30:1: redefines-builtin-id: redefinition of the built-in function copy (revive)
go/common/workspace/creds.go:242:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi-language-go/main.go:569:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi-language-go/main.go:706:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi/run_test.go:925:2: redefines-builtin-id: redefinition of the built-in type any (revive)
go/pulumi/run_test.go:933:3: redefines-builtin-id: redefinition of the built-in type any (revive)
nodejs/cmd/pulumi-language-nodejs/main.go:778:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/cmd/pulumi-language-python/main.go:1011:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/cmd/pulumi-language-python/main.go:863:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/python.go:230:2: redefines-builtin-id: redefinition of the built-in function print (revive)
```
**tests**
```
integration/integration_util_test.go:282:11: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
```
2023-03-20 23:48:02 +00:00
|
|
|
if i+1 > length {
|
|
|
|
length = i + 1
|
2017-02-24 03:03:22 +00:00
|
|
|
}
|
|
|
|
}
|
all: Fix revive issues
Fixes the following issues found by revive
included in the latest release of golangci-lint.
Full list of issues:
**pkg**
```
backend/display/object_diff.go:47:10: superfluous-else: if block ends with a break statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
backend/display/object_diff.go:716:12: redefines-builtin-id: redefinition of the built-in function delete (revive)
backend/display/object_diff.go:742:14: redefines-builtin-id: redefinition of the built-in function delete (revive)
backend/display/object_diff.go:983:10: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (revive)
backend/httpstate/backend.go:1814:4: redefines-builtin-id: redefinition of the built-in function cap (revive)
backend/httpstate/backend.go:1824:5: redefines-builtin-id: redefinition of the built-in function cap (revive)
backend/httpstate/client/client.go:444:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
backend/httpstate/client/client.go:455:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
cmd/pulumi/org.go:113:4: if-return: redundant if ...; err != nil check, just return error instead. (revive)
cmd/pulumi/util.go:216:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
codegen/docs/gen.go:428:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
codegen/hcl2/model/expression.go:2151:5: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:151:2: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:329:3: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/hcl2/syntax/comments.go:381:5: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/nodejs/gen.go:1367:5: redefines-builtin-id: redefinition of the built-in function copy (revive)
codegen/python/gen_program_expressions.go:136:2: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/python/gen_program_expressions.go:142:3: redefines-builtin-id: redefinition of the built-in function close (revive)
codegen/report/report.go:126:6: redefines-builtin-id: redefinition of the built-in function panic (revive)
codegen/schema/docs_test.go:210:10: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
codegen/schema/schema.go:790:2: redefines-builtin-id: redefinition of the built-in type any (revive)
codegen/schema/schema.go:793:4: redefines-builtin-id: redefinition of the built-in type any (revive)
resource/deploy/plan.go:506:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
resource/deploy/snapshot_test.go:59:3: redefines-builtin-id: redefinition of the built-in function copy (revive)
resource/deploy/state_builder.go:108:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
```
**sdk**
```
go/common/resource/plugin/context.go:142:2: redefines-builtin-id: redefinition of the built-in function copy (revive)
go/common/resource/plugin/plugin.go:142:12: superfluous-else: if block ends with a break statement, so drop this else and outdent its block (revive)
go/common/resource/properties_diff.go:114:2: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:117:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:122:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:127:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/resource/properties_diff.go:132:4: redefines-builtin-id: redefinition of the built-in function len (revive)
go/common/util/deepcopy/copy.go:30:1: redefines-builtin-id: redefinition of the built-in function copy (revive)
go/common/workspace/creds.go:242:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi-language-go/main.go:569:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi-language-go/main.go:706:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
go/pulumi/run_test.go:925:2: redefines-builtin-id: redefinition of the built-in type any (revive)
go/pulumi/run_test.go:933:3: redefines-builtin-id: redefinition of the built-in type any (revive)
nodejs/cmd/pulumi-language-nodejs/main.go:778:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/cmd/pulumi-language-python/main.go:1011:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/cmd/pulumi-language-python/main.go:863:2: if-return: redundant if ...; err != nil check, just return error instead. (revive)
python/python.go:230:2: redefines-builtin-id: redefinition of the built-in function print (revive)
```
**tests**
```
integration/integration_util_test.go:282:11: superfluous-else: if block ends with a continue statement, so drop this else and outdent its block (move short variable declaration to its own line if necessary) (revive)
```
2023-03-20 23:48:02 +00:00
|
|
|
return length
|
2017-02-24 03:03:22 +00:00
|
|
|
}
|
|
|
|
|
2019-03-12 01:01:48 +00:00
|
|
|
// IgnoreKeyFunc is the callback type for Diff's ignore option.
|
|
|
|
type IgnoreKeyFunc func(key PropertyKey) bool
|
|
|
|
|
2017-02-24 03:03:22 +00:00
|
|
|
// Diff returns a diffset by comparing the property map to another; it returns nil if there are no diffs.
|
2019-03-12 01:01:48 +00:00
|
|
|
func (props PropertyMap) Diff(other PropertyMap, ignoreKeys ...IgnoreKeyFunc) *ObjectDiff {
|
2017-02-25 01:02:02 +00:00
|
|
|
adds := make(PropertyMap)
|
2017-02-24 03:03:22 +00:00
|
|
|
deletes := make(PropertyMap)
|
|
|
|
sames := make(PropertyMap)
|
|
|
|
updates := make(map[PropertyKey]ValueDiff)
|
2017-02-25 01:02:02 +00:00
|
|
|
|
2019-03-12 01:01:48 +00:00
|
|
|
ignore := func(key PropertyKey) bool {
|
|
|
|
for _, ikf := range ignoreKeys {
|
|
|
|
if ikf(key) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2017-02-25 01:02:02 +00:00
|
|
|
// First find any updates or deletes.
|
2017-02-27 21:33:08 +00:00
|
|
|
for k, old := range props {
|
2019-03-12 01:01:48 +00:00
|
|
|
if ignore(k) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2017-02-24 03:03:22 +00:00
|
|
|
if new, has := other[k]; has {
|
2017-06-01 15:23:59 +00:00
|
|
|
// If a new exists, use it; for output properties, however, ignore differences.
|
|
|
|
if new.IsOutput() {
|
|
|
|
sames[k] = old
|
2019-03-12 01:01:48 +00:00
|
|
|
} else if diff := old.Diff(new, ignoreKeys...); diff != nil {
|
2017-06-05 02:24:48 +00:00
|
|
|
if !old.HasValue() {
|
2017-02-25 01:02:02 +00:00
|
|
|
adds[k] = new
|
2017-06-05 02:24:48 +00:00
|
|
|
} else if !new.HasValue() {
|
2017-02-27 21:33:08 +00:00
|
|
|
deletes[k] = old
|
2017-02-25 01:02:02 +00:00
|
|
|
} else {
|
|
|
|
updates[k] = *diff
|
|
|
|
}
|
2017-02-24 03:03:22 +00:00
|
|
|
} else {
|
2017-02-27 21:33:08 +00:00
|
|
|
sames[k] = old
|
2017-02-24 03:03:22 +00:00
|
|
|
}
|
2017-06-05 02:24:48 +00:00
|
|
|
} else if old.HasValue() {
|
2017-06-01 15:23:59 +00:00
|
|
|
// If there was no new property, it has been deleted.
|
2017-02-27 21:33:08 +00:00
|
|
|
deletes[k] = old
|
2017-02-24 03:03:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Next find any additions not in the old map.
|
2017-02-27 21:33:08 +00:00
|
|
|
for k, new := range other {
|
2019-03-12 01:01:48 +00:00
|
|
|
if ignore(k) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2017-06-05 02:24:48 +00:00
|
|
|
if _, has := props[k]; !has && new.HasValue() {
|
2017-02-27 21:33:08 +00:00
|
|
|
adds[k] = new
|
2017-02-24 03:03:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If no diffs were found, return nil; else return a diff structure.
|
|
|
|
if len(adds) == 0 && len(deletes) == 0 && len(updates) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return &ObjectDiff{
|
|
|
|
Adds: adds,
|
|
|
|
Deletes: deletes,
|
|
|
|
Sames: sames,
|
|
|
|
Updates: updates,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Diff returns a diff by comparing a single property value to another; it returns nil if there are no diffs.
|
2019-03-12 01:01:48 +00:00
|
|
|
func (v PropertyValue) Diff(other PropertyValue, ignoreKeys ...IgnoreKeyFunc) *ValueDiff {
|
2017-02-24 03:03:22 +00:00
|
|
|
if v.IsArray() && other.IsArray() {
|
2017-02-25 01:02:02 +00:00
|
|
|
old := v.ArrayValue()
|
|
|
|
new := other.ArrayValue()
|
2017-02-24 03:03:22 +00:00
|
|
|
// If any elements exist in the new array but not the old, track them as adds.
|
|
|
|
adds := make(map[int]PropertyValue)
|
2017-02-25 01:02:02 +00:00
|
|
|
for i := len(old); i < len(new); i++ {
|
|
|
|
adds[i] = new[i]
|
2017-02-24 03:03:22 +00:00
|
|
|
}
|
|
|
|
// If any elements exist in the old array but not the new, track them as adds.
|
|
|
|
deletes := make(map[int]PropertyValue)
|
2017-02-25 01:02:02 +00:00
|
|
|
for i := len(new); i < len(old); i++ {
|
|
|
|
deletes[i] = old[i]
|
2017-02-24 03:03:22 +00:00
|
|
|
}
|
|
|
|
// Now if elements exist in both, track them as sames or updates.
|
|
|
|
sames := make(map[int]PropertyValue)
|
|
|
|
updates := make(map[int]ValueDiff)
|
2017-02-25 01:02:02 +00:00
|
|
|
for i := 0; i < len(old) && i < len(new); i++ {
|
|
|
|
if diff := old[i].Diff(new[i]); diff != nil {
|
2017-02-24 03:03:22 +00:00
|
|
|
updates[i] = *diff
|
|
|
|
} else {
|
2017-02-25 01:02:02 +00:00
|
|
|
sames[i] = old[i]
|
2017-02-24 03:03:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-25 01:02:02 +00:00
|
|
|
if len(adds) == 0 && len(deletes) == 0 && len(updates) == 0 {
|
2017-02-24 03:03:22 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return &ValueDiff{
|
|
|
|
Old: v,
|
|
|
|
New: other,
|
|
|
|
Array: &ArrayDiff{
|
|
|
|
Adds: adds,
|
|
|
|
Deletes: deletes,
|
|
|
|
Sames: sames,
|
|
|
|
Updates: updates,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if v.IsObject() && other.IsObject() {
|
2017-02-25 01:02:02 +00:00
|
|
|
old := v.ObjectValue()
|
|
|
|
new := other.ObjectValue()
|
2019-03-12 01:01:48 +00:00
|
|
|
if diff := old.Diff(new, ignoreKeys...); diff != nil {
|
2017-02-24 03:03:22 +00:00
|
|
|
return &ValueDiff{
|
|
|
|
Old: v,
|
|
|
|
New: other,
|
|
|
|
Object: diff,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we got here, either the values are primitives, or they weren't the same type; do a simple diff.
|
2017-07-17 19:11:15 +00:00
|
|
|
if v.DeepEquals(other) {
|
2017-02-24 03:03:22 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return &ValueDiff{Old: v, New: other}
|
|
|
|
}
|
2017-02-26 02:24:12 +00:00
|
|
|
|
|
|
|
// DeepEquals returns true if this property map is deeply equal to the other property map; and false otherwise.
|
|
|
|
func (props PropertyMap) DeepEquals(other PropertyMap) bool {
|
|
|
|
// If any in props either doesn't exist, or is of a different value, return false.
|
Make more progress on the new deployment model
This change restructures a lot more pertaining to deployments, snapshots,
environments, and the like.
The most notable change is that the notion of a deploy.Source is introduced,
which splits the responsibility between the deploy.Plan -- which simply
understands how to compute and carry out deployment plans -- and the idea
of something that can produce new objects on-demand during deployment.
The primary such implementation is evalSource, which encapsulates an
interpreter and takes a package, args, and config map, and proceeds to run
the interpreter in a distinct goroutine. It synchronizes as needed to
poke and prod the interpreter along its path to create new resource objects.
There are two other sources, however. First, a nullSource, which simply
refuses to create new objects. This can be handy when writing isolated
tests but is also used to simulate the "empty" environment as necessary to
do a complete teardown of the target environment. Second, a fixedSource,
which takes a pre-computed array of objects, and hands those, in order, to
the planning engine; this is mostly useful as a testing technique.
Boatloads of code is now changed and updated in the various CLI commands.
This further chugs along towards pulumi/lumi#90. The end is in sight.
2017-06-10 18:50:47 +00:00
|
|
|
for _, k := range props.StableKeys() {
|
2017-02-26 02:24:12 +00:00
|
|
|
v := props[k]
|
|
|
|
if p, has := other[k]; has {
|
|
|
|
if !v.DeepEquals(p) {
|
|
|
|
return false
|
|
|
|
}
|
2017-06-05 02:24:48 +00:00
|
|
|
} else if v.HasValue() {
|
2017-02-26 02:24:12 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the other map has properties that this map doesn't have, return false.
|
Make more progress on the new deployment model
This change restructures a lot more pertaining to deployments, snapshots,
environments, and the like.
The most notable change is that the notion of a deploy.Source is introduced,
which splits the responsibility between the deploy.Plan -- which simply
understands how to compute and carry out deployment plans -- and the idea
of something that can produce new objects on-demand during deployment.
The primary such implementation is evalSource, which encapsulates an
interpreter and takes a package, args, and config map, and proceeds to run
the interpreter in a distinct goroutine. It synchronizes as needed to
poke and prod the interpreter along its path to create new resource objects.
There are two other sources, however. First, a nullSource, which simply
refuses to create new objects. This can be handy when writing isolated
tests but is also used to simulate the "empty" environment as necessary to
do a complete teardown of the target environment. Second, a fixedSource,
which takes a pre-computed array of objects, and hands those, in order, to
the planning engine; this is mostly useful as a testing technique.
Boatloads of code is now changed and updated in the various CLI commands.
This further chugs along towards pulumi/lumi#90. The end is in sight.
2017-06-10 18:50:47 +00:00
|
|
|
for _, k := range other.StableKeys() {
|
2017-06-05 02:24:48 +00:00
|
|
|
if _, has := props[k]; !has && other[k].HasValue() {
|
2017-02-26 02:24:12 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeepEquals returns true if this property map is deeply equal to the other property map; and false otherwise.
|
|
|
|
func (v PropertyValue) DeepEquals(other PropertyValue) bool {
|
|
|
|
// Arrays are equal if they are both of the same size and elements are deeply equal.
|
|
|
|
if v.IsArray() {
|
|
|
|
if !other.IsArray() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
va := v.ArrayValue()
|
|
|
|
oa := other.ArrayValue()
|
|
|
|
if len(va) != len(oa) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
for i, elem := range va {
|
|
|
|
if !elem.DeepEquals(oa[i]) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2017-07-17 19:11:15 +00:00
|
|
|
// Assets and archives enjoy value equality.
|
|
|
|
if v.IsAsset() {
|
|
|
|
if !other.IsAsset() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return v.AssetValue().Equals(other.AssetValue())
|
|
|
|
} else if v.IsArchive() {
|
|
|
|
if !other.IsArchive() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return v.ArchiveValue().Equals(other.ArchiveValue())
|
|
|
|
}
|
|
|
|
|
2017-02-26 02:24:12 +00:00
|
|
|
// Object values are equal if their contents are deeply equal.
|
|
|
|
if v.IsObject() {
|
|
|
|
if !other.IsObject() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
vo := v.ObjectValue()
|
|
|
|
oa := other.ObjectValue()
|
|
|
|
return vo.DeepEquals(oa)
|
|
|
|
}
|
|
|
|
|
2019-04-12 21:29:08 +00:00
|
|
|
// Secret are equal if the value they wrap are equal.
|
|
|
|
if v.IsSecret() {
|
|
|
|
if !other.IsSecret() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
vs := v.SecretValue()
|
|
|
|
os := other.SecretValue()
|
|
|
|
|
2019-05-15 21:41:28 +00:00
|
|
|
return vs.Element.DeepEquals(os.Element)
|
2019-04-12 21:29:08 +00:00
|
|
|
}
|
|
|
|
|
2020-10-27 17:12:12 +00:00
|
|
|
// Resource references are equal if they refer to the same resource. The package version is ignored.
|
|
|
|
if v.IsResourceReference() {
|
|
|
|
if !other.IsResourceReference() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
vr := v.ResourceReferenceValue()
|
|
|
|
or := other.ResourceReferenceValue()
|
|
|
|
|
2021-01-21 23:40:27 +00:00
|
|
|
if vr.URN != or.URN {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
vid, oid := vr.ID, or.ID
|
|
|
|
if vid.IsComputed() && oid.IsComputed() {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return vid.DeepEquals(oid)
|
2020-10-27 17:12:12 +00:00
|
|
|
}
|
|
|
|
|
2021-09-21 22:02:10 +00:00
|
|
|
// Outputs are equal if each of their fields is deeply equal.
|
|
|
|
if v.IsOutput() {
|
|
|
|
if !other.IsOutput() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
vo := v.OutputValue()
|
|
|
|
oo := other.OutputValue()
|
|
|
|
|
|
|
|
if vo.Known != oo.Known {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if vo.Secret != oo.Secret {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note that the dependencies are assumed to be sorted.
|
|
|
|
if len(vo.Dependencies) != len(oo.Dependencies) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
for i, dep := range vo.Dependencies {
|
|
|
|
if dep != oo.Dependencies[i] {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return vo.Element.DeepEquals(oo.Element)
|
|
|
|
}
|
|
|
|
|
2017-02-26 02:24:12 +00:00
|
|
|
// For all other cases, primitives are equal if their values are equal.
|
|
|
|
return v.V == other.V
|
|
|
|
}
|
2022-01-31 10:31:51 +00:00
|
|
|
|
2022-10-09 14:58:33 +00:00
|
|
|
// DiffIncludeUnknowns returns a diffset by comparing the property map to another; it returns nil if there are no diffs.
|
2022-01-31 10:31:51 +00:00
|
|
|
func (props PropertyMap) DiffIncludeUnknowns(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] = new
|
|
|
|
} else if diff := old.DiffIncludeUnknowns(new, ignoreKeys...); diff != nil {
|
|
|
|
if !old.HasValue() {
|
|
|
|
adds[k] = new
|
|
|
|
} else if !new.HasValue() {
|
|
|
|
deletes[k] = old
|
|
|
|
} else {
|
|
|
|
updates[k] = *diff
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sames[k] = new
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if old.IsComputed() {
|
|
|
|
// The old property was <computed> it probably resolved to undefined so this isn't a diff,
|
|
|
|
// but it isn't really a same either... just don't add to the diff
|
|
|
|
} else if old.HasValue() {
|
|
|
|
// If there was no new property, it has been deleted.
|
|
|
|
deletes[k] = old
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If no diffs were found, return nil; else return a diff structure.
|
|
|
|
if len(adds) == 0 && len(deletes) == 0 && len(updates) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return &ObjectDiff{
|
|
|
|
Adds: adds,
|
|
|
|
Deletes: deletes,
|
|
|
|
Sames: sames,
|
|
|
|
Updates: updates,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Diff returns a diff by comparing a single property value to another; it returns nil if there are no diffs.
|
|
|
|
func (v PropertyValue) DiffIncludeUnknowns(other PropertyValue, ignoreKeys ...IgnoreKeyFunc) *ValueDiff {
|
|
|
|
if v.IsArray() && other.IsArray() {
|
|
|
|
old := v.ArrayValue()
|
|
|
|
new := other.ArrayValue()
|
|
|
|
// If any elements exist in the new array but not the old, track them as adds.
|
|
|
|
adds := make(map[int]PropertyValue)
|
|
|
|
for i := len(old); i < len(new); i++ {
|
|
|
|
adds[i] = new[i]
|
|
|
|
}
|
|
|
|
// If any elements exist in the old array but not the new, track them as adds.
|
|
|
|
deletes := make(map[int]PropertyValue)
|
|
|
|
for i := len(new); i < len(old); i++ {
|
|
|
|
deletes[i] = old[i]
|
|
|
|
}
|
|
|
|
// Now if elements exist in both, track them as sames or updates.
|
|
|
|
sames := make(map[int]PropertyValue)
|
|
|
|
updates := make(map[int]ValueDiff)
|
|
|
|
for i := 0; i < len(old) && i < len(new); i++ {
|
|
|
|
if diff := old[i].DiffIncludeUnknowns(new[i]); diff != nil {
|
|
|
|
updates[i] = *diff
|
|
|
|
} else {
|
|
|
|
sames[i] = new[i]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(adds) == 0 && len(deletes) == 0 && len(updates) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return &ValueDiff{
|
|
|
|
Old: v,
|
|
|
|
New: other,
|
|
|
|
Array: &ArrayDiff{
|
|
|
|
Adds: adds,
|
|
|
|
Deletes: deletes,
|
|
|
|
Sames: sames,
|
|
|
|
Updates: updates,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if v.IsObject() && other.IsObject() {
|
|
|
|
old := v.ObjectValue()
|
|
|
|
new := other.ObjectValue()
|
|
|
|
if diff := old.DiffIncludeUnknowns(new, ignoreKeys...); diff != nil {
|
|
|
|
return &ValueDiff{
|
|
|
|
Old: v,
|
|
|
|
New: other,
|
|
|
|
Object: diff,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we got here, either the values are primitives, or they weren't the same type; do a simple diff.
|
|
|
|
if v.DeepEqualsIncludeUnknowns(other) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
return &ValueDiff{Old: v, New: other}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (props PropertyMap) DeepEqualsIncludeUnknowns(other PropertyMap) bool {
|
|
|
|
// If any in props either doesn't exist, or is of a different value, return false.
|
|
|
|
for _, k := range props.StableKeys() {
|
|
|
|
v := props[k]
|
|
|
|
if p, has := other[k]; has {
|
|
|
|
if !v.DeepEqualsIncludeUnknowns(p) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
} else if v.HasValue() && !v.IsComputed() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the other map has properties that this map doesn't have, return false.
|
|
|
|
for _, k := range other.StableKeys() {
|
|
|
|
if _, has := props[k]; !has && other[k].HasValue() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
func (v PropertyValue) DeepEqualsIncludeUnknowns(other PropertyValue) bool {
|
|
|
|
// Anything is equal to a computed
|
|
|
|
if v.IsComputed() || other.IsComputed() {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// Arrays are equal if they are both of the same size and elements are deeply equal.
|
|
|
|
if v.IsArray() {
|
|
|
|
if !other.IsArray() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
va := v.ArrayValue()
|
|
|
|
oa := other.ArrayValue()
|
|
|
|
if len(va) != len(oa) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
for i, elem := range va {
|
|
|
|
if !elem.DeepEqualsIncludeUnknowns(oa[i]) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
// Assets and archives enjoy value equality.
|
|
|
|
if v.IsAsset() {
|
|
|
|
if !other.IsAsset() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return v.AssetValue().Equals(other.AssetValue())
|
|
|
|
} else if v.IsArchive() {
|
|
|
|
if !other.IsArchive() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return v.ArchiveValue().Equals(other.ArchiveValue())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Object values are equal if their contents are deeply equal.
|
|
|
|
if v.IsObject() {
|
|
|
|
if !other.IsObject() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
vo := v.ObjectValue()
|
|
|
|
oa := other.ObjectValue()
|
|
|
|
return vo.DeepEqualsIncludeUnknowns(oa)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Secret are equal if the value they wrap are equal.
|
|
|
|
if v.IsSecret() {
|
|
|
|
if !other.IsSecret() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
vs := v.SecretValue()
|
|
|
|
os := other.SecretValue()
|
|
|
|
|
|
|
|
return vs.Element.DeepEqualsIncludeUnknowns(os.Element)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Resource references are equal if they refer to the same resource. The package version is ignored.
|
|
|
|
if v.IsResourceReference() {
|
|
|
|
if !other.IsResourceReference() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
vr := v.ResourceReferenceValue()
|
|
|
|
or := other.ResourceReferenceValue()
|
|
|
|
|
A property.Value implementation to replace resource.PropertyValue (#15145)
<!---
Thanks so much for your contribution! If this is your first time
contributing, please ensure that you have read the
[CONTRIBUTING](https://github.com/pulumi/pulumi/blob/master/CONTRIBUTING.md)
documentation.
-->
# Description
<!--- Please include a summary of the change and which issue is fixed.
Please also include relevant motivation and context. -->
The plan is to gradually replace resource.PropertyValue both internally
(in `pulumi/pulumi`) and in providers with this implementation.
This representation eliminates certain classes of bugs inherent with the
old representation:
- Modifiers (computed, secret, dependencies) live in a separate space
from values, so there is no longer a problem with different nestings.
- Equality is well defined and encapsulated.
- The distinction between `Output`, `Secret` and `Computed`.
- Names have been normalized (Input/Computed, Map/Object).
This is our chance to have a property value representation that we like,
so please leave comments if you think we can improve the API here.
## Checklist
- [X] I have run `make tidy` to update any new dependencies
- [X] I have run `make lint` to verify my code passes the lint check
- [ ] I have formatted my code using `gofumpt`
<!--- Please provide details if the checkbox below is to be left
unchecked. -->
- [ ] I have added tests that prove my fix is effective or that my
feature works
<!---
User-facing changes require a CHANGELOG entry.
-->
- [ ] I have run `make changelog` and committed the
`changelog/pending/<file>` documenting my change
<!--
If the change(s) in this PR is a modification of an existing call to the
Pulumi Cloud,
then the service should honor older versions of the CLI where this
change would not exist.
You must then bump the API version in
/pkg/backend/httpstate/client/api.go, as well as add
it to the service.
-->
- [ ] Yes, there are changes in this PR that warrants bumping the Pulumi
Cloud API version
<!-- @Pulumi employees: If yes, you must submit corresponding changes in
the service repo. -->
2024-03-14 19:58:59 +00:00
|
|
|
return vr.Equal(or)
|
2022-01-31 10:31:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Outputs are equal if each of their fields is deeply equal.
|
|
|
|
if v.IsOutput() {
|
|
|
|
if !other.IsOutput() {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
vo := v.OutputValue()
|
|
|
|
oo := other.OutputValue()
|
|
|
|
|
|
|
|
if vo.Known != oo.Known {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if vo.Secret != oo.Secret {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
// Note that the dependencies are assumed to be sorted.
|
|
|
|
if len(vo.Dependencies) != len(oo.Dependencies) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
for i, dep := range vo.Dependencies {
|
|
|
|
if dep != oo.Dependencies[i] {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return vo.Element.DeepEqualsIncludeUnknowns(oo.Element)
|
|
|
|
}
|
|
|
|
|
|
|
|
// For all other cases, primitives are equal if their values are equal.
|
|
|
|
return v.V == other.V
|
|
|
|
}
|