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);
}
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);
}
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);
}
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();
}
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();
}
Aggregations