use of io.stackgres.operator.conciliation.cluster.StackGresClusterContext in project stackgres by ongres.
the class OwnerReferenceDecorator method decorate.
@Override
public void decorate(StackGresClusterContext context, Iterable<? extends HasMetadata> resources) {
List<OwnerReference> ownerReferences = List.of(ResourceUtil.getOwnerReference(context.getSource()));
Seq.seq(resources).filter(resource -> Objects.equals(resource.getMetadata().getNamespace(), context.getSource().getMetadata().getNamespace())).filter(resource -> resource.getMetadata().getOwnerReferences().isEmpty()).forEach(resource -> {
resource.getMetadata().setOwnerReferences(ownerReferences);
if (resource.getKind().equals("StatefulSet")) {
StatefulSet sts = (StatefulSet) resource;
sts.getSpec().getVolumeClaimTemplates().forEach(vct -> vct.getMetadata().setOwnerReferences(ownerReferences));
}
});
}
use of io.stackgres.operator.conciliation.cluster.StackGresClusterContext 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();
}
use of io.stackgres.operator.conciliation.cluster.StackGresClusterContext in project stackgres by ongres.
the class PatroniScriptsConfigMap method buildVolume.
@NotNull
public Stream<Volume> buildVolume(StackGresClusterContext context) {
var indexedScripts = context.getIndexedScripts();
var inlineScripts = indexedScripts.stream().filter(t -> t.v1.getScript() != null).map(t -> new VolumeBuilder().withName(name(context, t)).withConfigMap(new ConfigMapVolumeSourceBuilder().withName(name(context, t)).withOptional(false).build()).build()).collect(Collectors.toUnmodifiableList());
var configMapScripts = indexedScripts.stream().filter(t -> t.v1.getScriptFrom() != null).filter(t -> t.v1.getScriptFrom().getConfigMapKeyRef() != null).map(t -> new VolumeBuilder().withName(name(context, t)).withConfigMap(new ConfigMapVolumeSourceBuilder().withName(t.v1.getScriptFrom().getConfigMapKeyRef().getName()).withOptional(false).build()).build()).collect(Collectors.toUnmodifiableList());
var secretScripts = indexedScripts.stream().filter(t -> t.v1.getScriptFrom() != null).filter(t -> t.v1.getScriptFrom().getSecretKeyRef() != null).map(t -> new VolumeBuilder().withName(name(context, t)).withSecret(new SecretVolumeSourceBuilder().withSecretName(t.v1.getScriptFrom().getSecretKeyRef().getName()).withOptional(false).build()).build()).collect(Collectors.toUnmodifiableList());
return ImmutableList.<Volume>builder().addAll(inlineScripts).addAll(configMapScripts).addAll(secretScripts).build().stream();
}
use of io.stackgres.operator.conciliation.cluster.StackGresClusterContext in project stackgres by ongres.
the class OwnerReferenceDecorator method decorate.
@Override
public void decorate(StackGresClusterContext context, Iterable<? extends HasMetadata> resources) {
List<OwnerReference> ownerReferences = getOwnerReferences(context.getSource());
resources.forEach(resource -> {
if (!resource.getMetadata().getOwnerReferences().isEmpty()) {
resource.getMetadata().getOwnerReferences().stream().filter(ownerReference -> ownerReference.getApiVersion().equals(CommonDefinition.GROUP + "/" + CommonDefinition.VERSION)).forEach(ownerReference -> ownerReference.setApiVersion(CommonDefinition.GROUP + "/v1beta1"));
} else {
resource.getMetadata().setOwnerReferences(ownerReferences);
if (resource.getKind().equals("StatefulSet")) {
StatefulSet sts = (StatefulSet) resource;
sts.getSpec().getVolumeClaimTemplates().forEach(vct -> vct.getMetadata().setOwnerReferences(ownerReferences));
}
}
});
}
use of io.stackgres.operator.conciliation.cluster.StackGresClusterContext in project stackgres by ongres.
the class InitRelocateBinaries method getContainer.
@Override
public Container getContainer(StackGresClusterContainerContext context) {
final StackGresClusterContext clusterContext = context.getClusterContext();
final String patroniImageName = StackGresComponent.PATRONI.findImageName(StackGresComponent.LATEST, ImmutableMap.of(StackGresComponent.POSTGRESQL, clusterContext.getCluster().getSpec().getPostgres().getVersion()));
return new ContainerBuilder().withName("relocate-binaries").withImage(patroniImageName).withImagePullPolicy("IfNotPresent").withCommand("/bin/sh", "-ex", ClusterStatefulSetPath.TEMPLATES_PATH.path() + "/" + ClusterStatefulSetPath.LOCAL_BIN_RELOCATE_BINARIES_SH_PATH.filename()).withEnv(postgresExtensionsMounts.getDerivedEnvVars(ContextUtil.toPostgresContext(context))).withVolumeMounts(templateMounts.getVolumeMounts(context)).addToVolumeMounts(new VolumeMountBuilder().withName(context.getDataVolumeName()).withMountPath(ClusterStatefulSetPath.PG_BASE_PATH.path()).build()).build();
}
Aggregations