-
Notifications
You must be signed in to change notification settings - Fork 222
redesign #906
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
redesign #906
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
79cd6cd
feat: add desired and matches methods on DependentResource
metacosm 1c8aaf8
refactor: move classes to more coherent locations
metacosm 2d885f1
refactor: remove DependentResourceControllerFactory
metacosm 94f546a
refactor: remove Cleaner interface
metacosm 91c4646
refactor: put the reconciling logic in DependentResourceController
metacosm 6271998
refactor: return DependentResource.desired now returns Optional
metacosm 83efe79
chore: add @Ignore to mark internal Reconciler implementations
metacosm 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
8 changes: 0 additions & 8 deletions
8
operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/Dependent.java
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
...ramework-core/src/main/java/io/javaoperatorsdk/operator/api/config/DependentResource.java
This file was deleted.
Oops, something went wrong.
10 changes: 10 additions & 0 deletions
10
...mework-core/src/main/java/io/javaoperatorsdk/operator/api/config/dependent/Dependent.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,10 @@ | ||
package io.javaoperatorsdk.operator.api.config.dependent; | ||
|
||
import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource; | ||
|
||
public @interface Dependent { | ||
|
||
Class<?> resourceType(); | ||
|
||
Class<? extends DependentResource> type(); | ||
} |
3 changes: 2 additions & 1 deletion
3
...onfig/DependentResourceConfiguration.java → ...ndent/DependentResourceConfiguration.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
2 changes: 1 addition & 1 deletion
2
...rator/api/config/KubernetesDependent.java → ...config/dependent/KubernetesDependent.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
7 changes: 3 additions & 4 deletions
7
...rnetesDependentResourceConfiguration.java → ...rnetesDependentResourceConfiguration.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
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
9 changes: 0 additions & 9 deletions
9
...work-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/Builder.java
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
...work-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/Cleaner.java
This file was deleted.
Oops, something went wrong.
62 changes: 62 additions & 0 deletions
62
...src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/DependentResource.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,62 @@ | ||
package io.javaoperatorsdk.operator.api.reconciler.dependent; | ||
|
||
import java.util.Optional; | ||
|
||
import io.fabric8.kubernetes.api.model.HasMetadata; | ||
import io.javaoperatorsdk.operator.api.config.Utils; | ||
import io.javaoperatorsdk.operator.api.reconciler.Context; | ||
import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext; | ||
import io.javaoperatorsdk.operator.processing.event.source.EventSource; | ||
|
||
public interface DependentResource<R, P extends HasMetadata> { | ||
default EventSource initEventSource(EventSourceContext<P> context) { | ||
throw new IllegalStateException("Must be implemented if not automatically provided by the SDK"); | ||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
default Class<R> resourceType() { | ||
return (Class<R>) Utils.getFirstTypeArgumentFromInterface(getClass()); | ||
} | ||
|
||
default void delete(R fetched, P primary, Context context) {} | ||
|
||
/** | ||
* Computes the desired state of the dependent based on the state provided by the specified | ||
* primary resource. | ||
* | ||
* The default implementation returns {@code empty} which corresponds to the case where the | ||
* associated dependent should never be created by the associated reconciler or that the global | ||
* state of the cluster doesn't allow for the resource to be created at this point. | ||
* | ||
* @param primary the primary resource associated with the reconciliation process | ||
* @param context the {@link Context} associated with the reconciliation process | ||
* @return an instance of the dependent resource matching the desired state specified by the | ||
* primary resource or {@code empty} if the dependent shouldn't be created at this point | ||
* (or ever) | ||
*/ | ||
default Optional<R> desired(P primary, Context context) { | ||
return Optional.empty(); | ||
} | ||
|
||
/** | ||
* Checks whether the actual resource as fetched from the cluster matches the desired state | ||
* expressed by the specified primary resource. | ||
* | ||
* The default implementation always return {@code true}, which corresponds to the behavior where | ||
* the dependent never needs to be updated after it's been created. | ||
* | ||
* Note that failure to properly implement this method will lead to infinite loops. In particular, | ||
* for typical Kubernetes resource implementations, simply calling | ||
* {@code desired(primary, context).equals(actual)} is not enough because metadata will usually be | ||
* different. | ||
* | ||
* @param actual the current state of the resource as fetched from the cluster | ||
* @param primary the primary resource associated with the reconciliation request | ||
* @param context the {@link Context} associated with the reconciliation request | ||
* @return {@code true} if the actual state of the resource matches the desired state expressed by | ||
* the specified primary resource, {@code false} otherwise | ||
*/ | ||
default boolean match(R actual, P primary, Context context) { | ||
return true; | ||
} | ||
} |
94 changes: 0 additions & 94 deletions
94
...ava/io/javaoperatorsdk/operator/api/reconciler/dependent/DependentResourceController.java
This file was deleted.
Oops, something went wrong.
26 changes: 0 additions & 26 deletions
26
...javaoperatorsdk/operator/api/reconciler/dependent/DependentResourceControllerFactory.java
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
...work-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/dependent/Updater.java
This file was deleted.
Oops, something went wrong.
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.
I think it should not have a default implementation.
The most common case is like in the WebPage, when all the resources are managed by the operator, IMHO that should be the default approach. If the resource is not managed by us (so not created and not updated) should be probably a feature flag/mode on the resources. Maybe eventually a different type of resource.
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.
I'm not sure I follow. If we're not creating, nor updating the resource, why would it even be a dependent?
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.
To get input from it, like not sure from nodes or other configurations of the cluster. But something like this happens also in the tomcat example too if remember correctly.