Search in sources :

Example 1 with ReconciliationResult

use of io.stackgres.operator.conciliation.ReconciliationResult in project stackgres by ongres.

the class DistributedLogsConciliatorTest method shouldNotIgnoreChangesMarkedPauseUntilRestartAnnotationIfClusterIsNotPendingToRestart.

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

Example 2 with ReconciliationResult

use of io.stackgres.operator.conciliation.ReconciliationResult in project stackgres by ongres.

the class DistributedLogsConciliatorTest method shouldIgnoreDeletionsMarkedWithPauseUntilRestartAnnotationIfTheClusterIsPendingToRestart.

@Test
@DisplayName("Conciliation Should Ignore Deletions On Resources Marked With Reconciliation " + "Pause Until Restart Annotation If The Cluster Is Pending To Restart")
void shouldIgnoreDeletionsMarkedWithPauseUntilRestartAnnotationIfTheClusterIsPendingToRestart() {
    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);
    reset(statusManager);
    when(statusManager.isPendingRestart(distributedLogs)).thenReturn(true);
    ReconciliationResult result = conciliator.evalReconciliationState(getConciliationResource());
    assertEquals(0, result.getDeletions().size());
    assertTrue(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)

Example 3 with ReconciliationResult

use of io.stackgres.operator.conciliation.ReconciliationResult in project stackgres by ongres.

the class DistributedLogsConciliatorTest method shouldIgnoreChangesMarkedPauseUntilRestartAnnotationIfClusterIsPendingToRestart.

@Test
@DisplayName("Conciliation Should Ignore Changes On Resources Marked With Reconciliation " + "Pause Until Restart Annotation If The Cluster Is Pending To Restart")
void shouldIgnoreChangesMarkedPauseUntilRestartAnnotationIfClusterIsPendingToRestart() {
    final List<HasMetadata> requiredResources = KubernetessMockResourceGenerationUtil.buildResources("test", "test");
    final List<HasMetadata> deployedResources = deepCopy(requiredResources);
    deployedResources.stream().findAny().orElseThrow().getMetadata().setAnnotations(Map.of(StackGresContext.RECONCILIATION_PAUSE_UNTIL_RESTART_KEY, Boolean.TRUE.toString()));
    Conciliator<StackGresDistributedLogs> conciliator = buildConciliator(requiredResources, deployedResources);
    reset(statusManager);
    when(statusManager.isPendingRestart(distributedLogs)).thenReturn(true);
    ReconciliationResult result = conciliator.evalReconciliationState(getConciliationResource());
    assertEquals(0, result.getPatches().size());
    assertTrue(result.isUpToDate());
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) StackGresDistributedLogs(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs) ReconciliationResult(io.stackgres.operator.conciliation.ReconciliationResult) ConciliatorTest(io.stackgres.operator.conciliation.ConciliatorTest) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with ReconciliationResult

use of io.stackgres.operator.conciliation.ReconciliationResult in project stackgres by ongres.

the class DbOpsConciliator method evalReconciliationState.

@Override
public ReconciliationResult evalReconciliationState(StackGresDbOps config) {
    final ReconciliationResult reconciliationResult = super.evalReconciliationState(config);
    reconciliationResult.setDeletions(reconciliationResult.getDeletions().stream().filter(ReconciliationUtil::isResourceReconciliationNotPausedUntilRestart).collect(Collectors.toUnmodifiableList()));
    reconciliationResult.setPatches(reconciliationResult.getPatches().stream().filter(tuple -> ReconciliationUtil.isResourceReconciliationNotPausedUntilRestart(tuple.v2)).collect(Collectors.toUnmodifiableList()));
    return reconciliationResult;
}
Also used : ReconciliationResult(io.stackgres.operator.conciliation.ReconciliationResult) ReconciliationUtil(io.stackgres.operator.conciliation.ReconciliationUtil)

Example 5 with ReconciliationResult

use of io.stackgres.operator.conciliation.ReconciliationResult 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

ReconciliationResult (io.stackgres.operator.conciliation.ReconciliationResult)8 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)4 StackGresDistributedLogs (io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs)4 ConciliatorTest (io.stackgres.operator.conciliation.ConciliatorTest)4 ReconciliationUtil (io.stackgres.operator.conciliation.ReconciliationUtil)4 DisplayName (org.junit.jupiter.api.DisplayName)4 Test (org.junit.jupiter.api.Test)4 ArrayList (java.util.ArrayList)2 Random (java.util.Random)2