Skip to content

Informer based CustomResourceEventSource and caching #581

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 9 commits into from
Oct 12, 2021
4 changes: 2 additions & 2 deletions .github/workflows/master-snapshot-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: [11, 16]
distribution: [temurin, adopt-openj9]
java: [ 11, 17 ]
distribution: [ temurin ]
kubernetes: [ 'v1.17.13','v1.18.20','v1.19.14','v1.20.10','v1.21.4', 'v1.22.1' ]
steps:
- uses: actions/checkout@v2
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ concurrency:
cancel-in-progress: true
on:
pull_request:
branches: [ master ]
branches: [ master, v2 ]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ 11 ]
distribution: [ temurin, adopt-openj9 ]
java: [ 11, 17 ]
distribution: [ temurin ]
kubernetes: [ 'v1.17.13','v1.18.20','v1.19.14','v1.20.10','v1.21.4', 'v1.22.1' ]
steps:
- uses: actions/checkout@v2
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ target/

# VSCode
.factorypath

.mvn/wrapper/maven-wrapper.jar
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import io.javaoperatorsdk.operator.Metrics;
import io.javaoperatorsdk.operator.processing.DefaultEventHandler.EventMonitor;
import io.javaoperatorsdk.operator.processing.event.CustomResourceID;
import io.javaoperatorsdk.operator.processing.event.Event;
import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.core.instrument.Timer;
Expand All @@ -15,12 +16,12 @@ public class MicrometerMetrics implements Metrics {
private final MeterRegistry registry;
private final EventMonitor monitor = new EventMonitor() {
@Override
public void processedEvent(String uid, Event event) {
public void processedEvent(CustomResourceID uid, Event event) {
incrementProcessedEventsNumber();
}

@Override
public void failedEvent(String uid, Event event) {
public void failedEvent(CustomResourceID uid, Event event) {
incrementControllerRetriesNumber();
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static String getNameFor(Class<? extends ResourceController> controllerCl
final var annotation = controllerClass.getAnnotation(Controller.class);
if (annotation != null) {
final var name = annotation.name();
if (!Controller.NULL.equals(name)) {
if (!Controller.EMPTY_STRING.equals(name)) {
return name;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import java.util.List;

import io.fabric8.kubernetes.client.Watcher;
import io.javaoperatorsdk.operator.processing.event.Event;
import io.javaoperatorsdk.operator.processing.event.internal.CustomResourceEvent;
import io.javaoperatorsdk.operator.processing.event.internal.ResourceAction;

public class EventListUtils {

Expand All @@ -13,7 +13,7 @@ public static boolean containsCustomResourceDeletedEvent(List<Event> events) {
.anyMatch(
e -> {
if (e instanceof CustomResourceEvent) {
return ((CustomResourceEvent) e).getAction() == Watcher.Action.DELETED;
return ((CustomResourceEvent) e).getAction() == ResourceAction.DELETED;
} else {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
@Target({ElementType.TYPE})
public @interface Controller {

String NULL = "";
String EMPTY_STRING = "";
String WATCH_CURRENT_NAMESPACE = "JOSDK_WATCH_CURRENT";
String NO_FINALIZER = "JOSDK_NO_FINALIZER";

String name() default NULL;
String name() default EMPTY_STRING;

/**
* Optional finalizer name, if it is not provided, one will be automatically generated. If the
Expand All @@ -24,7 +24,7 @@
*
* @return the finalizer name
*/
String finalizerName() default NULL;
String finalizerName() default EMPTY_STRING;

/**
* If true, will dispatch new event to the controller if generation increased since the last
Expand All @@ -50,7 +50,7 @@
*
* @return the label selector
*/
String labelSelector() default NULL;
String labelSelector() default EMPTY_STRING;


/**
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class DefaultControllerConfiguration<R extends CustomResource<?, ?>>
private final RetryConfiguration retryConfiguration;
private final String labelSelector;
private final CustomResourceEventFilter<R> customResourceEventFilter;
private Class<R> customResourceClass;
private final Class<R> customResourceClass;
private ConfigurationService service;

public DefaultControllerConfiguration(
Expand Down Expand Up @@ -54,29 +54,6 @@ public DefaultControllerConfiguration(
setConfigurationService(service);
}

@Deprecated
public DefaultControllerConfiguration(
String associatedControllerClassName,
String name,
String crdName,
String finalizer,
boolean generationAware,
Set<String> namespaces,
RetryConfiguration retryConfiguration) {
this(
associatedControllerClassName,
name,
crdName,
finalizer,
generationAware,
namespaces,
retryConfiguration,
null,
null,
null,
null);
}

@Override
public String getName() {
return name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ public class ConfiguredController<R extends CustomResource<?, ?>> implements Res
Closeable {
private final ResourceController<R> controller;
private final ControllerConfiguration<R> configuration;
private final KubernetesClient k8sClient;
private final KubernetesClient kubernetesClient;
private EventSourceManager eventSourceManager;

public ConfiguredController(ResourceController<R> controller,
ControllerConfiguration<R> configuration,
KubernetesClient k8sClient) {
KubernetesClient kubernetesClient) {
this.controller = controller;
this.configuration = configuration;
this.k8sClient = k8sClient;
this.kubernetesClient = kubernetesClient;
}

@Override
Expand Down Expand Up @@ -140,11 +140,11 @@ public ControllerConfiguration<R> getConfiguration() {
}

public KubernetesClient getClient() {
return k8sClient;
return kubernetesClient;
}

public MixedOperation<R, KubernetesResourceList<R>, Resource<R>> getCRClient() {
return k8sClient.resources(configuration.getCustomResourceClass());
return kubernetesClient.resources(configuration.getCustomResourceClass());
}

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

This file was deleted.

Loading