Search in sources :

Example 26 with StackGresDistributedLogs

use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs in project stackgres by ongres.

the class Fluentd method buildSource.

@NotNull
public HasMetadata buildSource(StackGresDistributedLogsContext context) {
    final StackGresDistributedLogs cluster = context.getSource();
    final String namespace = cluster.getMetadata().getNamespace();
    final Map<String, String> data = ImmutableMap.of("fluentd.conf", getFluentdConfig(context));
    final Map<String, String> clusterLabels = labelFactory.clusterLabels(cluster);
    final ConfigMap configMap = new ConfigMapBuilder().withNewMetadata().withNamespace(namespace).withName(FluentdUtil.configName(cluster)).withLabels(clusterLabels).endMetadata().withData(data).build();
    return configMap;
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) StackGresDistributedLogs(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) NotNull(org.jetbrains.annotations.NotNull)

Example 27 with StackGresDistributedLogs

use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs in project stackgres by ongres.

the class DistributedLogsReferenceValidatorTest method giveAnAttemptToUpdateToAnKnownProfile_shouldNotFail.

@Test
void giveAnAttemptToUpdateToAnKnownProfile_shouldNotFail() throws ValidationFailed {
    final StackGresClusterReview review = JsonUtil.readFromJson("cluster_allow_requests/distributed_logs_update.json", StackGresClusterReview.class);
    String distributedLogsName = review.getRequest().getObject().getSpec().getDistributedLogs().getDistributedLogs();
    String namespace = review.getRequest().getObject().getMetadata().getNamespace();
    StackGresDistributedLogs distributedLogs = JsonUtil.readFromJson("distributedlogs/default.json", StackGresDistributedLogs.class);
    when(distributedLogsFinder.findByNameAndNamespace(distributedLogsName, namespace)).thenReturn(Optional.of(distributedLogs));
    validator.validate(review);
    verify(distributedLogsFinder).findByNameAndNamespace(anyString(), anyString());
}
Also used : StackGresClusterReview(io.stackgres.operator.common.StackGresClusterReview) StackGresDistributedLogs(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.jupiter.api.Test)

Example 28 with StackGresDistributedLogs

use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs in project stackgres by ongres.

the class DistributedLogsControllerReconciliator method reconcile.

@SuppressFBWarnings(value = "REC_CATCH_EXCEPTION", justification = "False positives")
@Override
protected ReconciliationResult<Void> reconcile(KubernetesClient client, StackGresDistributedLogsContext context) throws Exception {
    boolean statusUpdated = false;
    ReconciliationResult<Boolean> extensionReconciliationResult = extensionReconciliator.reconcile(client, context);
    if (extensionReconciliationResult.result().orElse(false) && context.getCluster().getStatus() != null && context.getCluster().getStatus().getPodStatuses() != null) {
        if (context.getDistributedLogs().getStatus() == null) {
            context.getDistributedLogs().setStatus(new StackGresDistributedLogsStatus());
        }
        context.getDistributedLogs().getStatus().setPodStatuses(context.getCluster().getStatus().getPodStatuses());
    }
    ReconciliationResult<Boolean> clusterReconciliationResult = clusterReconciliator.reconcile(client, context);
    statusUpdated = statusUpdated || clusterReconciliationResult.result().orElse(false);
    if (extensionReconciliationResult.result().orElse(false) || clusterReconciliationResult.result().orElse(false)) {
        distributedLogsScheduler.updateStatus(context.getDistributedLogs(), StackGresDistributedLogs::getStatus, StackGresDistributedLogs::setStatus);
    }
    return extensionReconciliationResult.join(clusterReconciliationResult);
}
Also used : StackGresDistributedLogs(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs) StackGresDistributedLogsStatus(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsStatus) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 29 with StackGresDistributedLogs

use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs in project stackgres by ongres.

the class EventController method sendEvent.

/**
 * Send an event.
 */
public void sendEvent(EventReason reason, String message, KubernetesClient client) {
    StackGresDistributedLogs distributedLogs = distributedLogsFinder.findByNameAndNamespace(DistributedLogsControllerProperty.DISTRIBUTEDLOGS_NAME.getString(), DistributedLogsControllerProperty.DISTRIBUTEDLOGS_NAMESPACE.getString()).orElse(null);
    sendEvent(reason, message, distributedLogs, client);
}
Also used : StackGresDistributedLogs(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs)

Example 30 with StackGresDistributedLogs

use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs in project stackgres by ongres.

the class ResourceWatcherFactory method onError.

@Override
public void onError(WatcherException cause) {
    StackGresDistributedLogs distributedLogs = distributedLogsFinder.findByNameAndNamespace(DistributedLogsControllerProperty.DISTRIBUTEDLOGS_NAME.getString(), DistributedLogsControllerProperty.DISTRIBUTEDLOGS_NAMESPACE.getString()).orElse(null);
    eventEmitter.sendEvent(DistributedLogsControllerEventReason.DISTRIBUTEDLOGS_CONTROLLER_ERROR, "Watcher was closed unexpectedly: " + (cause.getMessage() != null ? cause.getMessage() : "unknown reason"), distributedLogs);
}
Also used : StackGresDistributedLogs(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs)

Aggregations

StackGresDistributedLogs (io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs)48 NotNull (org.jetbrains.annotations.NotNull)14 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)13 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)12 Inject (javax.inject.Inject)11 Test (org.junit.jupiter.api.Test)11 Optional (java.util.Optional)10 Collectors (java.util.stream.Collectors)10 List (java.util.List)9 Map (java.util.Map)9 Volume (io.fabric8.kubernetes.api.model.Volume)8 StatefulSet (io.fabric8.kubernetes.api.model.apps.StatefulSet)8 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)7 Container (io.fabric8.kubernetes.api.model.Container)7 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)7 VolumeMount (io.fabric8.kubernetes.api.model.VolumeMount)7 StackGresUtil (io.stackgres.common.StackGresUtil)7 StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)6 ImmutableMap (com.google.common.collect.ImmutableMap)6