use of io.stackgres.common.crd.sgcluster.StackGresClusterDbOpsMajorVersionUpgradeStatus in project stackgres by ongres.
the class InitMajorVersionUpgrade method getContainer.
@Override
public Container getContainer(StackGresClusterContainerContext context) {
final StackGresClusterContext clusterContext = context.getClusterContext();
StackGresClusterDbOpsMajorVersionUpgradeStatus majorVersionUpgradeStatus = Optional.of(clusterContext.getSource()).map(StackGresCluster::getStatus).map(StackGresClusterStatus::getDbOps).map(StackGresClusterDbOpsStatus::getMajorVersionUpgrade).orElseThrow();
String primaryInstance = majorVersionUpgradeStatus.getPrimaryInstance();
String targetVersion = majorVersionUpgradeStatus.getTargetPostgresVersion();
String sourceVersion = majorVersionUpgradeStatus.getSourcePostgresVersion();
String sourceMajorVersion = StackGresComponent.POSTGRESQL.findMajorVersion(sourceVersion);
String locale = majorVersionUpgradeStatus.getLocale();
String encoding = majorVersionUpgradeStatus.getEncoding();
String dataChecksum = majorVersionUpgradeStatus.getDataChecksum().toString();
String link = majorVersionUpgradeStatus.getLink().toString();
String clone = majorVersionUpgradeStatus.getClone().toString();
String check = majorVersionUpgradeStatus.getCheck().toString();
final String targetPatroniImageName = StackGresComponent.PATRONI.findImageName(StackGresComponent.LATEST, ImmutableMap.of(StackGresComponent.POSTGRESQL, targetVersion));
final PostgresContainerContext postgresContainerContext = 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).build();
return new ContainerBuilder().withName(StackgresClusterContainers.MAJOR_VERSION_UPGRADE).withImage(targetPatroniImageName).withImagePullPolicy("IfNotPresent").withCommand("/bin/sh", "-ex", ClusterStatefulSetPath.TEMPLATES_PATH.path() + "/" + ClusterStatefulSetPath.LOCAL_BIN_MAJOR_VERSION_UPGRADE_SH_PATH.filename()).addToEnv(new EnvVarBuilder().withName("PRIMARY_INSTANCE").withValue(primaryInstance).build(), new EnvVarBuilder().withName("TARGET_VERSION").withValue(targetVersion).build(), new EnvVarBuilder().withName("SOURCE_VERSION").withValue(sourceVersion).build(), new EnvVarBuilder().withName("LOCALE").withValue(locale).build(), new EnvVarBuilder().withName("ENCODING").withValue(encoding).build(), new EnvVarBuilder().withName("DATA_CHECKSUM").withValue(dataChecksum).build(), new EnvVarBuilder().withName("LINK").withValue(link).build(), new EnvVarBuilder().withName("CLONE").withValue(clone).build(), new EnvVarBuilder().withName("CHECK").withValue(check).build(), new EnvVarBuilder().withName("POD_NAME").withValueFrom(new EnvVarSourceBuilder().withFieldRef(new ObjectFieldSelector("v1", "metadata.name")).build()).build()).addAllToEnv(majorVersionUpgradeMounts.getDerivedEnvVars(postgresContainerContext)).withVolumeMounts(templateMounts.getVolumeMounts(context)).addAllToVolumeMounts(majorVersionUpgradeMounts.getVolumeMounts(postgresContainerContext)).build();
}
Aggregations