Search in sources :

Example 51 with StackGresCluster

use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.

the class ClusterPatroniEnvVarFactory method createResource.

@Override
public List<EnvVar> createResource(StackGresClusterContext context) {
    StackGresCluster cluster = context.getSource();
    List<EnvVar> additionalEnvVars = Optional.ofNullable(cluster.getSpec()).map(StackGresClusterSpec::getInitData).map(StackGresClusterInitData::getRestore).map(StackGresClusterRestore::getFromBackup).map(StackGresClusterRestoreFromBackup::getPointInTimeRecovery).map(StackGresClusterRestorePitr::getRestoreToTimestamp).map(Instant::parse).map(restoreToTimestamp -> new EnvVarBuilder().withName("RECOVERY_TARGET_TIME").withValue(DateTimeFormatter.ISO_LOCAL_DATE.withZone(ZoneId.from(ZoneOffset.UTC)).format(restoreToTimestamp) + " " + DateTimeFormatter.ISO_LOCAL_TIME.withZone(ZoneId.from(ZoneOffset.UTC)).format(restoreToTimestamp)).build()).map(List::of).orElse(List.of());
    List<EnvVar> patroniEnvVars = createPatroniEnvVars(cluster);
    return ImmutableList.<EnvVar>builder().add(new EnvVarBuilder().withName("PATRONI_RESTAPI_LISTEN").withValue("0.0.0.0:" + EnvoyUtil.PATRONI_PORT).build()).addAll(patroniEnvVars).addAll(additionalEnvVars).build();
}
Also used : StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StackGresClusterRestorePitr(io.stackgres.common.crd.sgcluster.StackGresClusterRestorePitr) StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) StackGresClusterRestore(io.stackgres.common.crd.sgcluster.StackGresClusterRestore) EnvVar(io.fabric8.kubernetes.api.model.EnvVar) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder)

Example 52 with StackGresCluster

use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.

the class PodTemplateSpecFactoryTest method shouldNodeAffinity_HasTheSameRequireDuringSchedulingRequirementsSize.

@Test
void shouldNodeAffinity_HasTheSameRequireDuringSchedulingRequirementsSize() {
    NodeAffinity nodeAffinity = new NodeAffinityFixture().withValidRequirement().build();
    StackGresCluster cluster = new StackGresClusterFixture().withNodeAffinity(nodeAffinity).build();
    io.fabric8.kubernetes.api.model.NodeAffinity k8sPodNodeAffinity = this.podTemplateSpecFactory.buildPodNodeAffinity(cluster);
    assertEquals(2, k8sPodNodeAffinity.getRequiredDuringSchedulingIgnoredDuringExecution().getNodeSelectorTerms().size());
}
Also used : NodeAffinityFixture(io.stackgres.operator.fixture.NodeAffinityFixture) NodeAffinity(io.stackgres.common.crd.NodeAffinity) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StackGresClusterFixture(io.stackgres.operator.fixture.StackGresClusterFixture) Test(org.junit.jupiter.api.Test)

Example 53 with StackGresCluster

use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.

the class PodTemplateSpecFactoryTest method shouldNodeAffinity_HasTheSamePreferredDuringSchedulingRequirementsKey.

@Test
void shouldNodeAffinity_HasTheSamePreferredDuringSchedulingRequirementsKey() {
    NodeAffinity nodeAffinity = new NodeAffinityFixture().withValidPreferredScheduling().build();
    StackGresCluster cluster = new StackGresClusterFixture().withNodeAffinity(nodeAffinity).build();
    io.fabric8.kubernetes.api.model.NodeAffinity k8sPodNodeAffinity = this.podTemplateSpecFactory.buildPodNodeAffinity(cluster);
    k8sPodNodeAffinity.getPreferredDuringSchedulingIgnoredDuringExecution().forEach(preference -> {
        preference.getPreference().getMatchExpressions().forEach(math -> {
            assertEquals(PREFERRED_TOPOLOGY_KEY, math.getKey());
        });
    });
}
Also used : NodeAffinityFixture(io.stackgres.operator.fixture.NodeAffinityFixture) NodeAffinity(io.stackgres.common.crd.NodeAffinity) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StackGresClusterFixture(io.stackgres.operator.fixture.StackGresClusterFixture) Test(org.junit.jupiter.api.Test)

