Generate an additive JSON Patch instead of overwriting containers #175
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue #, if available: 165
Description of changes:
The problem in #165 is that the code is serializing the k8s.io structs as is, with an 'add' operation that effectively replaces the Container in the PodSpec. This works until fields are added, like grpc, at which point this webhook has to be updated, or it will drop the new fields.
Instead of serializing the entire container struct, this uses jsonpatch to create a diff from the modifications, and generated a targeted patch that only adds and modifies the things it needs to. Unknown fields will not be dropped.
I've not updated the test cases as they are hardcoded to expect a specific patch (that will drop unknown fields.) TBH, that approach needs to be rethought.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.