use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs in project stackgres by ongres.
the class PatroniServices method createPatroniService.
private Service createPatroniService(StackGresDistributedLogsContext context) {
StackGresDistributedLogs cluster = context.getSource();
final Map<String, String> primaryLabels = labelFactory.patroniPrimaryLabels(cluster);
String serviceType = Optional.ofNullable(cluster.getSpec()).map(StackGresDistributedLogsSpec::getPostgresServices).map(StackGresPostgresServices::getPrimary).map(StackGresPostgresService::getType).orElse(CLUSTER_IP.toString());
return new ServiceBuilder().withNewMetadata().withNamespace(cluster.getMetadata().getNamespace()).withName(name(context)).withLabels(primaryLabels).endMetadata().withNewSpec().withPorts(new ServicePortBuilder().withProtocol("TCP").withName(PatroniConfigMap.POSTGRES_PORT_NAME).withPort(PatroniUtil.POSTGRES_SERVICE_PORT).withTargetPort(new IntOrString(PatroniConfigMap.POSTGRES_PORT_NAME)).build(), new ServicePortBuilder().withProtocol("TCP").withName(PatroniConfigMap.POSTGRES_REPLICATION_PORT_NAME).withPort(PatroniUtil.REPLICATION_SERVICE_PORT).withTargetPort(new IntOrString(PatroniConfigMap.POSTGRES_REPLICATION_PORT_NAME)).build()).withType(serviceType).endSpec().build();
}
use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs in project stackgres by ongres.
the class PatroniConfigMap method buildSource.
@NotNull
public HasMetadata buildSource(StackGresDistributedLogsContext context) {
final StackGresDistributedLogs cluster = context.getSource();
final String pgVersion = "12.6";
final String patroniLabels;
final Map<String, String> value = labelFactory.patroniClusterLabels(cluster);
try {
patroniLabels = objectMapper.writeValueAsString(value);
} catch (JsonProcessingException ex) {
throw new RuntimeException(ex);
}
// NOPMD
final String pgHost = "0.0.0.0";
final int pgRawPort = EnvoyUtil.PG_PORT;
final int pgPort = EnvoyUtil.PG_PORT;
Map<String, String> data = new HashMap<>();
data.put("PATRONI_SCOPE", labelFactory.clusterScope(cluster));
data.put("PATRONI_KUBERNETES_SCOPE_LABEL", labelFactory.labelMapper().clusterScopeKey());
data.put("PATRONI_KUBERNETES_LABELS", patroniLabels);
data.put("PATRONI_KUBERNETES_USE_ENDPOINTS", "true");
data.put("PATRONI_KUBERNETES_PORTS", getKubernetesPorts(pgPort, pgRawPort));
data.put("PATRONI_SUPERUSER_USERNAME", "postgres");
data.put("PATRONI_REPLICATION_USERNAME", "replicator");
data.put("PATRONI_POSTGRESQL_LISTEN", pgHost + ":" + EnvoyUtil.PG_PORT);
data.put("PATRONI_POSTGRESQL_CONNECT_ADDRESS", "${PATRONI_KUBERNETES_POD_IP}:" + pgRawPort);
data.put("PATRONI_RESTAPI_LISTEN", "0.0.0.0:8008");
data.put("PATRONI_POSTGRESQL_DATA_DIR", PatroniEnvPaths.PG_DATA_PATH.getPath());
data.put("PATRONI_POSTGRESQL_BIN_DIR", "/usr/lib/postgresql/" + pgVersion + "/bin");
data.put("PATRONI_POSTGRES_UNIX_SOCKET_DIRECTORY", PatroniEnvPaths.PG_RUN_PATH.getPath());
if (PATRONI_LOGGER.isTraceEnabled()) {
data.put("PATRONI_LOG_LEVEL", "DEBUG");
}
data.put("PATRONI_SCRIPTS", "1");
return new ConfigMapBuilder().withNewMetadata().withNamespace(cluster.getMetadata().getNamespace()).withName(name(context)).withLabels(value).endMetadata().withData(StackGresUtil.addMd5Sum(data)).build();
}
use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs in project stackgres by ongres.
the class PatroniContainer method getContainer.
@Override
public Container getContainer(DistributedLogsContainerContext context) {
final StackGresDistributedLogs cluster = context.getDistributedLogsContext().getSource();
final String startScript = "/start-patroni.sh";
return new ContainerBuilder().withName(StackgresClusterContainers.PATRONI).withImage(IMAGE_NAME).withCommand("/bin/sh", "-ex", PatroniEnvPaths.LOCAL_BIN_PATH.getPath() + startScript).withImagePullPolicy("IfNotPresent").withPorts(new ContainerPortBuilder().withName(PatroniConfigMap.POSTGRES_PORT_NAME).withProtocol("TCP").withContainerPort(EnvoyUtil.PG_PORT).build(), new ContainerPortBuilder().withName(PATRONI_RESTAPI_PORT_NAME).withProtocol("TCP").withContainerPort(EnvoyUtil.PATRONI_ENTRY_PORT).build()).withVolumeMounts(getVolumeMounts(context)).withEnvFrom(new EnvFromSourceBuilder().withConfigMapRef(new ConfigMapEnvSourceBuilder().withName(cluster.getMetadata().getName()).build()).build()).withEnv(getEnvVar(context)).withLivenessProbe(new ProbeBuilder().withHttpGet(new HTTPGetActionBuilder().withPath("/cluster").withPort(new IntOrString(EnvoyUtil.PATRONI_ENTRY_PORT)).withScheme("HTTP").build()).withInitialDelaySeconds(15).withPeriodSeconds(20).withFailureThreshold(6).build()).withReadinessProbe(new ProbeBuilder().withHttpGet(new HTTPGetActionBuilder().withPath("/read-only").withPort(new IntOrString(EnvoyUtil.PATRONI_ENTRY_PORT)).withScheme("HTTP").build()).withInitialDelaySeconds(5).withPeriodSeconds(10).build()).build();
}
use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs in project stackgres by ongres.
the class DistributedLogsRequiredResourcesGeneratorTest method get095Cluster.
private StackGresDistributedLogs get095Cluster() {
StackGresDistributedLogs distributedLogs095 = JsonUtil.readFromJson("distributedlogs/0.9.json", StackGresDistributedLogs.class);
distributedLogs095.getMetadata().setNamespace(randomNamespace);
distributedLogs095.getMetadata().setName(randomName);
distributedLogs095.getMetadata().setUid(clusterUid);
return distributedLogs095;
}
use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs in project stackgres by ongres.
the class DistributedLogsRequiredResourcesGeneratorTest method givenADistributedLogsIn095_shouldGenerateAStsCompatibleWithThatVersion.
@Test
void givenADistributedLogsIn095_shouldGenerateAStsCompatibleWithThatVersion() {
StackGresDistributedLogs distributedLogs095 = get095Cluster();
StatefulSet deployedS = get095Sts(distributedLogs095);
StatefulSet generatedSts = generator.getRequiredResources(distributedLogs095).stream().filter(r -> r.getKind().equals("StatefulSet")).map(r -> (StatefulSet) r).findFirst().orElseThrow();
/*
* Sorting volumes and volume mounts since it has no effect on the stability of the containers,
* but it could throw false failures if unsorted //
*/
sortVolumes(deployedS);
sortVolumes(generatedSts);
assertTrue(stsComparator.isTheSameResource(generatedSts, deployedS));
assertTrue(stsComparator.isResourceContentEqual(generatedSts, deployedS));
}
Aggregations