Skip to content

Commit

Permalink
fix: delay accessing ConfigurationService from DevUI until ready (#640)
Browse files Browse the repository at this point in the history
* fix: inject Operator in JSONRPCService

The Operator should be ready at that point.

* chore: remove old-style Dev UI

* refactor: simplify and remove unused code in DependentInfo
  • Loading branch information
metacosm authored Jul 3, 2023
1 parent edcd7f7 commit 8d95efc
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 215 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,13 @@ void updateControllerConfigurations(
ControllerConfigurationsBuildItem serviceBuildItem,
VersionBuildItem versionBuildItem,
LaunchModeBuildItem launchMode) {
final var supplier = recorder
.configurationServiceSupplier(versionBuildItem.getVersion(),
serviceBuildItem.getControllerConfigs(),
generatedCRDs.getCRDGenerationInfo(),
runTimeConfiguration, buildTimeConfiguration, launchMode.getLaunchMode());
final var supplier = recorder.configurationServiceSupplier(
versionBuildItem.getVersion(),
serviceBuildItem.getControllerConfigs(),
generatedCRDs.getCRDGenerationInfo(),
runTimeConfiguration,
buildTimeConfiguration,
launchMode.getLaunchMode());
syntheticBeanBuildItemBuildProducer.produce(
SyntheticBeanBuildItem.configure(QuarkusConfigurationService.class)
.scope(Singleton.class)
Expand Down

This file was deleted.

61 changes: 0 additions & 61 deletions core/deployment/src/main/resources/dev-templates/controllers.html

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ public QuarkusConfigurationService(
@Override
public <R extends HasMetadata> QuarkusControllerConfiguration<R> getConfigurationFor(Reconciler<R> reconciler) {
final var unwrapped = unwrap(reconciler);
final var configuration = (QuarkusControllerConfiguration<R>) super.getConfigurationFor(
unwrapped);
final var configuration = (QuarkusControllerConfiguration<R>) super.getConfigurationFor(unwrapped);
configuration.initAnnotationConfigurables(unwrapped);
return configuration;
}
Expand Down Expand Up @@ -215,20 +214,22 @@ public DependentResource createFrom(DependentResourceSpec spec, QuarkusControlle
final var dependentKey = getDependentKey(configuration, spec);
var dependentResource = knownDependents.get(dependentKey);
if (dependentResource == null) {
final Class<? extends DependentResource<?, ?>> dependentResourceClass = spec
.getDependentResourceClass();
final var dependent = Arc.container().instance(dependentResourceClass).get();
if (dependent == null) {
throw new IllegalStateException(
"Couldn't find bean associated with DependentResource "
+ dependentResourceClass.getName());
final Class<? extends DependentResource<?, ?>> dependentResourceClass = spec.getDependentResourceClass();
try (final var dependentInstance = Arc.container().instance(dependentResourceClass)) {
final var dependent = dependentInstance.get();

if (dependent == null) {
throw new IllegalStateException(
"Couldn't find bean associated with DependentResource "
+ dependentResourceClass.getName());
}

dependentResource = ClientProxy.unwrap(dependent);
// configure the bean
DependentResourceConfigurationResolver.configure(dependentResource, spec, configuration);
// record the configured dependent for later retrieval if needed
knownDependents.put(dependentKey, dependentResource);
}

dependentResource = ClientProxy.unwrap(dependent);
// configure the bean
DependentResourceConfigurationResolver.configure(dependentResource, spec, configuration);
// record the configured dependent for later retrieval if needed
knownDependents.put(dependentKey, dependentResource);
}
return dependentResource;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@
import java.util.stream.Collectors;

import io.fabric8.kubernetes.api.model.HasMetadata;
import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext;
import io.javaoperatorsdk.operator.processing.Controller;

public class ControllerInfo<P extends HasMetadata> {
private final Controller<P> controller;
private final Set<EventSourceInfo> eventSources;
@SuppressWarnings("rawtypes")
private final Set<DependentInfo> dependents;

@SuppressWarnings({ "rawtypes", "unchecked" })
public ControllerInfo(Controller<P> controller) {
this.controller = controller;
final var context = new EventSourceContext<>(controller.getEventSourceManager().getControllerResourceEventSource(),
controller.getConfiguration(), controller.getClient());
dependents = controller.getConfiguration().getDependentResources().stream()
.map(spec -> new DependentInfo(spec, context))
.map(spec -> new DependentInfo(spec))
.sorted()
.collect(Collectors.toCollection(LinkedHashSet::new));
eventSources = controller.getEventSourceManager().getNamedEventSourcesStream()
Expand Down Expand Up @@ -57,13 +56,14 @@ public Set<EventSourceInfo> getEventSources() {
return eventSources;
}

@SuppressWarnings("rawtypes")
public Set<DependentInfo> getDependents() {
return dependents;
}

@SuppressWarnings("unused")
public List<P> getKnownResources() {
return controller.getEventSourceManager().getControllerResourceEventSource().list().collect(
Collectors.toList());
return controller.getEventSourceManager().getControllerResourceEventSource().list()
.collect(Collectors.toList());
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,74 +1,24 @@
package io.quarkiverse.operatorsdk.runtime.devconsole;

import java.util.Optional;
import java.util.Set;

import io.fabric8.kubernetes.api.model.HasMetadata;
import io.javaoperatorsdk.operator.api.config.dependent.DependentResourceSpec;
import io.javaoperatorsdk.operator.api.reconciler.EventSourceContext;
import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResource;
import io.javaoperatorsdk.operator.processing.dependent.workflow.Condition;
import io.javaoperatorsdk.operator.processing.event.EventSourceMetadata;
import io.javaoperatorsdk.operator.processing.event.source.Configurable;
import io.javaoperatorsdk.operator.processing.event.source.EventSource;
import io.javaoperatorsdk.operator.processing.event.source.ResourceEventSource;
import io.quarkus.arc.Arc;

@SuppressWarnings({ "unused", "rawtypes" })
public class DependentInfo<R, P extends HasMetadata> implements Comparable<DependentInfo> {
private final DependentResourceSpec<R, P> spec;
private final EventSourceContext<P> context;

public DependentInfo(DependentResourceSpec<R, P> spec, EventSourceContext<P> context) {
public DependentInfo(DependentResourceSpec<R, P> spec) {
this.spec = spec;
this.context = context;
}

EventSource eventSource() {
// todo: fix-me
final DependentResource<R, P> dependent = Arc.container()
.instance(spec.getDependentResourceClass()).get();
return dependent.eventSource(context).orElse(null);
}

public EventSourceInfo getEventSource() {
return Optional.ofNullable(eventSource()).map(es -> new EventSourceMetadata() {
@Override
public String name() {
return DependentInfo.this.getName();
}

@Override
public Class<?> type() {
return es.getClass();
}

@Override
public Optional<Class<?>> resourceType() {
return es instanceof ResourceEventSource
? Optional.of(((ResourceEventSource<?, ?>) es).resourceType())
: Optional.empty();
}

@Override
public Optional<?> configuration() {
return es instanceof Configurable
? Optional.of(((Configurable<?>) es).configuration())
: Optional.empty();
}

}).map(EventSourceInfo::new).orElse(null);
}

public String getResourceClass() {
// todo: fix-me
final DependentResource<R, P> dependent = Arc.container()
.instance(spec.getDependentResourceClass()).get();
return dependent.resourceType().getName();
}

public Optional<?> getDependentResourceConfiguration() {
return null; // todo
try (final var dependent = Arc.container().instance(spec.getDependentResourceClass())) {
return dependent.get().resourceType().getName();
}
}

public String getName() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
package io.quarkiverse.operatorsdk.runtime.devui;

import java.util.Collection;
import java.util.stream.Collectors;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;

import io.javaoperatorsdk.operator.Operator;
import io.javaoperatorsdk.operator.processing.Controller;
import io.quarkiverse.operatorsdk.runtime.devconsole.ControllerInfo;
import io.quarkiverse.operatorsdk.runtime.devconsole.ControllersSupplier;

@ApplicationScoped
public class JSONRPCService {
private final ControllersSupplier supplier = new ControllersSupplier();
@Inject
Operator operator;

@SuppressWarnings("rawtypes")
@SuppressWarnings({ "rawtypes", "unchecked" })
public Collection<ControllerInfo> getControllers() {
return supplier.get();
return operator.getRegisteredControllers().stream()
.map(Controller.class::cast)
.map(registeredController -> new ControllerInfo(registeredController))
.collect(Collectors.toList());
}

@SuppressWarnings("unused")
public int controllersCount() {
return supplier.count();
return operator.getRegisteredControllersNumber();
}
}

0 comments on commit 8d95efc

Please sign in to comment.