Search in sources :

Example 1 with StackGresClusterDbOpsStatus

use of io.stackgres.common.crd.sgcluster.StackGresClusterDbOpsStatus in project stackgres by ongres.

the class ClusterRestartStateHandlerImplTest method initializeClusterStatus.

@Override
protected void initializeClusterStatus(StackGresCluster cluster, List<Pod> pods) {
    final StackGresClusterStatus status = new StackGresClusterStatus();
    final StackGresClusterDbOpsStatus dbOps = new StackGresClusterDbOpsStatus();
    final StackGresClusterDbOpsRestartStatus restartStatus = new StackGresClusterDbOpsRestartStatus();
    restartStatus.setInitialInstances(pods.stream().map(Pod::getMetadata).map(ObjectMeta::getName).collect(Collectors.toList()));
    restartStatus.setPrimaryInstance(getPrimaryInstance(pods).getMetadata().getName());
    dbOps.setRestart(restartStatus);
    status.setDbOps(dbOps);
    cluster.setStatus(status);
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) StackGresClusterDbOpsStatus(io.stackgres.common.crd.sgcluster.StackGresClusterDbOpsStatus) StackGresClusterStatus(io.stackgres.common.crd.sgcluster.StackGresClusterStatus) StackGresClusterDbOpsRestartStatus(io.stackgres.common.crd.sgcluster.StackGresClusterDbOpsRestartStatus)

Example 2 with StackGresClusterDbOpsStatus

use of io.stackgres.common.crd.sgcluster.StackGresClusterDbOpsStatus in project stackgres by ongres.

the class MinorVersionUpgradeRestartStateHandlerImplTest method initializeClusterStatus.

@Override
protected void initializeClusterStatus(StackGresCluster cluster, List<Pod> pods) {
    final StackGresClusterStatus status = new StackGresClusterStatus();
    final StackGresClusterDbOpsStatus dbOps = new StackGresClusterDbOpsStatus();
    final StackGresClusterDbOpsMinorVersionUpgradeStatus minorVersionUpgrade = new StackGresClusterDbOpsMinorVersionUpgradeStatus();
    minorVersionUpgrade.setInitialInstances(pods.stream().map(Pod::getMetadata).map(ObjectMeta::getName).collect(Collectors.toList()));
    minorVersionUpgrade.setPrimaryInstance(getPrimaryInstance(pods).getMetadata().getName());
    minorVersionUpgrade.setSourcePostgresVersion("11.6");
    minorVersionUpgrade.setTargetPostgresVersion(cluster.getSpec().getPostgres().getVersion());
    dbOps.setMinorVersionUpgrade(minorVersionUpgrade);
    status.setDbOps(dbOps);
    cluster.setStatus(status);
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) StackGresClusterDbOpsStatus(io.stackgres.common.crd.sgcluster.StackGresClusterDbOpsStatus) StackGresClusterDbOpsMinorVersionUpgradeStatus(io.stackgres.common.crd.sgcluster.StackGresClusterDbOpsMinorVersionUpgradeStatus) StackGresClusterStatus(io.stackgres.common.crd.sgcluster.StackGresClusterStatus)

Example 3 with StackGresClusterDbOpsStatus

use of io.stackgres.common.crd.sgcluster.StackGresClusterDbOpsStatus in project stackgres by ongres.

the class ClusterRestartStateHandlerImplTest method initializeClusterStatus.

@Override
protected void initializeClusterStatus(StackGresCluster cluster, List<Pod> pods) {
    final StackGresClusterStatus status = new StackGresClusterStatus();
    final StackGresClusterDbOpsStatus dbOps = new StackGresClusterDbOpsStatus();
    final StackGresClusterDbOpsSecurityUpgradeStatus securityUpgrade = new StackGresClusterDbOpsSecurityUpgradeStatus();
    securityUpgrade.setInitialInstances(pods.stream().map(Pod::getMetadata).map(ObjectMeta::getName).collect(Collectors.toList()));
    securityUpgrade.setPrimaryInstance(getPrimaryInstance(pods).getMetadata().getName());
    dbOps.setSecurityUpgrade(securityUpgrade);
    status.setDbOps(dbOps);
    cluster.setStatus(status);
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) StackGresClusterDbOpsStatus(io.stackgres.common.crd.sgcluster.StackGresClusterDbOpsStatus) StackGresClusterDbOpsSecurityUpgradeStatus(io.stackgres.common.crd.sgcluster.StackGresClusterDbOpsSecurityUpgradeStatus) StackGresClusterStatus(io.stackgres.common.crd.sgcluster.StackGresClusterStatus)

Example 4 with StackGresClusterDbOpsStatus

use of io.stackgres.common.crd.sgcluster.StackGresClusterDbOpsStatus in project stackgres by ongres.

the class ResetPatroniInit method getContainer.

@Override
public Container getContainer(StackGresClusterContainerContext context) {
    final StackGresClusterContext clusterContext = context.getClusterContext();
    String primaryInstance = Optional.of(clusterContext.getSource()).map(StackGresCluster::getStatus).map(StackGresClusterStatus::getDbOps).map(StackGresClusterDbOpsStatus::getMajorVersionUpgrade).map(StackGresClusterDbOpsMajorVersionUpgradeStatus::getPrimaryInstance).orElseThrow();
    return new ContainerBuilder().withName("reset-patroni-initialize").withImage(StackGresComponent.KUBECTL.findLatestImageName()).withImagePullPolicy("IfNotPresent").withCommand("/bin/sh", "-ex", ClusterStatefulSetPath.TEMPLATES_PATH.path() + "/" + ClusterStatefulSetPath.LOCAL_BIN_RESET_PATRONI_INITIALIZE_SH_PATH.filename()).addToEnv(new EnvVarBuilder().withName("PRIMARY_INSTANCE").withValue(primaryInstance).build(), new EnvVarBuilder().withName("POD_NAME").withValueFrom(new EnvVarSourceBuilder().withFieldRef(new ObjectFieldSelector("v1", "metadata.name")).build()).build(), new EnvVarBuilder().withName("CLUSTER_NAMESPACE").withValue(clusterContext.getCluster().getMetadata().getNamespace()).build(), new EnvVarBuilder().withName("PATRONI_ENDPOINT_NAME").withValue(patroniServices.configName(clusterContext)).build()).addAllToEnv(patroniEnvironmentVariables.createResource(clusterContext)).withVolumeMounts(new VolumeMountBuilder().withName(PatroniStaticVolume.USER.getVolumeName()).withMountPath("/etc/passwd").withSubPath("etc/passwd").withReadOnly(true).build()).addAllToVolumeMounts(templateMounts.getVolumeMounts(context)).addToVolumeMounts(new VolumeMountBuilder().withName(PatroniStaticVolume.LOCAL_BIN.getVolumeName()).withMountPath("/usr/local/bin/dbops/major-version-upgrade/reset-patroni-initialize.sh").withSubPath("reset-patroni-initialize.sh").withReadOnly(true).build()).addAllToVolumeMounts(postgresDataMounts.getVolumeMounts(context)).build();
}
Also used : StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) ObjectFieldSelector(io.fabric8.kubernetes.api.model.ObjectFieldSelector) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) EnvVarSourceBuilder(io.fabric8.kubernetes.api.model.EnvVarSourceBuilder) StackGresClusterDbOpsStatus(io.stackgres.common.crd.sgcluster.StackGresClusterDbOpsStatus) StackGresClusterContext(io.stackgres.operator.conciliation.cluster.StackGresClusterContext) VolumeMountBuilder(io.fabric8.kubernetes.api.model.VolumeMountBuilder) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder)

Example 5 with StackGresClusterDbOpsStatus

use of io.stackgres.common.crd.sgcluster.StackGresClusterDbOpsStatus 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

StackGresClusterDbOpsStatus (io.stackgres.common.crd.sgcluster.StackGresClusterDbOpsStatus)6 StackGresClusterStatus (io.stackgres.common.crd.sgcluster.StackGresClusterStatus)4 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)3 StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)2 StackGresClusterContext (io.stackgres.operator.conciliation.cluster.StackGresClusterContext)2 ContainerBuilder (io.fabric8.kubernetes.api.model.ContainerBuilder)1 EnvVarBuilder (io.fabric8.kubernetes.api.model.EnvVarBuilder)1 EnvVarSourceBuilder (io.fabric8.kubernetes.api.model.EnvVarSourceBuilder)1 ObjectFieldSelector (io.fabric8.kubernetes.api.model.ObjectFieldSelector)1 VolumeMountBuilder (io.fabric8.kubernetes.api.model.VolumeMountBuilder)1 ClusterDbOpsMajorVersionUpgradeStatus (io.stackgres.apiweb.dto.cluster.ClusterDbOpsMajorVersionUpgradeStatus)1 ClusterDbOpsMinorVersionUpgradeStatus (io.stackgres.apiweb.dto.cluster.ClusterDbOpsMinorVersionUpgradeStatus)1 ClusterDbOpsRestartStatus (io.stackgres.apiweb.dto.cluster.ClusterDbOpsRestartStatus)1 ClusterDbOpsSecurityUpgradeStatus (io.stackgres.apiweb.dto.cluster.ClusterDbOpsSecurityUpgradeStatus)1 ClusterDbOpsStatus (io.stackgres.apiweb.dto.cluster.ClusterDbOpsStatus)1 StackGresComponent (io.stackgres.common.StackGresComponent)1 StackGresDistributedLogsUtil (io.stackgres.common.StackGresDistributedLogsUtil)1 StackGresClusterDbOpsMinorVersionUpgradeStatus (io.stackgres.common.crd.sgcluster.StackGresClusterDbOpsMinorVersionUpgradeStatus)1 StackGresClusterDbOpsRestartStatus (io.stackgres.common.crd.sgcluster.StackGresClusterDbOpsRestartStatus)1 StackGresClusterDbOpsSecurityUpgradeStatus (io.stackgres.common.crd.sgcluster.StackGresClusterDbOpsSecurityUpgradeStatus)1