Search in sources :

Example 31 with StackGresCluster

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();
}
Also used : StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) VolumeMountBuilder(io.fabric8.kubernetes.api.model.VolumeMountBuilder) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder)

Example 32 with StackGresCluster

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);
}
Also used : StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) AbstractPatroniTemplatesConfigMap(io.stackgres.operator.conciliation.factory.v09.AbstractPatroniTemplatesConfigMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder)

Example 33 with StackGresCluster

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();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) VolumeMountBuilder(io.fabric8.kubernetes.api.model.VolumeMountBuilder) ResourceRequirements(io.fabric8.kubernetes.api.model.ResourceRequirements) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) PostgresContainerContext(io.stackgres.operator.conciliation.factory.PostgresContainerContext) HTTPGetActionBuilder(io.fabric8.kubernetes.api.model.HTTPGetActionBuilder) ProbeBuilder(io.fabric8.kubernetes.api.model.ProbeBuilder) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) StackGresClusterContext(io.stackgres.operator.conciliation.cluster.StackGresClusterContext) ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) EnvFromSourceBuilder(io.fabric8.kubernetes.api.model.EnvFromSourceBuilder) ConfigMapEnvSourceBuilder(io.fabric8.kubernetes.api.model.ConfigMapEnvSourceBuilder)

Example 34 with StackGresCluster

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();
    });
}
Also used : SecretBuilder(io.fabric8.kubernetes.api.model.SecretBuilder) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StackGresBackupConfigSpec(io.stackgres.common.crd.sgbackupconfig.StackGresBackupConfigSpec) HashMap(java.util.HashMap) NotNull(org.jetbrains.annotations.NotNull)

Example 35 with StackGresCluster

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);
}
Also used : StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) StackGresClusterPostgres(io.stackgres.common.crd.sgcluster.StackGresClusterPostgres) StackGresExtensionIndexAnyVersion(io.stackgres.common.extension.StackGresExtensionIndexAnyVersion)

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