Skip to content

Commit

Permalink
fix: workaround ObjectMapper issue
Browse files Browse the repository at this point in the history
  • Loading branch information
metacosm committed Mar 30, 2023
1 parent 8c13119 commit 715c783
Show file tree
Hide file tree
Showing 2 changed files with 154 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
package com.redhat.agogos.k8s;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.client.Config;
import io.javaoperatorsdk.operator.api.config.*;
import io.javaoperatorsdk.operator.api.monitoring.Metrics;
import io.javaoperatorsdk.operator.api.reconciler.Reconciler;
import io.javaoperatorsdk.operator.api.reconciler.dependent.DependentResourceFactory;
import io.javaoperatorsdk.operator.processing.dependent.workflow.ManagedWorkflowFactory;
import io.quarkiverse.operatorsdk.runtime.QuarkusConfigurationService;
import io.quarkiverse.operatorsdk.runtime.QuarkusControllerConfiguration;

import javax.enterprise.inject.Produces;
import javax.inject.Inject;
import javax.inject.Singleton;

import java.time.Duration;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ExecutorService;

public class AgogosConfigurationServiceProvider {
@Inject
QuarkusConfigurationService qosdkConfigurationService;

@Produces
@Singleton
AgogosConfigurationService congfigurationService() {
return new AgogosConfigurationService(qosdkConfigurationService);
}

public static class AgogosConfigurationService implements ConfigurationService {

private final QuarkusConfigurationService delegate;
private final ObjectMapper mapper;

@Override
public Config getClientConfiguration() {
return delegate.getClientConfiguration();
}

@Override
public <R extends HasMetadata> QuarkusControllerConfiguration<R> getConfigurationFor(Reconciler<R> reconciler) {
return delegate.getConfigurationFor(reconciler);
}

@Override
public boolean checkCRDAndValidateLocalModel() {
return delegate.checkCRDAndValidateLocalModel();
}

@Override
public int concurrentReconciliationThreads() {
return delegate.concurrentReconciliationThreads();
}

@Override
public int getTerminationTimeoutSeconds() {
return delegate.getTerminationTimeoutSeconds();
}

@Override
public Metrics getMetrics() {
return delegate.getMetrics();
}

@Override
public Optional<LeaderElectionConfiguration> getLeaderElectionConfiguration() {
return delegate.getLeaderElectionConfiguration();
}

@Override
public Optional<InformerStoppedHandler> getInformerStoppedHandler() {
return delegate.getInformerStoppedHandler();
}

@Override
public int concurrentWorkflowExecutorThreads() {
return delegate.concurrentWorkflowExecutorThreads();
}

@Override
public boolean closeClientOnStop() {
return delegate.closeClientOnStop();
}

@Override
public boolean stopOnInformerErrorDuringStartup() {
return delegate.stopOnInformerErrorDuringStartup();
}

@Override
public Duration cacheSyncTimeout() {
return delegate.cacheSyncTimeout();
}

@Override
public DependentResourceFactory<QuarkusControllerConfiguration<?>> dependentResourceFactory() {
return delegate.dependentResourceFactory();
}

@Override
public ManagedWorkflowFactory<QuarkusControllerConfiguration<?>> getWorkflowFactory() {
return delegate.getWorkflowFactory();
}

@Override
public Set<String> getKnownReconcilerNames() {
return delegate.getKnownReconcilerNames();
}

@Override
public Version getVersion() {
return delegate.getVersion();
}

@Override
public Cloner getResourceCloner() {
return delegate.getResourceCloner();
}

@Override
public ObjectMapper getObjectMapper() {
return mapper;
}

@Override
public ExecutorService getExecutorService() {
return delegate.getExecutorService();
}

@Override
public ExecutorService getWorkflowExecutorService() {
return delegate.getWorkflowExecutorService();
}

@Override
public ResourceClassResolver getResourceClassResolver() {
return delegate.getResourceClassResolver();
}

public AgogosConfigurationService(QuarkusConfigurationService delegate) {
this.delegate = delegate;
mapper = new ObjectMapper();
mapper.registerModule(new JavaTimeModule());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.redhat.agogos.k8s.controllers.ComponentController;
import io.javaoperatorsdk.operator.Operator;
import io.javaoperatorsdk.operator.api.config.ConfigurationService;
import io.quarkus.runtime.ShutdownEvent;
import io.quarkus.runtime.StartupEvent;
import org.jboss.logging.Logger;
Expand All @@ -15,8 +14,11 @@
public class PlatformOperator {
private static final Logger LOG = Logger.getLogger(PlatformOperator.class);

// we inject a specific configuration service instance that provides a plain ObjectMapper
// instead of using the one from Fabric8 to work around
// https://github.com/fabric8io/kubernetes-client/issues/5009
@Inject
ConfigurationService configuration;
AgogosConfigurationServiceProvider.AgogosConfigurationService configuration;

/**
* Required to start the operator and register all controllers automatically.
Expand Down

0 comments on commit 715c783

Please sign in to comment.