Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix SSA dry-run when an Apply is called on outputs #2615

Merged
merged 5 commits into from
Oct 20, 2023

Conversation

rquitales
Copy link
Contributor

@rquitales rquitales commented Oct 18, 2023

Proposed changes

This PR unsets the empty initialized status subresource from a SSA dry-run to prevent panics during pulumi preview when the Pulumi program contains an Apply on a status field. By removing the field completely, the Pulumi engine will be able to defer returning until after the resource is created, which is when the status subresource is populated.

Related issues (optional)

Fixes: #2577
Fixes: #2315

@rquitales rquitales requested review from EronWright and a team October 18, 2023 23:12
@github-actions
Copy link

Does the PR have any schema changes?

Looking good! No breaking changes found.
No new resources/functions.

@codecov-commenter
Copy link

codecov-commenter commented Oct 18, 2023

Codecov Report

Merging #2615 (a28b9d9) into master (8494869) will decrease coverage by 0.01%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##           master    #2615      +/-   ##
==========================================
- Coverage   18.60%   18.59%   -0.01%     
==========================================
  Files          47       47              
  Lines        9664     9667       +3     
==========================================
  Hits         1798     1798              
- Misses       7757     7760       +3     
  Partials      109      109              
Files Coverage Δ
provider/pkg/provider/provider.go 7.25% <0.00%> (-0.01%) ⬇️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Comment on lines +1914 to +1919
// We need to delete the empty status field returned from the API server if we are in
// preview mode. Having the status field set will cause a panic during preview if the Pulumi
// program attempts to read the status field.
if req.GetPreview() {
unstructured.RemoveNestedField(initialized.Object, "status")
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the marshaled value of status? I ask because plugin.MarshalProperties is called with SkipNulls: true, which implies to me that this shouldn't be necessary. Since it is necessary, does SkipNulls: true not work?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The status field is typically not nullable in Kubernetes objects, so I would expect that the status is empty, not null, here.

@rquitales could you elaborate on where the panic comes from? Is it in the application code or in the engine?
const ip = svc.status.apply((s) => s.loadBalancer.ingress[0].ip);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm almost certain that the panic comes from s being null (or undefined) in the lambda that is run during preview, instead of svc.status being unknown and the apply not running.

Copy link
Contributor Author

@rquitales rquitales Oct 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the status field returned from a SSA dry run is empty. The panic comes from the application code: const ip = svc.status.apply((s) => s.loadBalancer.ingress[0].ip) since it's attempting to grab the IP address.

Without this fix, the status field is populated with an empty, but initialized object. So attempting to access ingress[0] will cause a panic since the slice will be of length 0. If we nullify the status field, then the panic is averted.

provider/pkg/provider/provider.go Show resolved Hide resolved
tests/sdk/nodejs/preview_test.go Outdated Show resolved Hide resolved
@rquitales rquitales enabled auto-merge (squash) October 20, 2023 00:42
@rquitales rquitales merged commit e850a81 into master Oct 20, 2023
18 checks passed
@rquitales rquitales deleted the rquitales/fix-ssa-dry-run branch October 20, 2023 07:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants