Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import io.fabric8.kubernetes.api.model.HasMetadata;
import io.javaoperatorsdk.operator.api.config.DefaultResourceConfiguration;
import io.javaoperatorsdk.operator.api.config.ResourceConfiguration;
import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext;
import io.javaoperatorsdk.operator.processing.event.source.SecondaryToPrimaryMapper;
import io.javaoperatorsdk.operator.processing.event.source.informer.Mappers;

Expand Down Expand Up @@ -40,7 +39,7 @@ public SecondaryToPrimaryMapper<R> getSecondaryToPrimaryMapper() {
SecondaryToPrimaryMapper<R> getSecondaryToPrimaryMapper();

@SuppressWarnings("unused")
class InformerConfigurationBuilder<R extends HasMetadata, P extends HasMetadata> {
class InformerConfigurationBuilder<R extends HasMetadata> {

private SecondaryToPrimaryMapper<R> secondaryToPrimaryMapper;
private Set<String> namespaces;
Expand All @@ -51,24 +50,24 @@ private InformerConfigurationBuilder(Class<R> resourceClass) {
this.resourceClass = resourceClass;
}

public InformerConfigurationBuilder<R, P> withSecondaryToPrimaryMapper(
public InformerConfigurationBuilder<R> withSecondaryToPrimaryMapper(
SecondaryToPrimaryMapper<R> secondaryToPrimaryMapper) {
this.secondaryToPrimaryMapper = secondaryToPrimaryMapper;
return this;
}

public InformerConfigurationBuilder<R, P> withNamespaces(String... namespaces) {
public InformerConfigurationBuilder<R> withNamespaces(String... namespaces) {
this.namespaces = namespaces != null ? Set.of(namespaces) : Collections.emptySet();
return this;
}

public InformerConfigurationBuilder<R, P> withNamespaces(Set<String> namespaces) {
public InformerConfigurationBuilder<R> withNamespaces(Set<String> namespaces) {
this.namespaces = namespaces != null ? namespaces : Collections.emptySet();
return this;
}


public InformerConfigurationBuilder<R, P> withLabelSelector(String labelSelector) {
public InformerConfigurationBuilder<R> withLabelSelector(String labelSelector) {
this.labelSelector = labelSelector;
return this;
}
Expand All @@ -80,19 +79,15 @@ public InformerConfiguration<R> build() {
}
}

static <R extends HasMetadata, P extends HasMetadata> InformerConfigurationBuilder<R, P> from(
EventSourceContext<P> context, Class<R> resourceClass) {
static <R extends HasMetadata> InformerConfigurationBuilder<R> from(
Class<R> resourceClass) {
return new InformerConfigurationBuilder<>(resourceClass);
}

@SuppressWarnings({"rawtypes", "unchecked"})
static InformerConfigurationBuilder from(Class resourceClass) {
return new InformerConfigurationBuilder<>(resourceClass);
}

static <R extends HasMetadata, P extends HasMetadata> InformerConfigurationBuilder<R, P> from(
static <R extends HasMetadata> InformerConfigurationBuilder<R> from(
InformerConfiguration<R> configuration) {
return new InformerConfigurationBuilder<R, P>(configuration.getResourceClass())
return new InformerConfigurationBuilder<R>(configuration.getResourceClass())
.withNamespaces(configuration.getNamespaces())
.withLabelSelector(configuration.getLabelSelector())
.withSecondaryToPrimaryMapper(configuration.getSecondaryToPrimaryMapper());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void configureWith(KubernetesDependentResourceConfig config) {

@SuppressWarnings("unchecked")
private void configureWith(String labelSelector, Set<String> namespaces) {
final var primaryResourcesRetriever =
final SecondaryToPrimaryMapper<R> primaryResourcesRetriever =
(this instanceof SecondaryToPrimaryMapper) ? (SecondaryToPrimaryMapper<R>) this
: Mappers.fromOwnerReference();
InformerConfiguration<R> ic =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private ConfigMap createConfigMap(CreateUpdateEventFilterTestCustomResource reso
public Map<String, EventSource> prepareEventSources(
EventSourceContext<CreateUpdateEventFilterTestCustomResource> context) {
InformerConfiguration<ConfigMap> informerConfiguration =
InformerConfiguration.from(context, ConfigMap.class)
InformerConfiguration.from(ConfigMap.class)
.withLabelSelector("integrationtest = " + this.getClass().getSimpleName())
.build();
informerEventSource = new InformerEventSource<>(informerConfiguration, client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public Map<String, EventSource> prepareEventSources(
EventSourceContext<InformerEventSourceTestCustomResource> context) {

InformerConfiguration<ConfigMap> config =
InformerConfiguration.from(context, ConfigMap.class)
InformerConfiguration.from(ConfigMap.class)
.withSecondaryToPrimaryMapper(Mappers.fromAnnotation(RELATED_RESOURCE_NAME))
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public Map<String, EventSource> prepareEventSources(
EventSourceContext<MultipleSecondaryEventSourceCustomResource> context) {


var config = InformerConfiguration.from(context, ConfigMap.class)
var config = InformerConfiguration.from(ConfigMap.class)
.withNamespaces(context.getControllerConfiguration().getNamespaces())
.withLabelSelector("multisecondary")
.withSecondaryToPrimaryMapper(s -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public Map<String, EventSource> prepareEventSources(
context.getPrimaryCache().addIndexer(CONFIG_MAP_RELATION_INDEXER, indexer);

var informerConfiguration =
InformerConfiguration.from(context, ConfigMap.class)
InformerConfiguration.from(ConfigMap.class)
.withSecondaryToPrimaryMapper(
(ConfigMap secondaryResource) -> context
.getPrimaryCache()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public Map<String, EventSource> prepareEventSources(EventSourceContext<Webapp> c
.collect(Collectors.toSet());

InformerConfiguration<Tomcat> configuration =
InformerConfiguration.from(context, Tomcat.class)
InformerConfiguration.from(Tomcat.class)
.withSecondaryToPrimaryMapper(webappsMatchingTomcatName)
.build();
return EventSourceInitializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ public WebPageReconciler(KubernetesClient kubernetesClient) {
@Override
public Map<String, EventSource> prepareEventSources(EventSourceContext<WebPage> context) {
var configMapEventSource =
new InformerEventSource<>(InformerConfiguration.from(context, ConfigMap.class)
new InformerEventSource<>(InformerConfiguration.from(ConfigMap.class)
.withLabelSelector(LOW_LEVEL_LABEL_KEY)
.build(), context);
var deploymentEventSource =
new InformerEventSource<>(InformerConfiguration.from(context, Deployment.class)
new InformerEventSource<>(InformerConfiguration.from(Deployment.class)
.withLabelSelector(LOW_LEVEL_LABEL_KEY)
.build(), context);
var serviceEventSource =
new InformerEventSource<>(InformerConfiguration.from(context, Service.class)
new InformerEventSource<>(InformerConfiguration.from(Service.class)
.withLabelSelector(LOW_LEVEL_LABEL_KEY)
.build(), context);
var ingressEventSource =
new InformerEventSource<>(InformerConfiguration.from(context, Ingress.class)
new InformerEventSource<>(InformerConfiguration.from(Ingress.class)
.withLabelSelector(LOW_LEVEL_LABEL_KEY)
.build(), context);
return EventSourceInitializer.nameEventSources(configMapEventSource, deploymentEventSource,
Expand Down