Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
11533: Allow opting out of PULUMI_OPTIMIZED_CHECKPOINT_PATCH r=t0yv0 a=t0yv0

<!--- 
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

Allow users to opt out of deltaCheckpointUpdates even if the backend indicates it should be used. This remains necessary while PULUMI_OPTIMIZED_CHECKPOINT_PATCH has higher memory requirements on the client and may cause out-of-memory issues in constrained environments.

<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->

Part of https://github.com/pulumi/home/issues/2426

## Checklist

<!--- 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 Service,
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 Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


11537: Fix panic in mapper support for map[string]*string r=t0yv0 a=t0yv0

<!--- 
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

`map[string]*string` does not turn around through mapper, causing a panic.

```go
go test -run TestReproduceMapStringPointerTurnaroundIssue                                                                                                  ~/code/pulumi/sdk/go/common/util/mapper
--- FAIL: TestReproduceMapStringPointerTurnaroundIssue (0.00s)
    mapper_test.go:608: encodedMap: map[args:map[key:value]]
panic: reflect: Elem of invalid type string [recovered]
        panic: reflect: Elem of invalid type string

goroutine 20 [running]:
testing.tRunner.func1.2({0x11cb480, 0xc0000992b0})
        /nix/store/0c30lcag5r6ahw3qj0x7lkshpry4yqwl-go-1.19/share/go/src/testing/testing.go:1396 +0x24e
testing.tRunner.func1()
        /nix/store/0c30lcag5r6ahw3qj0x7lkshpry4yqwl-go-1.19/share/go/src/testing/testing.go:1399 +0x39f
panic({0x11cb480, 0xc0000992b0})
        /nix/store/0c30lcag5r6ahw3qj0x7lkshpry4yqwl-go-1.19/share/go/src/runtime/panic.go:884 +0x212
reflect.(*rtype).Elem(0x11d1500?)
        /nix/store/0c30lcag5r6ahw3qj0x7lkshpry4yqwl-go-1.19/share/go/src/reflect/type.go:972 +0x134
github.com/pulumi/pulumi/sdk/v3/go/common/util/mapper.(*mapper).adjustValueForAssignment(0xc0000a2240, {0x11d1500?, 0xc000099290?, 0x98?}, {0x126b940?, 0x11c6160}, {0x126b940?, 0x11dd060}, {0xc0000a4a80, 0xf})
        /Users/t0yv0/code/pulumi/sdk/go/common/util/mapper/mapper_decode.go:158 +0x2ea
github.com/pulumi/pulumi/sdk/v3/go/common/util/mapper.(*mapper).adjustValueForAssignment(0xc0000a2240, {0x11d5c20?, 0xc00009d470?, 0x11de1e0?}, {0x126b940?, 0x11d5680}, {0x126b940?, 0x11dd060}, {0x11c0b24, 0x4})
        /Users/t0yv0/code/pulumi/sdk/go/common/util/mapper/mapper_decode.go:204 +0x1a15
github.com/pulumi/pulumi/sdk/v3/go/common/util/mapper.(*mapper).DecodeValue(0xc0000a2240, 0xc0000a0060?, {0x126b940?, 0x11dd060}, {0x11c0b24, 0x4}, {0xc0000aac80?, 0xc0000a0060?}, 0x1)
        /Users/t0yv0/code/pulumi/sdk/go/common/util/mapper/mapper_decode.go:117 +0x8ee
github.com/pulumi/pulumi/sdk/v3/go/common/util/mapper.(*mapper).Decode(0xc0000a2240, 0xc0000a8380?, {0x11c36a0?, 0xc0000a0060?})
        /Users/t0yv0/code/pulumi/sdk/go/common/util/mapper/mapper_decode.go:55 +0x8db
github.com/pulumi/pulumi/sdk/v3/go/common/util/mapper.TestReproduceMapStringPointerTurnaroundIssue.func2(0xc000083520?)
        /Users/t0yv0/code/pulumi/sdk/go/common/util/mapper/mapper_test.go:592 +0xe9
github.com/pulumi/pulumi/sdk/v3/go/common/util/mapper.TestReproduceMapStringPointerTurnaroundIssue(0xc000083520)
        /Users/t0yv0/code/pulumi/sdk/go/common/util/mapper/mapper_test.go:610 +0x11f
testing.tRunner(0xc000083520, 0x1231f88)
        /nix/store/0c30lcag5r6ahw3qj0x7lkshpry4yqwl-go-1.19/share/go/src/testing/testing.go:1446 +0x10b
created by testing.(*T).Run
        /nix/store/0c30lcag5r6ahw3qj0x7lkshpry4yqwl-go-1.19/share/go/src/testing/testing.go:1493 +0x35f
exit status 2
FAIL    github.com/pulumi/pulumi/sdk/v3/go/common/util/mapper   0.674s
```


<!--- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. -->

Fixes # (issue)

## Checklist

<!--- 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 Service,
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 Service API version
  <!-- `@Pulumi` employees: If yes, you must submit corresponding changes in the service repo. -->


11539: Add `*[TYPE]` to `[TYPE]Ptr` methods r=aq17 a=aq17

Fixes #11536
Adds methods to convert pointer types to corresponding pulumi Ptr types

11540: ci: Remove page file tweak for Windows r=aq17 a=AaronFriel

