Skip to content

Commit cd90e7e

Browse files
committed
feat: expectations
Signed-off-by: Attila Mészáros <[email protected]>
1 parent 7d59c63 commit cd90e7e

File tree

4 files changed

+65
-17
lines changed

4 files changed

+65
-17
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package io.javaoperatorsdk.operator.api.reconciler;
2+
3+
import io.fabric8.kubernetes.api.model.HasMetadata;
4+
import io.javaoperatorsdk.operator.api.config.ControllerConfiguration;
5+
import io.javaoperatorsdk.operator.processing.event.EventSourceRetriever;
6+
import io.javaoperatorsdk.operator.processing.event.source.IndexerResourceCache;
7+
8+
import java.util.Optional;
9+
import java.util.Set;
10+
import java.util.stream.Stream;
11+
12+
public interface CacheAware<P extends HasMetadata> {
13+
default <R> Optional<R> getSecondaryResource(Class<R> expectedType) {
14+
return getSecondaryResource(expectedType, null);
15+
}
16+
17+
<R> Set<R> getSecondaryResources(Class<R> expectedType);
18+
19+
default <R> Stream<R> getSecondaryResourcesAsStream(Class<R> expectedType) {
20+
return getSecondaryResources(expectedType).stream();
21+
}
22+
23+
<R> Optional<R> getSecondaryResource(Class<R> expectedType, String eventSourceName);
24+
25+
ControllerConfiguration<P> getControllerConfiguration();
26+
27+
/**
28+
* Retrieves the primary resource.
29+
*
30+
* @return the primary resource associated with the current reconciliation
31+
*/
32+
P getPrimaryResource();
33+
34+
/**
35+
* Retrieves the primary resource cache.
36+
*
37+
* @return the {@link IndexerResourceCache} associated with the associated {@link Reconciler} for
38+
* this context
39+
*/
40+
@SuppressWarnings("unused")
41+
IndexedResourceCache<P> getPrimaryCache();
42+
43+
EventSourceRetriever<P> eventSourceRetriever();
44+
}

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/reconciler/Context.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,10 @@
1212
import io.javaoperatorsdk.operator.processing.event.EventSourceRetriever;
1313
import io.javaoperatorsdk.operator.processing.event.source.IndexerResourceCache;
1414

15-
public interface Context<P extends HasMetadata> {
15+
public interface Context<P extends HasMetadata> extends CacheAware<P> {
1616

1717
Optional<RetryInfo> getRetryInfo();
1818

19-
default <R> Optional<R> getSecondaryResource(Class<R> expectedType) {
20-
return getSecondaryResource(expectedType, null);
21-
}
22-
23-
<R> Set<R> getSecondaryResources(Class<R> expectedType);
24-
25-
default <R> Stream<R> getSecondaryResourcesAsStream(Class<R> expectedType) {
26-
return getSecondaryResources(expectedType).stream();
27-
}
28-
29-
<R> Optional<R> getSecondaryResource(Class<R> expectedType, String eventSourceName);
30-
31-
ControllerConfiguration<P> getControllerConfiguration();
32-
3319
/**
3420
* Retrieve the {@link ManagedWorkflowAndDependentResourceContext} used to interact with {@link
3521
* io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource}s and associated {@link
@@ -39,8 +25,6 @@ default <R> Stream<R> getSecondaryResourcesAsStream(Class<R> expectedType) {
3925
*/
4026
ManagedWorkflowAndDependentResourceContext managedWorkflowAndDependentResourceContext();
4127

42-
EventSourceRetriever<P> eventSourceRetriever();
43-
4428
KubernetesClient getClient();
4529

4630
/** ExecutorService initialized by framework for workflows. Used for workflow standalone mode. */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package io.javaoperatorsdk.operator.api.reconciler.expectation;
2+
3+
import io.fabric8.kubernetes.api.model.HasMetadata;
4+
5+
import java.time.Duration;
6+
7+
public interface Expectation<P extends HasMetadata> {
8+
9+
boolean isMet(P primary, ExpectationContext<P> context);
10+
11+
Duration timeout();
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package io.javaoperatorsdk.operator.api.reconciler.expectation;
2+
3+
import io.fabric8.kubernetes.api.model.HasMetadata;
4+
import io.javaoperatorsdk.operator.api.reconciler.CacheAware;
5+
6+
public interface ExpectationContext<P extends HasMetadata> extends CacheAware<P> {
7+
8+
}

0 commit comments

Comments
 (0)