Search in sources :

Example 1 with StackGresClusterDbOpsMajorVersionUpgradeStatus

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();
}
Also used : ImmutablePostgresContainerContext(io.stackgres.operator.conciliation.factory.ImmutablePostgresContainerContext) PostgresContainerContext(io.stackgres.operator.conciliation.factory.PostgresContainerContext) ObjectFieldSelector(io.fabric8.kubernetes.api.model.ObjectFieldSelector) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) EnvVarSourceBuilder(io.fabric8.kubernetes.api.model.EnvVarSourceBuilder) StackGresClusterContext(io.stackgres.operator.conciliation.cluster.StackGresClusterContext) StackGresClusterDbOpsMajorVersionUpgradeStatus(io.stackgres.common.crd.sgcluster.StackGresClusterDbOpsMajorVersionUpgradeStatus) StackGresClusterStatus(io.stackgres.common.crd.sgcluster.StackGresClusterStatus) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder)

Aggregations

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 StackGresClusterDbOpsMajorVersionUpgradeStatus (io.stackgres.common.crd.sgcluster.StackGresClusterDbOpsMajorVersionUpgradeStatus)1 StackGresClusterStatus (io.stackgres.common.crd.sgcluster.StackGresClusterStatus)1 StackGresClusterContext (io.stackgres.operator.conciliation.cluster.StackGresClusterContext)1 ImmutablePostgresContainerContext (io.stackgres.operator.conciliation.factory.ImmutablePostgresContainerContext)1 PostgresContainerContext (io.stackgres.operator.conciliation.factory.PostgresContainerContext)1