use of io.stackgres.common.crd.sgcluster.StackGresClusterPostgres in project stackgres by ongres.
the class ExtensionsResourceTest method getIndexAnyVersion.
private StackGresExtensionIndexAnyVersion getIndexAnyVersion(String postgresVersion, StackGresClusterExtension clusterExtension) {
StackGresCluster cluster = new StackGresCluster();
cluster.setSpec(new StackGresClusterSpec());
cluster.getSpec().setPostgres(new StackGresClusterPostgres());
cluster.getSpec().getPostgres().setVersion(postgresVersion);
return new StackGresExtensionIndexAnyVersion(cluster, clusterExtension);
}
use of io.stackgres.common.crd.sgcluster.StackGresClusterPostgres in project stackgres by ongres.
the class SslValidatorTest method prepareForSsl.
private void prepareForSsl(StackGresClusterReview review) {
review.getRequest().getObject().getSpec().setPostgres(new StackGresClusterPostgres());
review.getRequest().getObject().getSpec().getPostgres().setSsl(new StackGresClusterSsl());
review.getRequest().getObject().getSpec().getPostgres().getSsl().setEnabled(true);
review.getRequest().getObject().getSpec().getPostgres().getSsl().setCertificateSecretKeySelector(new SecretKeySelector());
review.getRequest().getObject().getSpec().getPostgres().getSsl().getCertificateSecretKeySelector().setName("secret1");
review.getRequest().getObject().getSpec().getPostgres().getSsl().getCertificateSecretKeySelector().setKey("test");
review.getRequest().getObject().getSpec().getPostgres().getSsl().setPrivateKeySecretKeySelector(new SecretKeySelector());
review.getRequest().getObject().getSpec().getPostgres().getSsl().getPrivateKeySecretKeySelector().setName("secret2");
review.getRequest().getObject().getSpec().getPostgres().getSsl().getPrivateKeySecretKeySelector().setKey("test");
}
use of io.stackgres.common.crd.sgcluster.StackGresClusterPostgres in project stackgres by ongres.
the class ExtensionUtilTest method testExtensionsMetadataMapSameMajorBuild.
@Test
public void testExtensionsMetadataMapSameMajorBuild() {
StackGresCluster cluster = new StackGresCluster();
cluster.setSpec(new StackGresClusterSpec());
cluster.getSpec().setPostgres(new StackGresClusterPostgres());
var extensionMetadataMap = ExtensionUtil.toExtensionsMetadataIndexSameMajorBuilds(repository, extensionsMetadata);
cluster.getSpec().getPostgres().setVersion(firstPgMajorVersion);
Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(0))));
Assertions.assertEquals(1, extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(0))).size());
Assertions.assertNotEquals(repository, extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(0))).get(0).getExtension().getRepository());
Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(1))));
Assertions.assertEquals(1, extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(1))).size());
Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(1))).get(0).getExtension().getRepository());
Assertions.assertNull(extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(2))));
Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(3))));
Assertions.assertEquals(1, extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(3))).size());
Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(3))).get(0).getExtension().getRepository());
cluster.getSpec().getPostgres().setVersion(secondPgMajorVersion);
Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(0))));
Assertions.assertEquals(1, extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(0))).size());
Assertions.assertNotEquals(repository, extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(0))).get(0).getExtension().getRepository());
Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(1))));
Assertions.assertEquals(1, extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(1))).size());
Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(1))).get(0).getExtension().getRepository());
Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(2))));
Assertions.assertEquals(1, extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(2))).size());
Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(2))).get(0).getExtension().getRepository());
Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(3))));
Assertions.assertEquals(1, extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(3))).size());
Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndexSameMajorBuild(cluster, extensions.get(3))).get(0).getExtension().getRepository());
}
use of io.stackgres.common.crd.sgcluster.StackGresClusterPostgres in project stackgres by ongres.
the class ExtensionUtilTest method testExtensionsMetadataMapAnyVersion.
@Test
public void testExtensionsMetadataMapAnyVersion() {
StackGresCluster cluster = new StackGresCluster();
cluster.setSpec(new StackGresClusterSpec());
cluster.getSpec().setPostgres(new StackGresClusterPostgres());
cluster.getSpec().setPostgres(new StackGresClusterPostgres());
Map<StackGresExtensionIndexAnyVersion, List<StackGresExtensionMetadata>> extensionMetadataMap = ExtensionUtil.toExtensionsMetadataIndexAnyVersions(repository, extensionsMetadata);
cluster.getSpec().getPostgres().setVersion(firstPgMajorVersion);
Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(0))));
Assertions.assertEquals(1, extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(0))).size());
Assertions.assertNotEquals(repository, extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(0))).get(0).getExtension().getRepository());
Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(1))));
Assertions.assertEquals(1, extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(1))).size());
Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(1))).get(0).getExtension().getRepository());
Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(2))));
Assertions.assertEquals(1, extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(2))).size());
Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(2))).get(0).getExtension().getRepository());
Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(3))));
Assertions.assertEquals(1, extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(3))).size());
Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(3))).get(0).getExtension().getRepository());
cluster.getSpec().getPostgres().setVersion(secondPgMajorVersion);
Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(0))));
Assertions.assertEquals(1, extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(0))).size());
Assertions.assertNotEquals(repository, extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(0))).get(0).getExtension().getRepository());
Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(1))));
Assertions.assertEquals(2, extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(1))).size());
Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(1))).get(0).getExtension().getRepository());
Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(1))).get(1).getExtension().getRepository());
Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(2))));
Assertions.assertEquals(2, extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(2))).size());
Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(2))).get(0).getExtension().getRepository());
Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(2))).get(1).getExtension().getRepository());
Assertions.assertNotNull(extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(3))));
Assertions.assertEquals(1, extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(3))).size());
Assertions.assertEquals(repository.toASCIIString(), extensionMetadataMap.get(new StackGresExtensionIndexAnyVersion(cluster, extensions.get(3))).get(0).getExtension().getRepository());
}
use of io.stackgres.common.crd.sgcluster.StackGresClusterPostgres in project stackgres by ongres.
the class ExtensionsChannelMutator method mutate.
@Override
public List<JsonPatchOperation> mutate(StackGresClusterReview review) {
if (review.getRequest().getOperation() == Operation.CREATE || review.getRequest().getOperation() == Operation.UPDATE) {
ImmutableList.Builder<JsonPatchOperation> operations = ImmutableList.builder();
Optional.of(review).map(StackGresClusterReview::getRequest).map(AdmissionRequest<StackGresCluster>::getObject).ifPresent(cluster -> {
Optional.of(cluster).map(StackGresCluster::getSpec).map(StackGresClusterSpec::getPostgres).map(StackGresClusterPostgres::getExtensions).stream().flatMap(extensions -> Seq.seq(extensions).zipWithIndex()).forEach(Unchecked.consumer(extension -> {
final JsonPointer extensionVersionPointer = CLUSTER_CONFIG_POINTER.append("postgres").append("extensions").append(extension.v2.intValue()).append("version");
final StackGresExtensionMetadata extensionMetadata;
try {
extensionMetadata = extensionMetadataManager.getExtensionCandidateSameMajorBuild(cluster, extension.v1);
} catch (Exception ex) {
LOGGER.warn("Unable to retrieve candidate with same major build for extension", ex);
return;
}
final StackGresClusterInstalledExtension installedExtension = ExtensionUtil.getInstalledExtension(extension.v1, extensionMetadata);
final TextNode extensionVersion = new TextNode(installedExtension.getVersion());
if (extension.v1.getVersion() == null) {
operations.add(new AddOperation(extensionVersionPointer, extensionVersion));
} else if (!installedExtension.getVersion().equals(extension.v1.getVersion())) {
operations.add(new ReplaceOperation(extensionVersionPointer, extensionVersion));
}
}));
});
return operations.build();
}
return ImmutableList.of();
}
Aggregations