Search in sources :

Example 1 with StackGresClusterContainerContext

use of io.stackgres.operator.conciliation.factory.cluster.StackGresClusterContainerContext in project stackgres by ongres.

the class AbstractEnvoy method getContainer.

@Override
public Container getContainer(StackGresClusterContainerContext context) {
    ContainerBuilder container = new ContainerBuilder();
    container.withName(NAME).withImage(StackGresComponent.ENVOY.findLatestImageName()).withImagePullPolicy("IfNotPresent").withVolumeMounts(new VolumeMountBuilder().withName(NAME).withMountPath("/etc/envoy").withReadOnly(true).build()).addAllToVolumeMounts(getVolumeMounts(context)).withPorts(new ContainerPortBuilder().withProtocol("TCP").withContainerPort(EnvoyUtil.PG_ENTRY_PORT).build(), new ContainerPortBuilder().withProtocol("TCP").withContainerPort(EnvoyUtil.PG_REPL_ENTRY_PORT).build()).withCommand("/usr/local/bin/envoy").withArgs(Seq.of("-c", "/etc/envoy/default_envoy.yaml", "--bootstrap-version", "2").append(Seq.of(ENVOY_LOGGER.isTraceEnabled()).filter(traceEnabled -> traceEnabled).map(traceEnabled -> ImmutableList.of("-l", "debug")).flatMap(List::stream)).toArray(String[]::new));
    return container.build();
}
Also used : VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) StackGresContext(io.stackgres.common.StackGresContext) VolumeFactory(io.stackgres.operator.conciliation.factory.VolumeFactory) ConfigMapVolumeSourceBuilder(io.fabric8.kubernetes.api.model.ConfigMapVolumeSourceBuilder) Container(io.fabric8.kubernetes.api.model.Container) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) LoggerFactory(org.slf4j.LoggerFactory) Seq(org.jooq.lambda.Seq) StackgresClusterContainers(io.stackgres.common.StackgresClusterContainers) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Inject(javax.inject.Inject) StatefulSetDynamicVolumes(io.stackgres.operator.conciliation.factory.cluster.StatefulSetDynamicVolumes) EnvoyUtil(io.stackgres.common.EnvoyUtil) ImmutableVolumePair(io.stackgres.operator.conciliation.factory.ImmutableVolumePair) VolumeMountBuilder(io.fabric8.kubernetes.api.model.VolumeMountBuilder) StackGresClusterPod(io.stackgres.common.crd.sgcluster.StackGresClusterPod) VolumePair(io.stackgres.operator.conciliation.factory.VolumePair) YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) ContainerFactory(io.stackgres.operator.conciliation.factory.ContainerFactory) Volume(io.fabric8.kubernetes.api.model.Volume) StackGresClusterContainerContext(io.stackgres.operator.conciliation.factory.cluster.StackGresClusterContainerContext) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) StackGresClusterContext(io.stackgres.operator.conciliation.cluster.StackGresClusterContext) LabelFactoryForCluster(io.stackgres.common.LabelFactoryForCluster) VolumeBuilder(io.fabric8.kubernetes.api.model.VolumeBuilder) YamlMapperProvider(io.stackgres.common.YamlMapperProvider) ResourceUtil(io.stackgres.operatorframework.resource.ResourceUtil) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) StackGresComponent(io.stackgres.common.StackGresComponent) StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) NotNull(org.jetbrains.annotations.NotNull) ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) VolumeMountBuilder(io.fabric8.kubernetes.api.model.VolumeMountBuilder)

Example 2 with StackGresClusterContainerContext

use of io.stackgres.operator.conciliation.factory.cluster.StackGresClusterContainerContext in project stackgres by ongres.

the class ContextUtil method toPostgresContext.

