Skip to content

Commit cfccc71

Browse files
authored
feat: dependent resource inherits namespaces from controller config (#1020)
1 parent b358329 commit cfccc71

File tree

31 files changed

+102
-92
lines changed

31 files changed

+102
-92
lines changed

operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/informer/InformerConfiguration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,8 @@ public InformerConfiguration<R, P> build() {
105105

106106
static <R extends HasMetadata, P extends HasMetadata> InformerConfigurationBuilder<R, P> from(
107107
EventSourceContext<P> context, Class<R> resourceClass) {
108-
return new InformerConfigurationBuilder<>(resourceClass, context.getConfigurationService());
108+
return new InformerConfigurationBuilder<>(resourceClass, context.getControllerConfiguration()
109+
.getConfigurationService());
109110
}
110111

111112
static InformerConfigurationBuilder from(ConfigurationService configurationService,

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
import java.util.Optional;
44

5-
import io.javaoperatorsdk.operator.api.config.ConfigurationService;
5+
import io.fabric8.kubernetes.api.model.HasMetadata;
6+
import io.javaoperatorsdk.operator.api.config.ControllerConfiguration;
67
import io.javaoperatorsdk.operator.api.reconciler.dependent.ManagedDependentResourceContext;
78

8-
public interface Context {
9+
public interface Context<P extends HasMetadata> {
910

1011
Optional<RetryInfo> getRetryInfo();
1112

@@ -15,7 +16,7 @@ default <T> Optional<T> getSecondaryResource(Class<T> expectedType) {
1516

1617
<T> Optional<T> getSecondaryResource(Class<T> expectedType, String eventSourceName);
1718

18-
ConfigurationService getConfigurationService();
19+
ControllerConfiguration<P> getControllerConfiguration();
1920

2021
ManagedDependentResourceContext managedDependentResourceContext();
2122
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@
33
import java.util.Optional;
44

55
import io.fabric8.kubernetes.api.model.HasMetadata;
6-
import io.javaoperatorsdk.operator.api.config.ConfigurationService;
6+
import io.javaoperatorsdk.operator.api.config.ControllerConfiguration;
77
import io.javaoperatorsdk.operator.api.reconciler.dependent.ManagedDependentResourceContext;
88
import io.javaoperatorsdk.operator.processing.Controller;
99

10-
public class DefaultContext<P extends HasMetadata> implements Context {
10+
public class DefaultContext<P extends HasMetadata> implements Context<P> {
1111

1212
private final RetryInfo retryInfo;
1313
private final Controller<P> controller;
1414
private final P primaryResource;
15-
private final ConfigurationService configurationService;
15+
private final ControllerConfiguration<P> controllerConfiguration;
1616
private ManagedDependentResourceContext managedDependentResourceContext;
1717

1818
public DefaultContext(RetryInfo retryInfo, Controller<P> controller, P primaryResource) {
1919
this.retryInfo = retryInfo;
2020
this.controller = controller;
2121
this.primaryResource = primaryResource;
22-
this.configurationService = controller.getConfiguration().getConfigurationService();
22+
this.controllerConfiguration = controller.getConfiguration();
2323
this.managedDependentResourceContext = new ManagedDependentResourceContext(
2424
controller.getDependents());
2525
}
@@ -37,8 +37,8 @@ public <T> Optional<T> getSecondaryResource(Class<T> expectedType, String eventS
3737
}
3838

3939
@Override
40-
public ConfigurationService getConfigurationService() {
41-
return configurationService;
40+
public ControllerConfiguration<P> getControllerConfiguration() {
41+
return controllerConfiguration;
4242
}
4343

4444
public ManagedDependentResourceContext managedDependentResourceContext() {

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

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import io.fabric8.kubernetes.api.model.HasMetadata;
44
import io.fabric8.kubernetes.client.KubernetesClient;
5-
import io.javaoperatorsdk.operator.api.config.ConfigurationService;
5+
import io.javaoperatorsdk.operator.api.config.ControllerConfiguration;
66
import io.javaoperatorsdk.operator.processing.event.source.EventSource;
77
import io.javaoperatorsdk.operator.processing.event.source.ResourceCache;
88

@@ -14,13 +14,14 @@
1414
public class EventSourceContext<P extends HasMetadata> {
1515

1616
private final ResourceCache<P> primaryCache;
17-
private final ConfigurationService configurationService;
17+
private final ControllerConfiguration<P> controllerConfiguration;
1818
private final KubernetesClient client;
1919

2020
public EventSourceContext(ResourceCache<P> primaryCache,
21-
ConfigurationService configurationService, KubernetesClient client) {
21+
ControllerConfiguration<P> controllerConfiguration,
22+
KubernetesClient client) {
2223
this.primaryCache = primaryCache;
23-
this.configurationService = configurationService;
24+
this.controllerConfiguration = controllerConfiguration;
2425
this.client = client;
2526
}
2627

@@ -34,16 +35,13 @@ public ResourceCache<P> getPrimaryCache() {
3435
}
3536

3637
/**
37-
* Retrieves the {@link ConfigurationService} associated with the operator. This allows, in
38-
* particular, to lookup global configuration information such as the configured
39-
* {@link io.javaoperatorsdk.operator.api.monitoring.Metrics} or
40-
* {@link io.javaoperatorsdk.operator.api.config.Cloner} implementations, which could be useful to
41-
* event sources.
38+
* Retrieves the {@link ControllerConfiguration} associated with the operator. This allows, in
39+
* particular, to lookup controller and global configuration information such as the configured*
4240
*
43-
* @return the {@link ConfigurationService} associated with the operator
41+
* @return the {@link ControllerConfiguration} associated with the operator
4442
*/
45-
public ConfigurationService getConfigurationService() {
46-
return configurationService;
43+
public ControllerConfiguration<P> getControllerConfiguration() {
44+
return controllerConfiguration;
4745
}
4846

4947
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public interface Reconciler<R extends HasMetadata> {
1313
* @return UpdateControl to manage updates on the custom resource (usually the status) after
1414
* reconciliation.
1515
*/
16-
UpdateControl<R> reconcile(R resource, Context context);
16+
UpdateControl<R> reconcile(R resource, Context<R> context);
1717

1818
/**
1919
* Note that this method is used in combination with finalizers. If automatic finalizer handling
@@ -37,7 +37,7 @@ public interface Reconciler<R extends HasMetadata> {
3737
* finalizer to indicate that the resource should not be deleted after all, in which case
3838
* the controller should restore the resource's state appropriately.
3939
*/
40-
default DeleteControl cleanup(R resource, Context context) {
40+
default DeleteControl cleanup(R resource, Context<R> context) {
4141
return DeleteControl.defaultDelete();
4242
}
4343
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public AbstractDependentResource() {
3636
}
3737

3838
@Override
39-
public void reconcile(P primary, Context context) {
39+
public void reconcile(P primary, Context<P> context) {
4040
final var creatable = isCreatable(primary, context);
4141
final var updatable = isUpdatable(primary, context);
4242
if (creatable || updatable) {
@@ -67,7 +67,7 @@ public void reconcile(P primary, Context context) {
6767
}
6868
}
6969

70-
protected void handleCreate(R desired, P primary, Context context) {
70+
protected void handleCreate(R desired, P primary, Context<P> context) {
7171
ResourceID resourceID = ResourceID.fromResource(primary);
7272
R created = null;
7373
try {
@@ -107,7 +107,7 @@ private void prepareEventFiltering(R desired, ResourceID resourceID) {
107107
}
108108
}
109109

110-
protected void handleUpdate(R actual, R desired, P primary, Context context) {
110+
protected void handleUpdate(R actual, R desired, P primary, Context<P> context) {
111111
ResourceID resourceID = ResourceID.fromResource(primary);
112112
R updated = null;
113113
try {
@@ -131,29 +131,29 @@ private RecentOperationCacheFiller<R> eventSourceAsRecentOperationCacheFiller()
131131
}
132132

133133
@Override
134-
public void cleanup(P primary, Context context) {
134+
public void cleanup(P primary, Context<P> context) {
135135
if (isDeletable(primary, context)) {
136136
deleter.delete(primary, context);
137137
}
138138
}
139139

140-
protected R desired(P primary, Context context) {
140+
protected R desired(P primary, Context<P> context) {
141141
throw new IllegalStateException(
142142
"desired method must be implemented if this DependentResource can be created and/or updated");
143143
}
144144

145145
@SuppressWarnings("unused")
146-
protected boolean isCreatable(P primary, Context context) {
146+
protected boolean isCreatable(P primary, Context<P> context) {
147147
return creatable;
148148
}
149149

150150
@SuppressWarnings("unused")
151-
protected boolean isUpdatable(P primary, Context context) {
151+
protected boolean isUpdatable(P primary, Context<P> context) {
152152
return updatable;
153153
}
154154

155155
@SuppressWarnings("unused")
156-
protected boolean isDeletable(P primary, Context context) {
156+
protected boolean isDeletable(P primary, Context<P> context) {
157157
return deletable;
158158
}
159159
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55

66
@FunctionalInterface
77
public interface Creator<R, P extends HasMetadata> {
8-
R create(R desired, P primary, Context context);
8+
R create(R desired, P primary, Context<P> context);
99
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55

66
@FunctionalInterface
77
public interface Deleter<P extends HasMetadata> {
8-
void delete(P primary, Context context);
8+
void delete(P primary, Context<P> context);
99
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import io.javaoperatorsdk.operator.api.reconciler.Context;
77

88
public interface DependentResource<R, P extends HasMetadata> {
9-
void reconcile(P primary, Context context);
9+
void reconcile(P primary, Context<P> context);
1010

11-
default void cleanup(P primary, Context context) {}
11+
default void cleanup(P primary, Context<P> context) {}
1212

1313
Optional<R> getResource(P primaryResource);
1414
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public DesiredEqualsMatcher(AbstractDependentResource<R, P> abstractDependentRes
1212
}
1313

1414
@Override
15-
public Result<R> match(R actualResource, P primary, Context context) {
15+
public Result<R> match(R actualResource, P primary, Context<P> context) {
1616
var desired = abstractDependentResource.desired(primary, context);
1717
return Result.computed(actualResource.equals(desired), desired);
1818
}

0 commit comments

Comments
 (0)