-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Edit a CustomResource should result in a patch #2923
Conversation
Can one of the admins verify this patch? |
@@ -346,9 +360,6 @@ public RawCustomResourceOperationsImpl dryRun(boolean isDryRun) { | |||
* @throws IOException in case of network/serialization failures or failures from Kubernetes API | |||
*/ | |||
public Map<String, Object> edit(String namespace, String name, String objectAsString) throws IOException { | |||
// Append resourceVersion in object metadata in order to | |||
// avoid : https://github.com/fabric8io/kubernetes-client/issues/1724 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is already implemented here:
Line 882 in 6e439a8
metadata.put(RESOURCE_VERSION, originalResourceVersion); |
A test seems to be failing:
|
@rohanKanojia I should have fixed the failing test, I'm having troubles with the build process, it often fails ... any hint on how to get it more reliable? |
You mean running tests via ide? I agree it's painful. Could you please check if this helps #2676 (comment) |
yesterday I was working in the IDE, today the IDE stopped to be able to compile the project and I have had to test every time with a |
You don't have to compile everything every time. Since you've made changes to However, you might need to build a project the first time. I use |
I think that the CI failure is unrelated now |
Don't worry, I've restarted the workflow |
Do I need to do anything more for this PR? |
|
||
private RawCustomResourceOperationsImpl(OkHttpClient client, Config config, CustomResourceDefinitionContext crdContext, String namespace, String name, long gracePeriodInSeconds, boolean cascading, String deletionPropagation, ListOptions listOptions, boolean dryRun) { | ||
super(client, config); | ||
this.customResourceDefinition = crdContext; | ||
this.objectMapper = Serialization.jsonMapper(); | ||
this.objectMapper = new ObjectMapper(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why can't we reuse the global ObjectMapper singleton instance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can test from my example:
https://github.com/andreaTP/fabric8-edit-as-patch/blob/8035f945a3c0be2db239c92632dc91bb4dda6d9e/src/main/scala/Main.scala#L59
After registering DefaultScalaModule
the global ObjectMapper will deserialize as Maps as "scala Maps" resulting in class cast exception e.g. here:
Line 870 in e60c634
Map<String, Object> metadata = (Map<String, Object>) objectAsMap.get(METADATA); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, that's very specific for your use case, and I'm sure you are having issues in other places around the code-base.
We should really need to find a neater way to address the problem.
Especially because if we start creating ObjectMapper instances across the different service implementations we'll have more problems in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please just propose me a solution, I will go-ahead 🙂
Here we RELY on having a clean ObjectMapper
, but, as said I'm open to suggestions!
Just to mention, no, fortunately, I have no other Serialization issues:
- Cloudflow Operator handling 3 different CR, one CRD, ConfigMaps, Secrets, Volumes etc. etc.
- Cloudflow CLI reading and writing again CRs, Secrets and more
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that seems very reasonable.
rebased on the latest master, anything else I can do to get this moving? |
@andreaTP : Thanks for updating as per review comments. I think we can get this merged once Marc approves it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thx!
Kudos, SonarCloud Quality Gate passed! |
Description
Trying to use the
edit
of a CR I found a couple of issues:ClassCastException
if there are external json modules registered e.g.: https://github.com/andreaTP/fabric8-edit-as-patch/blob/master/src/main/scala/Main.scala#L59PUT
while it's supposed to be aPATCH
as per:kubernetes-client/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/base/HasMetadataOperation.java
Lines 37 to 39 in 8d0957c
this PR address both issues.
Type of change
test, version modification, documentation, etc.)
Checklist
I tested the final result with this demo project:
https://github.com/andreaTP/fabric8-edit-as-patch
run with:
sbt run
I don't know how/where to add more exhaustive tests, I'm looking forward to guidance here 🙏