[WIP]add APIVersion and Kind checks for helper.ToUnstructured() #6028
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 type of PR is this?
/kind bug
What this PR does / why we need it:
This issue blocks me to continue #6017.
In function
helper.ToUnstructured()
, karmada will convert other types of object tounstructured.Unstructured
, but if object is missedTypeMeta
, the generatedunstructured.Unstructured
will also missedAPIVersion
andKind
, of course in most of the time these are harmful.Missing
TypeMeta
objects usually come from typed clients or objects that manually created in code.In kubernetes issue kubernetes/client-go#541 talked about typed client , looks like these guys won't fix this.
This issue affected many tests, and caused some tests to falsely report success. I fixed all the affected code I could see, but there may be still some I haven't noticed. This may also have an impact in non-test code, which I need to confirm further.
After fixing all the affected codes, I think adding an APIVersion and Kind checks to helper.ToUnstructured() can prevent the impact from expanding further. However, this check obviously needs to be added after ensuring that all the affected codes have been modified to avoid causing a stronger impact.
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: