Search in sources :

Example 16 with StackGresClusterContext

use of io.stackgres.operator.conciliation.cluster.StackGresClusterContext 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 postgresVersion = cluster.getSpec().getPostgres().getVersion();
    final String patroniImageName = StackGresComponent.PATRONI.findImageName(StackGresComponent.LATEST, ImmutableMap.of(StackGresComponent.POSTGRESQL, postgresVersion));
    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().withName(PatroniConfigMap.POSTGRES_PORT_NAME).withProtocol("TCP").withContainerPort(EnvoyUtil.PG_ENTRY_PORT).build(), new ContainerPortBuilder().withName(PatroniConfigMap.POSTGRES_REPLICATION_PORT_NAME).withProtocol("TCP").withContainerPort(EnvoyUtil.PG_REPL_ENTRY_PORT).build(), new ContainerPortBuilder().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)

Aggregations

StackGresClusterContext (io.stackgres.operator.conciliation.cluster.StackGresClusterContext)16 StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)13 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)8 StackGresVersion (io.stackgres.operator.common.StackGresVersion)8 OperatorVersionBinder (io.stackgres.operator.conciliation.OperatorVersionBinder)8 Singleton (javax.inject.Singleton)8 ImmutableList (com.google.common.collect.ImmutableList)7 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)7 LabelFactoryForCluster (io.stackgres.common.LabelFactoryForCluster)7 List (java.util.List)7 Stream (java.util.stream.Stream)7 Inject (javax.inject.Inject)7 Optional (java.util.Optional)6 ImmutableMap (com.google.common.collect.ImmutableMap)5 VolumeMountBuilder (io.fabric8.kubernetes.api.model.VolumeMountBuilder)5 Map (java.util.Map)5 Collectors (java.util.stream.Collectors)5 ContainerPortBuilder (io.fabric8.kubernetes.api.model.ContainerPortBuilder)4 Volume (io.fabric8.kubernetes.api.model.Volume)4 VolumeBuilder (io.fabric8.kubernetes.api.model.VolumeBuilder)4