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

Edit a CustomResource should result in a patch #2923

Merged
merged 8 commits into from
Apr 7, 2021

Conversation

andreaTP
Copy link
Member

@andreaTP andreaTP commented Mar 17, 2021

Description

Trying to use the edit of a CR I found a couple of issues:

this PR address both issues.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change
  • Chore (non-breaking change which doesn't affect codebase;
    test, version modification, documentation, etc.)

Checklist

  • Code contributed by me aligns with current project license: Apache 2.0
  • I Added CHANGELOG entry regarding this change
  • I have implemented unit tests to cover my changes
  • I have added/updated the javadocs and other documentation accordingly
  • No new bugs, code smells, etc. in SonarCloud report
  • I tested my code in Kubernetes
  • I tested my code in OpenShift

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 🙏

@centos-ci
Copy link

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
Copy link
Member Author

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:

@rohanKanojia
Copy link
Member

A test seems to be failing:

[INFO] Results:
[INFO] 
Error:  Errors: 
Error:    CustomResourceTest.testEdit:197 » KubernetesClient Failure executing: PATCH at...
[INFO] 
Error:  Tests run: 670, Failures: 0, Errors: 1, Skipped: 4
[INFO] 
[INFO] ------------------------------------------------------------------------

@andreaTP
Copy link
Member Author

@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?

@rohanKanojia
Copy link
Member

You mean running tests via ide? I agree it's painful. Could you please check if this helps #2676 (comment)

@andreaTP
Copy link
Member Author

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 mvn clean install command (and crazy long feedback loop cycle as you can imagine ...).
Re-importing failed at least 3 times ...

@rohanKanojia
Copy link
Member

You don't have to compile everything every time. Since you've made changes to kubernetes-client only, you should be able to check kubernetes-client and kubernetes-tests build okay.

However, you might need to build a project the first time. I use -DskipTests which compiles project in 10 minutes

@andreaTP
Copy link
Member Author

I think that the CI failure is unrelated now

@rohanKanojia
Copy link
Member

Don't worry, I've restarted the workflow

@andreaTP
Copy link
Member Author

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();
Copy link
Member

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?

Copy link
Member Author

@andreaTP andreaTP Mar 26, 2021

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:

Map<String, Object> metadata = (Map<String, Object>) objectAsMap.get(METADATA);

Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member Author

Choose a reason for hiding this comment

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

@manusa any suggestion to unblock this PR?
should we use the PatchUtils ObjectMapper?

I still think that a fresh one is more appropriate here until we have a more "structural" solution.
WDYT?

Copy link
Member

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.

@andreaTP
Copy link
Member Author

andreaTP commented Apr 1, 2021

rebased on the latest master, anything else I can do to get this moving?

@rohanKanojia
Copy link
Member

@andreaTP : Thanks for updating as per review comments. I think we can get this merged once Marc approves it.

@manusa manusa added this to the 5.3.0 milestone Apr 6, 2021
@rohanKanojia rohanKanojia requested a review from oscerd April 6, 2021 13:04
Copy link
Member

@manusa manusa left a comment

Choose a reason for hiding this comment

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

LGTM, thx!

@sonarcloud
Copy link

sonarcloud bot commented Apr 7, 2021

Kudos, SonarCloud Quality Gate passed!

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

93.3% 93.3% Coverage
0.0% 0.0% Duplication

@manusa manusa merged commit 07f77b1 into fabric8io:master Apr 7, 2021
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.

4 participants