Example 54 with StackGresCluster

use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.

the class PodTemplateSpecFactoryTest method shouldNodeAffinity_HasTheSameRequireDuringSchedulingRequirementsKey.

@Test
void shouldNodeAffinity_HasTheSameRequireDuringSchedulingRequirementsKey() {
    NodeAffinity nodeAffinity = new NodeAffinityFixture().withValidRequirement().build();
    StackGresCluster cluster = new StackGresClusterFixture().withNodeAffinity(nodeAffinity).build();
    io.fabric8.kubernetes.api.model.NodeAffinity k8sPodNodeAffinity = this.podTemplateSpecFactory.buildPodNodeAffinity(cluster);
    k8sPodNodeAffinity.getRequiredDuringSchedulingIgnoredDuringExecution().getNodeSelectorTerms().forEach(term -> {
        term.getMatchExpressions().forEach(math -> {
            assertEquals(REQUIRED_TOPOLY_KEY, math.getKey());
        });
    });
}
Also used : NodeAffinityFixture(io.stackgres.operator.fixture.NodeAffinityFixture) NodeAffinity(io.stackgres.common.crd.NodeAffinity) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StackGresClusterFixture(io.stackgres.operator.fixture.StackGresClusterFixture) Test(org.junit.jupiter.api.Test)

Example 55 with StackGresCluster

use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.

the class DefaultPostgresServicesMutatorTest method clusterWithPostgresServiceNoType_shouldSetClusterIP.

@Test
void clusterWithPostgresServiceNoType_shouldSetClusterIP() {
    StackGresPostgresService primary = new StackGresPostgresService();
    StackGresPostgresService replica = new StackGresPostgresService();
    primary.setEnabled(Boolean.TRUE);
    replica.setEnabled(Boolean.FALSE);
    setPostgresServices(primary, replica);
    StackGresCluster actualCluster = mutate(review);
    StackGresClusterPostgresServices pgServices = actualCluster.getSpec().getPostgresServices();
    assertEquals(Boolean.TRUE, pgServices.getPrimary().getEnabled());
    assertEquals("ClusterIP", pgServices.getPrimary().getType());
    assertEquals(Boolean.FALSE, pgServices.getReplicas().getEnabled());
    assertEquals("ClusterIP", pgServices.getReplicas().getType());
}
Also used : StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StackGresPostgresService(io.stackgres.common.crd.postgres.service.StackGresPostgresService) StackGresClusterPostgresServices(io.stackgres.common.crd.sgcluster.StackGresClusterPostgresServices) Test(org.junit.jupiter.api.Test)

Aggregations

StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)127 Test (org.junit.jupiter.api.Test)48 Optional (java.util.Optional)32 List (java.util.List)31 StackGresClusterSpec (io.stackgres.common.crd.sgcluster.StackGresClusterSpec)27 StackGresClusterInstalledExtension (io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension)25 ImmutableList (com.google.common.collect.ImmutableList)24 Inject (javax.inject.Inject)22 ArrayList (java.util.ArrayList)19 StackGresClusterStatus (io.stackgres.common.crd.sgcluster.StackGresClusterStatus)18 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)15 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)15 StackGresComponent (io.stackgres.common.StackGresComponent)15 StackGresClusterPodStatus (io.stackgres.common.crd.sgcluster.StackGresClusterPodStatus)14 ExtensionInstaller (io.stackgres.common.extension.ExtensionManager.ExtensionInstaller)14 StackGresClusterReview (io.stackgres.operator.common.StackGresClusterReview)13 Collectors (java.util.stream.Collectors)13 BeforeEach (org.junit.jupiter.api.BeforeEach)13 ExtensionUninstaller (io.stackgres.common.extension.ExtensionManager.ExtensionUninstaller)12 JsonUtil (io.stackgres.testutil.JsonUtil)12