-
Notifications
You must be signed in to change notification settings - Fork 220
feat: error handler improvements #1033
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c8deb6a
feat: adding context to error handler; using exception instead runtim…
csviri b15a63c
fix: error handling compilation issue
csviri 181bf20
feat: added error status update control
csviri 9f3223c
Update operator-framework-core/src/main/java/io/javaoperatorsdk/opera…
csviri 7e9e9ed
fix: improvements on error handling
csviri dd678d5
Merge branch 'error-handling-improvements' of github.com:java-operato…
csviri fda8b49
fix: exception wrapping
csviri a483cef
fix: addind missing override
csviri 35cf400
fix: unit tests
csviri 0206a65
docs: update
csviri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
41 changes: 41 additions & 0 deletions
41
...re/src/main/java/io/javaoperatorsdk/operator/api/reconciler/ErrorStatusUpdateControl.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.javaoperatorsdk.operator.api.reconciler; | ||
|
||
import java.util.Optional; | ||
|
||
import io.fabric8.kubernetes.api.model.HasMetadata; | ||
|
||
public class ErrorStatusUpdateControl<P extends HasMetadata> { | ||
|
||
private final P resource; | ||
private boolean noRetry = false; | ||
|
||
public static <T extends HasMetadata> ErrorStatusUpdateControl<T> updateStatus(T resource) { | ||
return new ErrorStatusUpdateControl<>(resource); | ||
} | ||
|
||
public static <T extends HasMetadata> ErrorStatusUpdateControl<T> noStatusUpdate() { | ||
return new ErrorStatusUpdateControl<>(null); | ||
} | ||
|
||
private ErrorStatusUpdateControl(P resource) { | ||
this.resource = resource; | ||
} | ||
|
||
/** | ||
* Instructs the controller to not retry the error. This is useful for non-recoverable errors. | ||
* | ||
* @return ErrorStatusUpdateControl | ||
*/ | ||
public ErrorStatusUpdateControl<P> withNoRetry() { | ||
this.noRetry = true; | ||
return this; | ||
} | ||
|
||
public Optional<P> getResource() { | ||
return Optional.ofNullable(resource); | ||
} | ||
|
||
public boolean isNoRetry() { | ||
return noRetry; | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -60,32 +60,36 @@ public Controller(Reconciler<P> reconciler, | |
public DeleteControl cleanup(P resource, Context<P> context) { | ||
dependents.cleanup(resource, context); | ||
|
||
return metrics().timeControllerExecution( | ||
new ControllerExecution<>() { | ||
@Override | ||
public String name() { | ||
return "cleanup"; | ||
} | ||
try { | ||
return metrics().timeControllerExecution( | ||
new ControllerExecution<>() { | ||
@Override | ||
public String name() { | ||
return "cleanup"; | ||
} | ||
|
||
@Override | ||
public String controllerName() { | ||
return configuration.getName(); | ||
} | ||
@Override | ||
public String controllerName() { | ||
return configuration.getName(); | ||
} | ||
|
||
@Override | ||
public String successTypeName(DeleteControl deleteControl) { | ||
return deleteControl.isRemoveFinalizer() ? "delete" : "finalizerNotRemoved"; | ||
} | ||
@Override | ||
public String successTypeName(DeleteControl deleteControl) { | ||
return deleteControl.isRemoveFinalizer() ? "delete" : "finalizerNotRemoved"; | ||
} | ||
|
||
@Override | ||
public DeleteControl execute() { | ||
return reconciler.cleanup(resource, context); | ||
} | ||
}); | ||
@Override | ||
public DeleteControl execute() { | ||
return reconciler.cleanup(resource, context); | ||
} | ||
}); | ||
} catch (Exception e) { | ||
throw new IllegalStateException(e); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed it to |
||
} | ||
} | ||
|
||
@Override | ||
public UpdateControl<P> reconcile(P resource, Context<P> context) { | ||
public UpdateControl<P> reconcile(P resource, Context<P> context) throws Exception { | ||
dependents.reconcile(resource, context); | ||
|
||
return metrics().timeControllerExecution( | ||
|
@@ -113,7 +117,7 @@ public String successTypeName(UpdateControl<P> result) { | |
} | ||
|
||
@Override | ||
public UpdateControl<P> execute() { | ||
public UpdateControl<P> execute() throws Exception { | ||
return reconciler.reconcile(resource, context); | ||
} | ||
}); | ||
|
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
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
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
Oops, something went wrong.
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.
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 throw an
IllegalStateException
here?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.
Changed it to
OperatorException
.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.
The goal is to wrap it to a runtime exception (but not the
RuntimeException
), not sure what is the best approach.