Skip to content

Persistent state dependent resources #1543

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 57 commits into from
Oct 26, 2022
Merged

Conversation

csviri
Copy link
Collaborator

@csviri csviri commented Oct 13, 2022

No description provided.

csviri and others added 9 commits October 6, 2022 11:04

Co-authored-by: Chris Laprun <metacosm@gmail.com>
* feat: decouple event source from cache + list discriminator (#1378)

* feat: bulk dependent resources (#1448)

* feat: optional eventsource on dependent resources (#1479)

* refactor: simplify handling of reused event sources (#1518)



Co-authored-by: Chris Laprun <metacosm@gmail.com>

* refactor: isolate index handling to BulkDependentResource interface (#1517)

* feat: key based bulk resource creation (#1521)

* improvement: bulk dependent resource api

* merge

Co-authored-by: Chris Laprun <metacosm@gmail.com>
Co-authored-by: Chris Laprun <metacosm@users.noreply.github.com>
@csviri csviri self-assigned this Oct 13, 2022
@csviri csviri force-pushed the persistent-state-dependent-resources branch 2 times, most recently from d483f7b to 74fd92f Compare October 13, 2022 14:36
csviri and others added 2 commits October 17, 2022 18:55
* refactor: deleteBulkResource -> deleteTargetResource

* refactor: remove now unneeded class

* refactor: deleteBulkResourcesIfRequired -> deleteExtraResources

* fix: javadoc
@csviri
Copy link
Collaborator Author

csviri commented Oct 19, 2022

closes #1221

public abstract class AbstractExternalDependentResource<R, P extends HasMetadata, T extends ResourceEventSource<R, P>>
extends AbstractEventSourceHolderDependentResource<R, P, T> {

private final boolean isDependentResourceWithExplicitState =
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would someone use this class and not implement DependentResourceWithExplicitState? If yes, why?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The thing is that the "batteries included" externals should support easily external resources with and without the state. So it should not implement DependentResourceWithExplicitState by default.
But you got a point, that if some just want to imlpement an external resource event source without state, might just extend AbstractEventSourceHolderDependentResource.

Maybe we should rename it to ExternalWithStateSupportDependentResource ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure renaming the class will fix the problem… Why would someone extend AbstractExternalDependentResource and not implement DependentResourceWithExplicitState? Could you detail a use case where someone would extend this class and not want an explicit external state with it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yep, so we have already samples for that (like the mysql sample):
If somebody want a PollingDependentResource, that does not need an external state.

Note that not every external resource needs an explicit state, for example if it can be addressed only by the information in the custom resource. However some might need one, like if a github PR is managed. Therefore the current implementation allows to a dependent resource to extend PollingDependentResource (and others) and to decide if it needs an external state or not implementing the related DependentResourceWithExplicitState.

I thing that we might address in a separate PR and could have an impact on this is this issue:
#1511
(but not necessarily)

However I recognize that Polling and PerResourcePolling DRs are quite a thin layer, that basically just creates an instance of a EventSource on top of a standard functionality. (althoug might be extended later for example with an improved configuration). So the structure might change in the future if we for example make it less explic? "Thus just an external event source that provides an event source" abstraction.

Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems, though, that (most of) the functionality that this class provides is only available if you implement DependentResourceWithExplicitState so I'm wondering about the benefit of having this class plus a separate interface when most (if not all of the behavior) is specific to that one use case.

Copy link
Collaborator Author

@csviri csviri Oct 25, 2022

Choose a reason for hiding this comment

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

Yep, but don't see how we would cover otherwise just optionally having this external state functionality for Polling EventSources.

csviri and others added 12 commits October 21, 2022 11:05

Co-authored-by: Chris Laprun <metacosm@gmail.com>
* feat: decouple event source from cache + list discriminator (#1378)

* feat: bulk dependent resources (#1448)

* feat: optional eventsource on dependent resources (#1479)

* refactor: simplify handling of reused event sources (#1518)



Co-authored-by: Chris Laprun <metacosm@gmail.com>

* refactor: isolate index handling to BulkDependentResource interface (#1517)

* feat: key based bulk resource creation (#1521)

* improvement: bulk dependent resource api

* merge

Co-authored-by: Chris Laprun <metacosm@gmail.com>
Co-authored-by: Chris Laprun <metacosm@users.noreply.github.com>
* refactor: deleteBulkResource -> deleteTargetResource

* refactor: remove now unneeded class

* refactor: deleteBulkResourcesIfRequired -> deleteExtraResources

* fix: javadoc
# Conflicts:
#	operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java
#	operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/BulkDependentResourceReconciler.java
#	operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/SingleDependentResourceReconciler.java
#	operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/external/AbstractPollingDependentResource.java
#	operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java

import static io.javaoperatorsdk.operator.sample.externalstate.ExternalStateDependentReconciler.ID_KEY;

public class ExternalWithStateDependentResourceDependentResourceWith extends
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we rename this class to something better?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

updated

public abstract class AbstractExternalDependentResource<R, P extends HasMetadata, T extends ResourceEventSource<R, P>>
extends AbstractEventSourceHolderDependentResource<R, P, T> {

private final boolean isDependentResourceWithExplicitState =
Copy link
Collaborator

Choose a reason for hiding this comment

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

It seems, though, that (most of) the functionality that this class provides is only available if you implement DependentResourceWithExplicitState so I'm wondering about the benefit of having this class plus a separate interface when most (if not all of the behavior) is specific to that one use case.


@Ignore
public abstract class AbstractPollingDependentResource<R, P extends HasMetadata>
extends AbstractCachingDependentResource<R, P> implements CacheKeyMapper<R> {
extends AbstractExternalDependentResource<R, P, ExternalResourceCachingEventSource<R, P>>
implements CacheKeyMapper<R> {

Copy link
Collaborator

Choose a reason for hiding this comment

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

Is a polling dependent resource necessarily external?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, we don't poll kubernetes API.

@@ -1,16 +1,13 @@
package io.javaoperatorsdk.operator.processing.dependent.kubernetes;

import java.util.HashMap;
import java.util.Optional;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we throw an exception if secondary is null?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is an outdated place, could you pls point me again where do you mean it?

# Conflicts:
#	operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/AbstractDependentResource.java
#	operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/BulkDependentResourceReconciler.java
#	operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/SingleDependentResourceReconciler.java
#	operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/external/AbstractPollingDependentResource.java
#	operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/dependent/kubernetes/KubernetesDependentResource.java
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 28 Code Smells

32.1% 32.1% Coverage
0.0% 0.0% Duplication

@csviri csviri requested a review from metacosm October 26, 2022 09:47
@csviri csviri merged commit f9f7b52 into next Oct 26, 2022
@csviri csviri deleted the persistent-state-dependent-resources branch October 26, 2022 14:19
csviri added a commit that referenced this pull request Oct 28, 2022
csviri added a commit that referenced this pull request Oct 31, 2022
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.

Support External Resource State Management for Dependent Resources
2 participants