Search in sources :

Example 41 with StackGresDistributedLogs

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

the class PatroniTemplatesConfigMap method buildSource.

@NotNull
public HasMetadata buildSource(StackGresDistributedLogsContext context) {
    Map<String, String> data = getPatroniTemplates();
    final StackGresDistributedLogs cluster = context.getSource();
    return new ConfigMapBuilder().withNewMetadata().withNamespace(cluster.getMetadata().getNamespace()).withName(name(cluster)).withLabels(labelFactory.clusterLabels(cluster)).endMetadata().withData(data).build();
}
Also used : StackGresDistributedLogs(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) NotNull(org.jetbrains.annotations.NotNull)

Example 42 with StackGresDistributedLogs

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

the class DistributedLogsTransformer method toCustomResource.

@Override
public StackGresDistributedLogs toCustomResource(DistributedLogsDto source, StackGresDistributedLogs original) {
    StackGresDistributedLogs transformation = Optional.ofNullable(original).orElseGet(StackGresDistributedLogs::new);
    transformation.setMetadata(getCustomResourceMetadata(source, original));
    final DistributedLogsSpec spec = source.getSpec();
    if (spec != null) {
        transformation.setSpec(getCustomResourceSpec(spec));
    }
    return transformation;
}
Also used : StackGresDistributedLogs(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs) DistributedLogsSpec(io.stackgres.apiweb.dto.distributedlogs.DistributedLogsSpec) StackGresDistributedLogsSpec(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsSpec)

Example 43 with StackGresDistributedLogs

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

the class DistributedLogsRequiredResourcesGeneratorTest method givenADistributedLogsIn095_shouldGenerateAInitTemplateConfigmapCompatibleWithThatVersion.

