[FLINK-39509][flink-kubernetes-webhook] Fix mutating webhook producing spurious object modifications on no-op patches#1093
Merged
Conversation
…rious object modifications on no-op patches
Contributor
|
can we please create a jira ticket and test for this? |
Contributor
Author
Sure, I created FLINK-39509. About the tests, these are covered as part of the #1094 PR and FLINK-39508 JIRA. I suggest to proceed with the current PR as-is first. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What is the purpose of the change
The mutating webhook's
FlinkMutatoralways performs a JacksonconvertValueserialization round-trip (HasMetadata-> typed class -> back) on every CREATE/UPDATE admission request. When noFlinkResourceMutatoractually modifies the resource, the round-tripped object can serialize differently from the original input (e.g., field ordering, null handling), causing the webhook to return a JSON patch to the API server even though nothing was logically changed.This leads to inconsistent behavior where
kubectl patchreportspatchedinstead ofpatched (no change)for resources likeFlinkDeployment, even when the patch contains no effective change (e.g., settingrestartNonceto its current value). While this does not trigger an actual reconciliation (the operator correctly detects no spec diff), it is confusing and causes unnecessaryresourceVersionbumps on the Kubernetes object.Brief change log
mutate*method inFlinkMutator, capture a snapshot of the typed object before running mutators viamapper.valueToTree(), then compare it against the state after mutators runHasMetadataresource, bypassing the serialization round-trip entirelyFlinkDeployment,FlinkSessionJob,FlinkStateSnapshotVerifying this change
This change is a trivial rework / code cleanup without any test coverage.
Manually verified the change by:
FlinkDeploymentwith an identicalrestartNoncevalue and confirmingkubectlnow correctly reportspatched (no change)FlinkSessionJobwith an identicalrestartNoncevalue and confirming the samepatched (no change)outputrestartNoncevalues) still correctly reportpatchedand trigger reconciliationConcretely, this change can be manually verified the change by deploying the
basic-session-deployment-and-job.yamlexample and patching with an already-appliedrestartNoncevalue:Before (without fix):
After (with fix):
Does this pull request potentially affect one of the following parts:
CustomResourceDescriptors: noDocumentation