use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.
the class PostgresExporter method getContainer.
@Override
public Container getContainer(StackGresClusterContainerContext context) {
StackGresCluster cluster = context.getClusterContext().getSource();
ContainerBuilder container = new ContainerBuilder();
container.withName(NAME).withImage(IMAGE_NAME).withImagePullPolicy("IfNotPresent").withCommand("/bin/sh", "-exc").withArgs("" + "run_postgres_exporter() {\n" + " set -x\n" + " exec /usr/local/bin/postgres_exporter \\\n" + " --log.level=" + (POSTGRES_EXPORTER_LOGGER.isTraceEnabled() ? "debug" : "info") + "\n" + "}\n" + "\n" + "set +x\n" + "while true\n" + "do\n" + " if ( [ -z \"$PID\" ] || [ ! -d \"/proc/$PID\" ] ) \\\n" + " && [ -S '" + ClusterStatefulSetPath.PG_RUN_PATH.path() + "/.s.PGSQL." + EnvoyUtil.PG_PORT + "' ]\n" + " then\n" + " if [ -n \"$PID\" ]\n" + " then\n" + " kill \"$PID\"\n" + " wait \"$PID\" || true\n" + " fi\n" + " run_postgres_exporter &\n" + " PID=\"$!\"\n" + " fi\n" + " sleep 5\n" + "done\n").withEnv(new EnvVarBuilder().withName("PGAPPNAME").withValue(NAME).build(), new EnvVarBuilder().withName("DATA_SOURCE_NAME").withValue("postgresql://postgres@:" + EnvoyUtil.PG_PORT + "/postgres" + "?host=" + ClusterStatefulSetPath.PG_RUN_PATH.path() + "&sslmode=disable").build(), new EnvVarBuilder().withName("PG_EXPORTER_EXTEND_QUERY_PATH").withValue("/var/opt/postgres-exporter/queries.yaml").build(), new EnvVarBuilder().withName("PG_EXPORTER_CONSTANT_LABELS").withValue("cluster_name=" + cluster.getMetadata().getName() + ", namespace=" + cluster.getMetadata().getNamespace()).build()).withPorts(new ContainerPortBuilder().withProtocol("TCP").withContainerPort(9187).build()).addAllToVolumeMounts(postgresSocket.getVolumeMounts(context)).addToVolumeMounts(new VolumeMountBuilder().withName(StatefulSetDynamicVolumes.EXPORTER_QUERIES.getVolumeName()).withMountPath("/var/opt/postgres-exporter/queries.yaml").withSubPath("queries.yaml").withReadOnly(true).build()).addAllToVolumeMounts(containerLocalOverride.getVolumeMounts(context));
return container.build();
}
use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.
the class TemplatesConfigMap method generateResource.
public Stream<HasMetadata> generateResource(StackGresClusterContext context) {
Map<String, String> data = getPatroniTemplates();
final StackGresCluster cluster = context.getSource();
ConfigMap configMap = new ConfigMapBuilder().withNewMetadata().withNamespace(cluster.getMetadata().getNamespace()).withName(name(context)).withLabels(labelFactory.clusterLabels(cluster)).endMetadata().withData(data).build();
return Stream.of(configMap);
}
use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.
the class Patroni method getContainer.
@Override
public Container getContainer(StackGresClusterContainerContext context) {
final StackGresClusterContext clusterContext = context.getClusterContext();
final StackGresCluster cluster = clusterContext.getSource();
final String patroniImageName = String.format(IMAGE_NAME, cluster.getSpec().getPostgres().getVersion());
ResourceRequirements podResources = requirementsFactory.createResource(clusterContext);
final String startScript = clusterContext.getRestoreBackup().isPresent() ? "/start-patroni-with-restore.sh" : "/start-patroni.sh";
final PostgresContainerContext postgresContext = ContextUtil.toPostgresContext(context);
ImmutableList.Builder<VolumeMount> volumeMounts = ImmutableList.<VolumeMount>builder().addAll(postgresSocket.getVolumeMounts(context)).add(new VolumeMountBuilder().withName(PatroniStaticVolume.DSHM.getVolumeName()).withMountPath(ClusterStatefulSetPath.SHARED_MEMORY_PATH.path()).build()).add(new VolumeMountBuilder().withName(PatroniStaticVolume.LOG.getVolumeName()).withMountPath(ClusterStatefulSetPath.PG_LOG_PATH.path()).build()).addAll(localBinMounts.getVolumeMounts(context)).add(new VolumeMountBuilder().withName(StatefulSetDynamicVolumes.PATRONI_ENV.getVolumeName()).withMountPath("/etc/env/patroni").build(), new VolumeMountBuilder().withName(PatroniStaticVolume.PATRONI_CONFIG.getVolumeName()).withMountPath("/etc/patroni").build()).addAll(backupMounts.getVolumeMounts(context)).addAll(postgresExtensions.getVolumeMounts(postgresContext));
clusterContext.getRestoreBackup().ifPresent(ignore -> volumeMounts.addAll(restoreMounts.getVolumeMounts(context)));
return new ContainerBuilder().withName(StackgresClusterContainers.PATRONI).withImage(patroniImageName).withCommand("/bin/sh", "-ex", ClusterStatefulSetPath.LOCAL_BIN_PATH.path() + startScript).withImagePullPolicy("IfNotPresent").withPorts(new ContainerPortBuilder().withProtocol("TCP").withName(PatroniConfigMap.POSTGRES_PORT_NAME).withContainerPort(EnvoyUtil.PG_ENTRY_PORT).build(), new ContainerPortBuilder().withProtocol("TCP").withName(PatroniConfigMap.POSTGRES_REPLICATION_PORT_NAME).withContainerPort(EnvoyUtil.PG_REPL_ENTRY_PORT).build(), new ContainerPortBuilder().withProtocol("TCP").withName(PATRONI_RESTAPI_PORT_NAME).withProtocol("TCP").withContainerPort(EnvoyUtil.PATRONI_ENTRY_PORT).build()).withVolumeMounts(volumeMounts.build()).addToVolumeMounts(clusterContext.getIndexedScripts().stream().map(t -> new VolumeMountBuilder().withName(PatroniScriptsConfigMap.name(clusterContext, t)).withMountPath("/etc/patroni/init-script.d/" + PatroniScriptsConfigMap.scriptName(t)).withSubPath(t.v1.getScript() != null ? PatroniScriptsConfigMap.scriptName(t) : t.v1.getScriptFrom().getConfigMapKeyRef() != null ? t.v1.getScriptFrom().getConfigMapKeyRef().getKey() : t.v1.getScriptFrom().getSecretKeyRef().getKey()).withReadOnly(true).build()).toArray(VolumeMount[]::new)).withEnvFrom(new EnvFromSourceBuilder().withConfigMapRef(new ConfigMapEnvSourceBuilder().withName(PatroniConfigMap.name(clusterContext)).build()).build()).withEnv(getEnvVars(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()).withResources(podResources).build();
}
use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.
the class RestoreSecret method buildSource.
@NotNull
public Optional<HasMetadata> buildSource(StackGresClusterContext context) {
return context.getRestoreBackup().map(restoreBackup -> {
Map<String, String> data = new HashMap<>();
data.put("BACKUP_RESOURCE_VERSION", restoreBackup.getMetadata().getResourceVersion());
String backupNamespace = restoreBackup.getMetadata().getNamespace();
final StackGresBackupConfigSpec backupConfig = restoreBackup.getStatus().getBackupConfig();
data.putAll(envVarFactory.getSecretEnvVar(backupNamespace, backupConfig));
final StackGresCluster cluster = context.getSource();
return new SecretBuilder().withNewMetadata().withNamespace(cluster.getMetadata().getNamespace()).withName(name(context)).withLabels(labelFactory.clusterLabels(cluster)).endMetadata().withType("Opaque").withStringData(StackGresUtil.addMd5Sum(data)).build();
});
}
use of io.stackgres.common.crd.sgcluster.StackGresCluster in project stackgres by ongres.
the class ExtensionsResourceTest method getIndexAnyVersion.
private StackGresExtensionIndexAnyVersion getIndexAnyVersion(String postgresVersion, StackGresClusterExtension clusterExtension) {
StackGresCluster cluster = new StackGresCluster();
cluster.setSpec(new StackGresClusterSpec());
cluster.getSpec().setPostgres(new StackGresClusterPostgres());
cluster.getSpec().getPostgres().setVersion(postgresVersion);
return new StackGresExtensionIndexAnyVersion(cluster, clusterExtension);
}
Aggregations