The step to [configure the pagefile on Windows](https://github.com/pulumi/pulumi/actions/runs/3624853251/jobs/6112393713) began failing due to an update to the underlying runner image. Given that this is blocking CI, we'll remove the step for now.

Either #11532 or #11471 should address performance of integration tests and reliability and obviate the need for this step.

Co-authored-by: Anton Tayanovskyy <anton@pulumi.com>
Co-authored-by: aq17 <aqiu@pulumi.com>
Co-authored-by: Aaron Friel <mayreply@aaronfriel.com>
  • Loading branch information
4 people committed Dec 6, 2022
5 parents bb1ef96 + 590003f + 751d795 + 2c40dd9 + 6146a3c commit 48bd671
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 16 deletions.
8 changes: 0 additions & 8 deletions .github/workflows/ci-run-test.yml
Expand Up @@ -125,14 +125,6 @@ jobs:
if: ${{ inputs.enable-coverage && runner.os != 'Windows' }}
run: |
echo "PULUMI_TEST_COVERAGE_PATH=$(pwd)/coverage" >> "$GITHUB_ENV"
# See: https://github.com/actions/virtual-environments/issues/2642#issuecomment-774988591
- name: Configure Windows pagefile
uses: aaronfriel/action-configure-pagefile@v2.0-beta.1
if: ${{ runner.os == 'Windows' }}
with:
minimum-size: 4GB
maximum-size: 4GB
disk-root: "D:"
- name: Configure Go Cache Key
env:
CACHE_KEY: "${{ fromJson(inputs.version-set).go }}-${{ runner.os }}-${{ runner.arch }}"
Expand Down
@@ -0,0 +1,4 @@
changes:
- type: feat
scope: sdk
description: Add methods to cast pointer types to corresponding Pulumi Ptr types
9 changes: 9 additions & 0 deletions pkg/backend/httpstate/backend.go
Expand Up @@ -1798,6 +1798,15 @@ func doDetectCapabilities(ctx context.Context, d diag.Sink, client *client.Clien
d.Warningf(diag.Message("" /*urn*/, "failed to decode capabilities: %v"), err)
return capabilities{}
}

// Allow users to opt out of deltaCheckpointUpdates even if the backend indicates it should be used. This
// remains necessary while PULUMI_OPTIMIZED_CHECKPOINT_PATCH has higher memory requirements on the client and
// may cause out-of-memory issues in constrained environments.
switch strings.ToLower(os.Getenv("PULUMI_OPTIMIZED_CHECKPOINT_PATCH")) {
case "0", "false":
caps.deltaCheckpointUpdates = nil
}

return caps
}

Expand Down
19 changes: 11 additions & 8 deletions sdk/go/common/util/mapper/mapper_decode.go
Expand Up @@ -151,16 +151,19 @@ func (md *mapper) adjustValueForAssignment(val reflect.Value,
// A simple conversion exists to make this right.
val = val.Convert(to)
} else if to.Kind() == reflect.Ptr && val.Type().AssignableTo(to.Elem()) {
// If the target is a pointer, turn the target into a pointer. If it's not addressable, make a copy.
if val.CanAddr() {
val = val.Addr()
// Here the destination type (to) is a pointer to a type that accepts val.
var adjusted reflect.Value // var adjusted *toElem
if val.CanAddr() && val.Addr().Type().AssignableTo(to) {
// If taking the address of val makes this right, do it.
adjusted = val.Addr() // adjusted = &val
} else {
slot := reflect.New(val.Type().Elem())
copy := reflect.ValueOf(val.Interface())
contract.Assert(copy.CanAddr())
slot.Set(copy)
val = slot
// Otherwise create a fresh pointer of the desired type and point it to val.
adjusted = reflect.New(to.Elem()) // adjusted = new(toElem)
adjusted.Elem().Set(val) // *adjusted = val
}
// In either case, the loop condition should be sastisfied at this point.
contract.Assert(adjusted.Type().AssignableTo(to))
return adjusted, nil
} else if val.Kind() == reflect.Interface {
// It could be that the source is an interface{} with the right element type (or the right element type
// through a series of successive conversions); go ahead and give it a try.
Expand Down
41 changes: 41 additions & 0 deletions sdk/go/common/util/mapper/mapper_test.go
Expand Up @@ -573,3 +573,44 @@ func TestBasicUnmap(t *testing.T) {
assert.False(t, hash1h)
}
}

func TestReproduceMapStringPointerTurnaroundIssue(t *testing.T) {
t.Parallel()

type X struct {
Args map[string]*string `pulumi:"args,optional"`
}

xToMap := func(build X) (map[string]interface{}, error) {
m, err := New(nil).Encode(build)
if err != nil {
return nil, err
}
return m, nil
}

xFromMap := func(pm map[string]interface{}) (X, error) {
var build X
err := New(nil).Decode(pm, &build)
if err != nil {
return X{}, err
}
return build, nil
}

value := "value"
expected := X{
Args: map[string]*string{
"key": &value,
},
}

encodedMap, err := xToMap(expected)
require.NoError(t, err)
t.Logf("encodedMap: %v", encodedMap)

back, err2 := xFromMap(encodedMap)
require.NoError(t, err2)

require.Equal(t, expected, back)
}
6 changes: 6 additions & 0 deletions sdk/go/pulumi/generate/templates/types_builtins.go.template
Expand Up @@ -47,6 +47,12 @@ type {{.PtrType}} {{.ElemElementType}}
func {{.Name}}(v {{.ElemElementType}}) {{.Name}}Input {
return ({{.InputType}})(&v)
}
func {{.Name}}FromPtr(v *{{.ElemElementType}}) {{.Name}}Input {
if v == nil {
return nil
}
return ({{.InputType}})(v)
}
{{end}}
{{if .DefineInputMethods}}
// ElementType returns the element type of this Input ({{.ElementType}}).
Expand Down
36 changes: 36 additions & 0 deletions sdk/go/pulumi/types_builtins.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 48bd671

Please sign in to comment.