public static PostgresContainerContext toPostgresContext(StackGresClusterContainerContext context) {
    final StackGresClusterContext clusterContext = context.getClusterContext();
    final StackGresCluster cluster = clusterContext.getSource();
    ImmutablePostgresContainerContext.Builder contextBuilder = Optional.of(clusterContext.getSource()).map(StackGresCluster::getStatus).map(StackGresClusterStatus::getDbOps).map(StackGresClusterDbOpsStatus::getMajorVersionUpgrade).map(majorVersionUpgradeStatus -> {
        String targetVersion = majorVersionUpgradeStatus.getTargetPostgresVersion();
        String sourceVersion = majorVersionUpgradeStatus.getSourcePostgresVersion();
        String sourceMajorVersion = StackGresComponent.POSTGRESQL.findMajorVersion(sourceVersion);
        return ImmutablePostgresContainerContext.builder().from(context).postgresMajorVersion(StackGresComponent.POSTGRESQL.findMajorVersion(targetVersion)).oldMajorVersion(sourceMajorVersion).imageBuildMajorVersion(StackGresComponent.POSTGRESQL.findBuildMajorVersion(targetVersion)).oldImageBuildMajorVersion(StackGresComponent.POSTGRESQL.findBuildMajorVersion(sourceVersion)).postgresVersion(targetVersion).oldPostgresVersion(sourceVersion);
    }).orElseGet(() -> {
        final String postgresVersion = cluster.getSpec().getPostgres().getVersion();
        final String majorVersion = StackGresComponent.POSTGRESQL.findMajorVersion(postgresVersion);
        final String buildMajorVersion = StackGresComponent.POSTGRESQL.findBuildMajorVersion(postgresVersion);
        return ImmutablePostgresContainerContext.builder().from(context).postgresVersion(postgresVersion).imageBuildMajorVersion(buildMajorVersion).postgresMajorVersion(majorVersion);
    });
    final List<StackGresClusterInstalledExtension> installedExtensions = Optional.ofNullable(cluster.getSpec()).map(StackGresClusterSpec::getToInstallPostgresExtensions).stream().flatMap(Collection::stream).collect(Collectors.toUnmodifiableList());
    contextBuilder.addAllInstalledExtensions(installedExtensions);
    return contextBuilder.build();
}
Also used : StackGresClusterStatus(io.stackgres.common.crd.sgcluster.StackGresClusterStatus) StackGresClusterContainerContext(io.stackgres.operator.conciliation.factory.cluster.StackGresClusterContainerContext) StackGresClusterDbOpsStatus(io.stackgres.common.crd.sgcluster.StackGresClusterDbOpsStatus) StackGresDistributedLogsUtil(io.stackgres.common.StackGresDistributedLogsUtil) StackGresClusterContext(io.stackgres.operator.conciliation.cluster.StackGresClusterContext) Collection(java.util.Collection) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StackGresDistributedLogsSpec(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsSpec) DistributedLogsContainerContext(io.stackgres.operator.conciliation.factory.distributedlogs.DistributedLogsContainerContext) Collectors(java.util.stream.Collectors) StackGresComponent(io.stackgres.common.StackGresComponent) StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) List(java.util.List) StackGresClusterInstalledExtension(io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension) Optional(java.util.Optional) StackGresDistributedLogs(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StackGresClusterDbOpsStatus(io.stackgres.common.crd.sgcluster.StackGresClusterDbOpsStatus) StackGresClusterContext(io.stackgres.operator.conciliation.cluster.StackGresClusterContext) StackGresClusterInstalledExtension(io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension)

Aggregations

StackGresComponent (io.stackgres.common.StackGresComponent)2 StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)2 StackGresClusterSpec (io.stackgres.common.crd.sgcluster.StackGresClusterSpec)2 StackGresClusterContext (io.stackgres.operator.conciliation.cluster.StackGresClusterContext)2 StackGresClusterContainerContext (io.stackgres.operator.conciliation.factory.cluster.StackGresClusterContainerContext)2 List (java.util.List)2 Optional (java.util.Optional)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 YAMLMapper (com.fasterxml.jackson.dataformat.yaml.YAMLMapper)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)1 ConfigMapVolumeSourceBuilder (io.fabric8.kubernetes.api.model.ConfigMapVolumeSourceBuilder)1 Container (io.fabric8.kubernetes.api.model.Container)1 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)1 ContainerPortBuilder (io.fabric8.kubernetes.api.model.ContainerPortBuilder)1 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)1 Volume (io.fabric8.kubernetes.api.model.Volume)1 VolumeBuilder (io.fabric8.kubernetes.api.model.VolumeBuilder)1 VolumeMount (io.fabric8.kubernetes.api.model.VolumeMount)1