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();
}
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());
}
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());
});
});
}
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());
});
});
}
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());
}
Aggregations