use of io.stackgres.apiweb.dto.Metadata in project stackgres by ongres.
the class ClusterResourceMockedTest method checkCustomResource.
@Override
protected void checkCustomResource(StackGresCluster resource, ClusterDto resourceDto, Operation operation) {
final Metadata dtoMetadata = resourceDto.getMetadata();
final ObjectMeta resourceMetadata = resource.getMetadata();
if (dtoMetadata != null) {
assertNotNull(resourceMetadata);
assertEquals(dtoMetadata.getName(), resourceMetadata.getName());
assertEquals(dtoMetadata.getNamespace(), resourceMetadata.getNamespace());
assertEquals(dtoMetadata.getUid(), resourceMetadata.getUid());
} else {
assertNull(resourceMetadata);
}
final ClusterSpec dtoSpec = resourceDto.getSpec();
final StackGresClusterSpec resourceSpec = resource.getSpec();
if (dtoSpec != null) {
assertNotNull(resourceSpec);
assertEquals(dtoSpec.getPrometheusAutobind(), resourceSpec.getPrometheusAutobind());
assertEquals(dtoSpec.getInstances(), resourceSpec.getInstances());
assertEquals(dtoSpec.getPostgres().getVersion(), resourceSpec.getPostgres().getVersion());
assertEquals(dtoSpec.getSgInstanceProfile(), resourceSpec.getResourceProfile());
final ClusterConfiguration dtoSpecConfigurations = dtoSpec.getConfigurations();
final StackGresClusterConfiguration resourceSpecConfiguration = resourceSpec.getConfiguration();
if (dtoSpecConfigurations != null) {
assertNotNull(resourceSpecConfiguration);
assertEquals(dtoSpecConfigurations.getSgBackupConfig(), resourceSpecConfiguration.getBackupConfig());
assertEquals(dtoSpecConfigurations.getSgPoolingConfig(), resourceSpecConfiguration.getConnectionPoolingConfig());
assertEquals(dtoSpecConfigurations.getSgPostgresConfig(), resourceSpecConfiguration.getPostgresConfig());
} else {
assertNull(resourceSpecConfiguration);
}
final ClusterPod dtoSpecPods = dtoSpec.getPods();
if (dtoSpecPods != null) {
final StackGresClusterPod resourceSpecPod = resourceSpec.getPod();
assertNotNull(resourceSpecPod);
assertEquals(dtoSpecPods.getDisableConnectionPooling(), resourceSpecPod.getDisableConnectionPooling());
assertEquals(dtoSpecPods.getDisableMetricsExporter(), resourceSpecPod.getDisableMetricsExporter());
assertEquals(dtoSpecPods.getDisableMetricsExporter(), resourceSpecPod.getDisableMetricsExporter());
final ClusterPodPersistentVolume dtoPV = dtoSpecPods.getPersistentVolume();
final StackGresPodPersistentVolume resourcePV = resourceSpecPod.getPersistentVolume();
if (dtoPV != null) {
assertNotNull(resourcePV);
assertEquals(dtoPV.getSize(), resourcePV.getSize());
assertEquals(dtoPV.getStorageClass(), resourcePV.getStorageClass());
} else {
assertNull(resourcePV);
}
final StackGresClusterSpecLabels resourceMetadataLabels = Optional.ofNullable(resourceSpec.getMetadata()).map(StackGresClusterSpecMetadata::getLabels).orElse(null);
final ClusterSpecLabels dtoMetadataLabels = Optional.ofNullable(dtoSpec.getMetadata()).map(ClusterSpecMetadata::getLabels).orElse(null);
if (dtoMetadataLabels != null) {
assertNotNull(resourceMetadataLabels);
assertEquals(dtoMetadataLabels.getClusterPods(), resourceMetadataLabels.getClusterPods());
} else {
assertNull(resourceMetadataLabels);
}
final ClusterPodScheduling podScheduling = dtoSpecPods.getScheduling();
final StackGresClusterPodScheduling resourceScheduling = resourceSpecPod.getScheduling();
if (podScheduling != null) {
assertNotNull(resourceScheduling);
assertEquals(podScheduling.getNodeSelector(), resourceScheduling.getNodeSelector());
assertEquals(podScheduling.getNodeAffinity(), resourceScheduling.getNodeAffinity());
} else {
assertNull(resourceScheduling);
}
}
final ClusterInitData dtoInitData = dtoSpec.getInitData();
final StackGresClusterInitData resourceInitData = resourceSpec.getInitData();
if (dtoInitData != null) {
assertNotNull(resourceInitData);
final ClusterRestore dtoRestore = dtoInitData.getRestore();
final StackGresClusterRestore resourceRestore = resourceInitData.getRestore();
if (dtoRestore != null) {
assertNotNull(resourceRestore);
assertEquals(dtoRestore.getFromBackup().getUid(), resourceRestore.getFromBackup().getUid());
} else {
assertNull(resourceRestore);
}
if (dtoInitData.getScripts() != null) {
assertNotNull(resourceInitData.getScripts());
assertEquals(dtoInitData.getScripts().size(), resourceInitData.getScripts().size());
Seq.zip(dtoInitData.getScripts(), resourceInitData.getScripts()).forEach(entryTuple -> {
ClusterScriptEntry dtoEntry = entryTuple.v1;
StackGresClusterScriptEntry resourceEntry = entryTuple.v2;
assertEquals(dtoEntry.getDatabase(), resourceEntry.getDatabase());
assertEquals(dtoEntry.getName(), resourceEntry.getName());
assertEquals(dtoEntry.getScript(), resourceEntry.getScript());
final ClusterScriptFrom dtoScriptFrom = dtoEntry.getScriptFrom();
final StackGresClusterScriptFrom resourceScriptFrom = resourceEntry.getScriptFrom();
if (dtoScriptFrom != null) {
assertNotNull(resourceScriptFrom);
final SecretKeySelector dtoSecretKeyRef = dtoScriptFrom.getSecretKeyRef();
final SecretKeySelector resourceSecretKeyRef = resourceScriptFrom.getSecretKeyRef();
if (dtoSecretKeyRef != null) {
assertNotNull(resourceSecretKeyRef);
assertEquals(dtoSecretKeyRef.getName(), resourceSecretKeyRef.getName());
assertEquals(dtoSecretKeyRef.getKey(), resourceSecretKeyRef.getKey());
} else {
assertNull(resourceSecretKeyRef);
}
final ConfigMapKeySelector resourceConfigMapKeyRef = resourceScriptFrom.getConfigMapKeyRef();
final ConfigMapKeySelector dtoConfigMapKeyRef = dtoScriptFrom.getConfigMapKeyRef();
if (dtoConfigMapKeyRef != null) {
assertNotNull(resourceConfigMapKeyRef);
assertEquals(dtoConfigMapKeyRef.getName(), resourceConfigMapKeyRef.getName());
assertEquals(dtoConfigMapKeyRef.getKey(), resourceConfigMapKeyRef.getKey());
} else {
assertNull(resourceConfigMapKeyRef);
}
} else {
assertNull(resourceScriptFrom);
}
});
}
} else {
assertNull(resourceInitData);
}
if (dtoSpec.getDistributedLogs() != null) {
assertNotNull(resourceSpec.getDistributedLogs());
assertEquals(dtoSpec.getDistributedLogs().getDistributedLogs(), resourceSpec.getDistributedLogs().getDistributedLogs());
} else {
assertNull(resourceSpec.getDistributedLogs());
}
} else {
assertNull(resourceSpec);
}
}
use of io.stackgres.apiweb.dto.Metadata in project stackgres by ongres.
the class ClusterResourceQuarkusTest method givenACreationWithConfigMapsScripts_shouldNotFail.
@Test
void givenACreationWithConfigMapsScripts_shouldNotFail() {
ClusterDto cluster = getClusterInlineScripts();
ClusterScriptEntry entry = getConfigMapScriptEntry();
cluster.getSpec().getInitData().setScripts(Collections.singletonList(entry));
final Metadata metadata = cluster.getMetadata();
metadata.setNamespace("test");
given().header(AUTHENTICATION_HEADER).body(cluster).contentType(ContentType.JSON).accept(ContentType.JSON).post("/stackgres/sgclusters").then().statusCode(204);
try (KubernetesClient client = factory.create()) {
ConfigMap configMap = client.configMaps().inNamespace("test").withName(entry.getScriptFrom().getConfigMapKeyRef().getName()).get();
assertNotNull(configMap);
String actualConfigScript = configMap.getData().get(entry.getScriptFrom().getConfigMapKeyRef().getKey());
assertEquals(entry.getScriptFrom().getConfigMapScript(), actualConfigScript);
}
}
use of io.stackgres.apiweb.dto.Metadata in project stackgres by ongres.
the class ClusterResourceQuarkusTest method givenACreationWithSecretScripts_shouldNotFail.
@Test
void givenACreationWithSecretScripts_shouldNotFail() {
ClusterDto cluster = getClusterInlineScripts();
ClusterScriptEntry entry = getSecretScriptEntry();
cluster.getSpec().getInitData().setScripts(Collections.singletonList(entry));
final Metadata metadata = cluster.getMetadata();
metadata.setNamespace("test");
given().header(AUTHENTICATION_HEADER).body(cluster).contentType(ContentType.JSON).accept(ContentType.JSON).post("/stackgres/sgclusters").then().statusCode(204);
try (KubernetesClient client = factory.create()) {
final ClusterScriptFrom scriptFrom = entry.getScriptFrom();
final SecretKeySelector secretKeyRef = scriptFrom.getSecretKeyRef();
Secret secret = client.secrets().inNamespace("test").withName(secretKeyRef.getName()).get();
assertNotNull(secret);
byte[] actualScript = Base64.getDecoder().decode(secret.getData().get(secretKeyRef.getKey()));
assertEquals(scriptFrom.getSecretScript(), new String(actualScript, StandardCharsets.UTF_8));
}
}
Aggregations