@Test
void givenADistributedLogsIn095_shouldGenerateAInitTemplateConfigmapCompatibleWithThatVersion() {
    StackGresDistributedLogs distributedLogs = get095Cluster();
    ConfigMap expectedConfigMap = get095InitTemplateConfigMap(distributedLogs);
    ConfigMap generatedConfigMap = generator.getRequiredResources(distributedLogs).stream().filter(r -> r.getKind().equals("ConfigMap")).filter(r -> r.getMetadata().getName().equals(expectedConfigMap.getMetadata().getName())).map(r -> (ConfigMap) r).findFirst().orElseThrow();
    assertTrue(configMapComparator.isTheSameResource(generatedConfigMap, expectedConfigMap));
    assertTrue(configMapComparator.isResourceContentEqual(generatedConfigMap, expectedConfigMap));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) Container(io.fabric8.kubernetes.api.model.Container) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StackGresClusterList(io.stackgres.common.crd.sgcluster.StackGresClusterList) EnvFromSource(io.fabric8.kubernetes.api.model.EnvFromSource) Seq(org.jooq.lambda.Seq) Mockito.lenient(org.mockito.Mockito.lenient) OwnerReference(io.fabric8.kubernetes.api.model.OwnerReference) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Inject(javax.inject.Inject) StringUtils(io.stackgres.testutil.StringUtils) CharStreams(com.google.common.io.CharStreams) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) StackGresDistributedLogs(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs) Volume(io.fabric8.kubernetes.api.model.Volume) InjectMock(io.quarkus.test.junit.mockito.InjectMock) ImmutableMap(com.google.common.collect.ImmutableMap) OwnerReferenceBuilder(io.fabric8.kubernetes.api.model.OwnerReferenceBuilder) ReconciliationScope(io.stackgres.operator.conciliation.ReconciliationScope) IOException(java.io.IOException) StackGresUtil(io.stackgres.common.StackGresUtil) Reader(java.io.Reader) UUID(java.util.UUID) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) StandardCharsets(java.nio.charset.StandardCharsets) DefaultComparator(io.stackgres.operator.conciliation.comparator.DefaultComparator) JsonUtil(io.stackgres.testutil.JsonUtil) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) List(java.util.List) Stream(java.util.stream.Stream) EnvVarSource(io.fabric8.kubernetes.api.model.EnvVarSource) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) Optional(java.util.Optional) Comparator(java.util.Comparator) CommonDefinition(io.stackgres.common.crd.CommonDefinition) NotNull(org.jetbrains.annotations.NotNull) InputStream(java.io.InputStream) CustomResource(io.fabric8.kubernetes.client.CustomResource) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) StackGresDistributedLogs(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 44 with StackGresDistributedLogs

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

the class DistributedLogsRequiredResourcesGeneratorTest method givenADistributedLogsIn095_shouldGenerateAFluentdConfigmapCompatibleWithThatVersion.

@Test
void givenADistributedLogsIn095_shouldGenerateAFluentdConfigmapCompatibleWithThatVersion() {
    StackGresDistributedLogs distributedLogs = get095Cluster();
    ConfigMap expectedConfigMap = get095FluentdConfigMap(distributedLogs);
    ConfigMap generatedConfigMap = generator.getRequiredResources(distributedLogs).stream().filter(r -> r.getKind().equals("ConfigMap")).filter(r -> r.getMetadata().getName().equals(expectedConfigMap.getMetadata().getName())).map(r -> (ConfigMap) r).findFirst().orElseThrow();
    assertTrue(configMapComparator.isTheSameResource(generatedConfigMap, expectedConfigMap));
    assertTrue(configMapComparator.isResourceContentEqual(generatedConfigMap, expectedConfigMap));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) Container(io.fabric8.kubernetes.api.model.Container) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StackGresClusterList(io.stackgres.common.crd.sgcluster.StackGresClusterList) EnvFromSource(io.fabric8.kubernetes.api.model.EnvFromSource) Seq(org.jooq.lambda.Seq) Mockito.lenient(org.mockito.Mockito.lenient) OwnerReference(io.fabric8.kubernetes.api.model.OwnerReference) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Inject(javax.inject.Inject) StringUtils(io.stackgres.testutil.StringUtils) CharStreams(com.google.common.io.CharStreams) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) StackGresDistributedLogs(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs) Volume(io.fabric8.kubernetes.api.model.Volume) InjectMock(io.quarkus.test.junit.mockito.InjectMock) ImmutableMap(com.google.common.collect.ImmutableMap) OwnerReferenceBuilder(io.fabric8.kubernetes.api.model.OwnerReferenceBuilder) ReconciliationScope(io.stackgres.operator.conciliation.ReconciliationScope) IOException(java.io.IOException) StackGresUtil(io.stackgres.common.StackGresUtil) Reader(java.io.Reader) UUID(java.util.UUID) InputStreamReader(java.io.InputStreamReader) Collectors(java.util.stream.Collectors) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) StatefulSet(io.fabric8.kubernetes.api.model.apps.StatefulSet) StandardCharsets(java.nio.charset.StandardCharsets) DefaultComparator(io.stackgres.operator.conciliation.comparator.DefaultComparator) JsonUtil(io.stackgres.testutil.JsonUtil) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) List(java.util.List) Stream(java.util.stream.Stream) EnvVarSource(io.fabric8.kubernetes.api.model.EnvVarSource) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) Optional(java.util.Optional) Comparator(java.util.Comparator) CommonDefinition(io.stackgres.common.crd.CommonDefinition) NotNull(org.jetbrains.annotations.NotNull) InputStream(java.io.InputStream) CustomResource(io.fabric8.kubernetes.client.CustomResource) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) StackGresDistributedLogs(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 45 with StackGresDistributedLogs

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

the class DistributedLogsConciliatorTest method shouldNotIgnoreDeletionsMarkedPauseUntilRestartAnnotationClusterIsNotPendingToRestart.

@Test
@DisplayName("Conciliation Should Not Ignore Deletions On Resources Marked With Reconciliation " + "Pause Until Restart Annotation If The Cluster Is Not Pending To Restart")
void shouldNotIgnoreDeletionsMarkedPauseUntilRestartAnnotationClusterIsNotPendingToRestart() {
    final List<HasMetadata> requiredResources = KubernetessMockResourceGenerationUtil.buildResources("test", "test");
    final List<HasMetadata> deployedResources = new ArrayList<>(requiredResources);
    int indexToRemove = new Random().nextInt(requiredResources.size());
    deployedResources.get(indexToRemove).getMetadata().setAnnotations(Map.of(StackGresContext.RECONCILIATION_PAUSE_UNTIL_RESTART_KEY, Boolean.TRUE.toString()));
    requiredResources.remove(indexToRemove);
    Conciliator<StackGresDistributedLogs> conciliator = buildConciliator(requiredResources, deployedResources);
    when(statusManager.isPendingRestart(distributedLogs)).thenReturn(false);
    ReconciliationResult result = conciliator.evalReconciliationState(getConciliationResource());
    assertEquals(1, result.getDeletions().size());
    assertFalse(result.isUpToDate());
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) Random(java.util.Random) StackGresDistributedLogs(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs) ReconciliationResult(io.stackgres.operator.conciliation.ReconciliationResult) ArrayList(java.util.ArrayList) ConciliatorTest(io.stackgres.operator.conciliation.ConciliatorTest) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

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