Skip to content

Commit 0aa5b49

Browse files
csviriiocaneldependabot[bot]metacosmlburgazzoli
authored
Informer based CustomResourceEventSource and caching (#581)
feat: This is a major change and backbone of v2. We change also how the Resources are addressed both internally and from event source with CustomResourceID. Additional improvements also added. * chore: renaming vars named k8sClient to kubernetsClient * chore(deps): bump jandex-maven-plugin from 1.1.1 to 1.2.1 (#592) Bumps [jandex-maven-plugin](https://github.com/wildfly/jandex-maven-plugin) from 1.1.1 to 1.2.1. - [Release notes](https://github.com/wildfly/jandex-maven-plugin/releases) - [Commits](wildfly/jandex-maven-plugin@1.1.1...1.2.1) --- updated-dependencies: - dependency-name: org.jboss.jandex:jandex-maven-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps-dev): bump mockito-core from 3.12.4 to 4.0.0 (#591) Bumps [mockito-core](https://github.com/mockito/mockito) from 3.12.4 to 4.0.0. - [Release notes](https://github.com/mockito/mockito/releases) - [Commits](mockito/mockito@v3.12.4...v4.0.0) --- updated-dependencies: - dependency-name: org.mockito:mockito-core dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * feature: Build PR on v2 * chore(ci): use Java 17 * chore(ci): use only Temurin distribution * chore: add generics to PostExecutionControl to reduce IDEs noise (#594) * chore: polish the junit5 extension (#593) * feat: Use informers as CustomResourceEventSource backbone and cache Co-authored-by: Ioannis Canellos <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Chris Laprun <[email protected]> Co-authored-by: Luca Burgazzoli <[email protected]>
1 parent b412821 commit 0aa5b49

File tree

59 files changed

+615
-910
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+615
-910
lines changed

Diff for: .github/workflows/master-snapshot-release.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ jobs:
1515
runs-on: ubuntu-latest
1616
strategy:
1717
matrix:
18-
java: [11, 16]
19-
distribution: [temurin, adopt-openj9]
18+
java: [ 11, 17 ]
19+
distribution: [ temurin ]
2020
kubernetes: [ 'v1.17.13','v1.18.20','v1.19.14','v1.20.10','v1.21.4', 'v1.22.1' ]
2121
steps:
2222
- uses: actions/checkout@v2

Diff for: .github/workflows/pr.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ concurrency:
88
cancel-in-progress: true
99
on:
1010
pull_request:
11-
branches: [ master ]
11+
branches: [ master, v2 ]
1212
workflow_dispatch:
1313
jobs:
1414
build:
1515
runs-on: ubuntu-latest
1616
strategy:
1717
matrix:
18-
java: [ 11 ]
19-
distribution: [ temurin, adopt-openj9 ]
18+
java: [ 11, 17 ]
19+
distribution: [ temurin ]
2020
kubernetes: [ 'v1.17.13','v1.18.20','v1.19.14','v1.20.10','v1.21.4', 'v1.22.1' ]
2121
steps:
2222
- uses: actions/checkout@v2

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,5 @@ target/
1010

1111
# VSCode
1212
.factorypath
13+
14+
.mvn/wrapper/maven-wrapper.jar

Diff for: micrometer-support/src/main/java/io/javaoperatorsdk/operator/micrometer/MicrometerMetrics.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import io.javaoperatorsdk.operator.Metrics;
77
import io.javaoperatorsdk.operator.processing.DefaultEventHandler.EventMonitor;
8+
import io.javaoperatorsdk.operator.processing.event.CustomResourceID;
89
import io.javaoperatorsdk.operator.processing.event.Event;
910
import io.micrometer.core.instrument.MeterRegistry;
1011
import io.micrometer.core.instrument.Timer;
@@ -15,12 +16,12 @@ public class MicrometerMetrics implements Metrics {
1516
private final MeterRegistry registry;
1617
private final EventMonitor monitor = new EventMonitor() {
1718
@Override
18-
public void processedEvent(String uid, Event event) {
19+
public void processedEvent(CustomResourceID uid, Event event) {
1920
incrementProcessedEventsNumber();
2021
}
2122

2223
@Override
23-
public void failedEvent(String uid, Event event) {
24+
public void failedEvent(CustomResourceID uid, Event event) {
2425
incrementControllerRetriesNumber();
2526
}
2627
};

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/ControllerUtils.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static String getNameFor(Class<? extends ResourceController> controllerCl
1818
final var annotation = controllerClass.getAnnotation(Controller.class);
1919
if (annotation != null) {
2020
final var name = annotation.name();
21-
if (!Controller.NULL.equals(name)) {
21+
if (!Controller.EMPTY_STRING.equals(name)) {
2222
return name;
2323
}
2424
}

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/EventListUtils.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
import java.util.List;
44

5-
import io.fabric8.kubernetes.client.Watcher;
65
import io.javaoperatorsdk.operator.processing.event.Event;
76
import io.javaoperatorsdk.operator.processing.event.internal.CustomResourceEvent;
7+
import io.javaoperatorsdk.operator.processing.event.internal.ResourceAction;
88

99
public class EventListUtils {
1010

@@ -13,7 +13,7 @@ public static boolean containsCustomResourceDeletedEvent(List<Event> events) {
1313
.anyMatch(
1414
e -> {
1515
if (e instanceof CustomResourceEvent) {
16-
return ((CustomResourceEvent) e).getAction() == Watcher.Action.DELETED;
16+
return ((CustomResourceEvent) e).getAction() == ResourceAction.DELETED;
1717
} else {
1818
return false;
1919
}

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/Controller.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
@Target({ElementType.TYPE})
1212
public @interface Controller {
1313

14-
String NULL = "";
14+
String EMPTY_STRING = "";
1515
String WATCH_CURRENT_NAMESPACE = "JOSDK_WATCH_CURRENT";
1616
String NO_FINALIZER = "JOSDK_NO_FINALIZER";
1717

18-
String name() default NULL;
18+
String name() default EMPTY_STRING;
1919

2020
/**
2121
* Optional finalizer name, if it is not provided, one will be automatically generated. If the
@@ -24,7 +24,7 @@
2424
*
2525
* @return the finalizer name
2626
*/
27-
String finalizerName() default NULL;
27+
String finalizerName() default EMPTY_STRING;
2828

2929
/**
3030
* If true, will dispatch new event to the controller if generation increased since the last
@@ -50,7 +50,7 @@
5050
*
5151
* @return the label selector
5252
*/
53-
String labelSelector() default NULL;
53+
String labelSelector() default EMPTY_STRING;
5454

5555

5656
/**

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/AbstractControllerConfiguration.java

-35
This file was deleted.

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/api/config/DefaultControllerConfiguration.java

+1-24
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class DefaultControllerConfiguration<R extends CustomResource<?, ?>>
1919
private final RetryConfiguration retryConfiguration;
2020
private final String labelSelector;
2121
private final CustomResourceEventFilter<R> customResourceEventFilter;
22-
private Class<R> customResourceClass;
22+
private final Class<R> customResourceClass;
2323
private ConfigurationService service;
2424

2525
public DefaultControllerConfiguration(
@@ -54,29 +54,6 @@ public DefaultControllerConfiguration(
5454
setConfigurationService(service);
5555
}
5656

57-
@Deprecated
58-
public DefaultControllerConfiguration(
59-
String associatedControllerClassName,
60-
String name,
61-
String crdName,
62-
String finalizer,
63-
boolean generationAware,
64-
Set<String> namespaces,
65-
RetryConfiguration retryConfiguration) {
66-
this(
67-
associatedControllerClassName,
68-
name,
69-
crdName,
70-
finalizer,
71-
generationAware,
72-
namespaces,
73-
retryConfiguration,
74-
null,
75-
null,
76-
null,
77-
null);
78-
}
79-
8057
@Override
8158
public String getName() {
8259
return name;

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/ConfiguredController.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ public class ConfiguredController<R extends CustomResource<?, ?>> implements Res
2626
Closeable {
2727
private final ResourceController<R> controller;
2828
private final ControllerConfiguration<R> configuration;
29-
private final KubernetesClient k8sClient;
29+
private final KubernetesClient kubernetesClient;
3030
private EventSourceManager eventSourceManager;
3131

3232
public ConfiguredController(ResourceController<R> controller,
3333
ControllerConfiguration<R> configuration,
34-
KubernetesClient k8sClient) {
34+
KubernetesClient kubernetesClient) {
3535
this.controller = controller;
3636
this.configuration = configuration;
37-
this.k8sClient = k8sClient;
37+
this.kubernetesClient = kubernetesClient;
3838
}
3939

4040
@Override
@@ -140,11 +140,11 @@ public ControllerConfiguration<R> getConfiguration() {
140140
}
141141

142142
public KubernetesClient getClient() {
143-
return k8sClient;
143+
return kubernetesClient;
144144
}
145145

146146
public MixedOperation<R, KubernetesResourceList<R>, Resource<R>> getCRClient() {
147-
return k8sClient.resources(configuration.getCustomResourceClass());
147+
return kubernetesClient.resources(configuration.getCustomResourceClass());
148148
}
149149

150150
/**
@@ -164,7 +164,8 @@ public void start() throws OperatorException {
164164
// check that the custom resource is known by the cluster if configured that way
165165
final CustomResourceDefinition crd; // todo: check proper CRD spec version based on config
166166
if (configuration.getConfigurationService().checkCRDAndValidateLocalModel()) {
167-
crd = k8sClient.apiextensions().v1().customResourceDefinitions().withName(crdName).get();
167+
crd =
168+
kubernetesClient.apiextensions().v1().customResourceDefinitions().withName(crdName).get();
168169
if (crd == null) {
169170
throwMissingCRDException(crdName, specVersion, controllerName);
170171
}

Diff for: operator-framework-core/src/main/java/io/javaoperatorsdk/operator/processing/CustomResourceCache.java

-116
This file was deleted.

0 commit comments

Comments
 (0)