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

Handle ignoreChanges for Server-Side Apply mode #2074

Merged
merged 4 commits into from
Jul 18, 2022

Conversation

lblackstone
Copy link
Member

@lblackstone lblackstone commented Jul 13, 2022

Proposed changes

Related issues (optional)

Fix #2012

@lblackstone lblackstone requested review from viveklak and a team July 13, 2022 21:46
@lblackstone
Copy link
Member Author

Note: I tagged @pulumi/platform in case anyone has suggestions for a better way to do this now. This implementation seems to work, but I wasn't sure if there was a function somewhere that handles this.

@github-actions
Copy link

Does the PR have any schema changes?

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

if err != nil {
return nil, fmt.Errorf("failed to parse ignore path: %w", err)
}
for p := range detailedDiff {
Copy link
Contributor

@viveklak viveklak Jul 13, 2022

Choose a reason for hiding this comment

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

Should we flip the loops so we go over detailedDiff at the top level and look through ignoreChanges in the nested loop? I assume ignore changes is a typically smaller slice?

Copy link
Contributor

@viveklak viveklak Jul 13, 2022

Choose a reason for hiding this comment

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

Curious why we need to do this? I haven't looked through engine code here but I would expect the engine to ignore relevant things from the diff response on the engine side instead? cc @Frassle for comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

@viveklak There's some additional context in #2012 (comment)

  Comment posted from Unblocked.

Copy link
Contributor

@viveklak viveklak Jul 13, 2022

Choose a reason for hiding this comment

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

I guess my question was if the engine should be doing the filtering of ignored changes given it has all the information it needs in order to perform the filtering on its side? Currently the provider has the opportunity to hand off diff to the engine with a DiffResponse_DIFF_UNKNOWN. Does this need to be as all-or-nothing as that?

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess my question was if the engine should be doing the filtering of ignored changes given it has all the information it needs in order to perform the filtering on its side?

I'm not sure about this. With SSA, I'm not sure if the engine would always be operating on the same information as the provider.

Copy link
Member

Choose a reason for hiding this comment

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

Curious why we need to do this? I haven't looked through engine code here but I would expect the engine to ignore relevant things from the diff response on the engine side instead?

I remember being confused why there was an ignoreChanges passed to the provider at all when I first saw, thinking the same thing. @pgavlin added it in pulumi/pulumi#3005. The engine will have already reset the inputs map to any old values due to ignoreChanges, I'll admit I'm not sure why this is insufficient for tf/k8ssa 😕

Copy link
Member

Choose a reason for hiding this comment

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

https://pulumi.slack.com/archives/C011EMDQ8JE/p1649841058403479 slack thread where Pat tried to explain why it's needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

So I'm not quite sure why this update is needed, but it's not working with the existing Diff code. The Update method isn't handling ignoreChanges at all, but it's also not doing any additional diff calculation, so perhaps it's deferring that work to the engine. Given the extra moving parts being introduced with Patch support, I'm hesitant to make major changes to the diff logic right now, so I think we should stick with this fix for the meantime.

@github-actions
Copy link

Does the PR have any schema changes?

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


import * as k8s from "@pulumi/kubernetes";

// This test creates a Provider with `enableServerSideApply` enabled. The following scenarios are tested:
Copy link
Member

Choose a reason for hiding this comment

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

Thank you for the comments here! I wish we did this in all the tests that are otherwise not exactly readable as to their intent.

}

if len(detailedDiff) > 0 {
for k := range patchObj {
Copy link
Member

Choose a reason for hiding this comment

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

I don't know this code very well but I wanted to ask if this change here is allright? This is now conditional. detailedDiff is now filtered by taking IgnoreChanges into account. The copying of patchObj to changes is now conditional. But it is not filtered. Is this OK? Consider:

  • IgnoreChanges is meaningful
  • detailedDiff got filtered, so delete(detailedDiff, diffPath.String()) fired a few times
  • remaining detailedDiff is non-empty; so len(detailedDiff) > 0
  • now changes becomes a copy of patchObj, including changes that are filtered out of detailedDiff?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes I think @t0yv0's observation is correct here? Seems like we should be scoping the keys to populate changes from detailedDiff instead (i.e. things that survived the pruning due to ignoreChanges).

Copy link
Member Author

Choose a reason for hiding this comment

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

Good points, thanks. I'll take another look at this logic today.

Copy link
Member

@t0yv0 t0yv0 left a comment

Choose a reason for hiding this comment

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

Looking good, have a few questions, not super familiar with this code though.

@github-actions
Copy link

Does the PR have any schema changes?

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

1 similar comment
@github-actions
Copy link

Does the PR have any schema changes?

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

@@ -1629,7 +1654,6 @@ func (k *kubeProvider) Diff(ctx context.Context, req *pulumirpc.DiffRequest) (*p
Replaces: replaces,
Stables: []string{},
DeleteBeforeReplace: deleteBeforeReplace,
Diffs: changes,
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: I got rid of the Diffs computation and am letting the engine handle this now. The DetailedDiff computation seems to be necessary to get an accurate diff with Server-side Apply. I tried setting DiffResponse_DIFF_UNKNOWN, but the result was incorrect.

Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting... Could you add a comment here in code to document the same? (why diffs are omitted?)

Copy link
Member

Choose a reason for hiding this comment

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

FWIW, I think this might be a tiny compatibility break with some very old versions of the CLI (~v0.17.20, which was released in June 2019). I think that the only break would be in the display code, which may no longer render the list of changed properties. I think that this is acceptable.

@github-actions
Copy link

Does the PR have any schema changes?

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

for _, ignorePath := range ignorePaths {
for _, diffPath := range diffPaths {
if ignorePath.Contains(diffPath) {
delete(detailedDiff, diffPath.String())
Copy link
Contributor

@viveklak viveklak Jul 18, 2022

Choose a reason for hiding this comment

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

Note I have found some instances where resource.PropertyPath doesn't retain the format when calling .String(). I will have fixes for this as part of pulumi/pulumi#10095. Shouldn't affect this change as long as we pull in fixes after the above lands. FYI.

@lblackstone lblackstone merged commit bd99d70 into master Jul 18, 2022
@pulumi-bot pulumi-bot deleted the lblackstone/ignore-changes branch July 18, 2022 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ignoreChanges has no effect when SSA is enabled
5 participants