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

Fix exception handling in AsyncDefaultAdmissionRequestMutator #284

Conversation

Donnerbart
Copy link
Contributor

@Donnerbart Donnerbart commented Nov 19, 2024

Fixes #283

  • Fixes exception handling in AsyncDefaultAdmissionRequestMutator
  • Adds convenient AsyncAdmissionController(Mutator<T> mutator) constructor
  • Shows simplified usage of Mutator and Validator classes in io.javaoperatorsdk.webhook.sample.commons.AdmissionControllers
  • Cleanup of code base (I'm already sorry for this one 😅)

Code Coverage

main

image

bugfix/fix-async-mutator-exception-handling

image

return asyncMutator.mutate(clonedResource, operation)
.thenApply(resource -> admissionResponseFromMutation(originalResource, resource))
.exceptionally(e -> {
if (e instanceof CompletionException) {
Copy link
Contributor Author

@Donnerbart Donnerbart Nov 19, 2024

Choose a reason for hiding this comment

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

This is the actual fix.

this(mutator, new ObjectMapperCloner<>());
}

public AsyncDefaultAdmissionRequestMutator(AsyncMutator<T> mutator, Cloner<T> cloner) {
this.mutator = mutator;
public AsyncDefaultAdmissionRequestMutator(Mutator<T> mutator, Cloner<T> cloner) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the internal convenience constructor to enable the use of a Mutator for an async endpoint.

resource.getMetadata().getLabels().putIfAbsent(MUTATION_TARGET_LABEL, "mutation-test");
return resource;
}));
return new AsyncAdmissionController<>(new IngressMutator());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This demonstrates the usage of the new convenience constructor. In general this shows how you can de-deduplicate the code for mutators and validators by using old-school inner classes that can be used for sync and async endpoints.

Copy link
Contributor

Choose a reason for hiding this comment

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

If you simply run mvn clean install, that should fix it (if remember correctly)

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, best would be to migrate this repo also to spotless plugin.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sadly not, mvn clean install is successful and no files are changed. The Quarkus/JOSDK repos with spotless worked indeed fine for me.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh, sry, for me neither. Would you like to do the migration to spotless or should I do it (not sure in what timeline) ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not a Maven guy (anymore), but I can surely have a look. I'd say this should go in to a new PR and then I rebase this one later?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, that would be ideal, thx!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've re-created the branch from main, cherry-picked each commit and ran spotless:apply for all of them. So all commits should be compliant with the code formatting now.

@Donnerbart
Copy link
Contributor Author

Donnerbart commented Nov 19, 2024

Obviously it wasn't enough to import the code style into IDEA. Sadly ./mvnw formatter:format -Dconfigfile=$PWD/contributing/eclipse-google-style.xml --file pom.xml doesn't do anything on my machine, although ./mvnw formatter:validate -Dconfigfile=$PWD/contributing/eclipse-google-style.xml --file pom.xml reports the same failure like the CI. Any hint how I can fix the formatting?

EDIT: I just impsort:sort to fix the imports, but the formatter:validate is still not happy.

Copy link
Contributor

@csviri csviri left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@Donnerbart Donnerbart force-pushed the bugfix/fix-async-mutator-exception-handling branch 2 times, most recently from 7ff0dd4 to d530946 Compare November 19, 2024 18:09
@csviri
Copy link
Contributor

csviri commented Nov 20, 2024

@Donnerbart the build fails, could you pls take a look. Thx

…d add constructor for Mutator interface

Signed-off-by: David Sondermann <[email protected]>
@Donnerbart Donnerbart force-pushed the bugfix/fix-async-mutator-exception-handling branch from d530946 to 6a6492f Compare November 20, 2024 11:14
@Donnerbart
Copy link
Contributor Author

It was just a missing import, an oversight when I re-created the branch.

Copy link
Contributor

@csviri csviri 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 @Donnerbart

@csviri csviri merged commit 2133d28 into operator-framework:main Nov 20, 2024
4 checks passed
@Donnerbart Donnerbart deleted the bugfix/fix-async-mutator-exception-handling branch November 20, 2024 13:40
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.

AsyncDefaultAdmissionRequestMutator doesn't handle NotAllowedException correctly
2 participants