use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs in project stackgres by ongres.
the class StackGresDistributedLogsUtil method getStackGresClusterForDistributedLogs.
static StackGresCluster getStackGresClusterForDistributedLogs(StackGresDistributedLogs distributedLogs) {
final StackGresCluster distributedLogsCluster = new StackGresCluster();
distributedLogsCluster.getMetadata().setNamespace(distributedLogs.getMetadata().getNamespace());
distributedLogsCluster.getMetadata().setName(distributedLogs.getMetadata().getName());
distributedLogsCluster.getMetadata().setUid(distributedLogs.getMetadata().getUid());
final StackGresClusterSpec spec = new StackGresClusterSpec();
spec.setPostgres(new StackGresClusterPostgres());
spec.getPostgres().setVersion(getPostgresVersion());
spec.setInstances(1);
final StackGresClusterPod pod = new StackGresClusterPod();
final StackGresPodPersistentVolume persistentVolume = new StackGresPodPersistentVolume();
persistentVolume.setSize(distributedLogs.getSpec().getPersistentVolume().getSize());
persistentVolume.setStorageClass(distributedLogs.getSpec().getPersistentVolume().getStorageClass());
pod.setPersistentVolume(persistentVolume);
spec.setPostgresServices(buildPostgresServices(distributedLogs.getSpec()));
StackGresClusterPodScheduling scheduling = new StackGresClusterPodScheduling();
Optional.of(distributedLogs).map(StackGresDistributedLogs::getSpec).map(StackGresDistributedLogsSpec::getScheduling).ifPresent(distributedLogsScheduling -> {
scheduling.setNodeSelector(distributedLogsScheduling.getNodeSelector());
scheduling.setTolerations(distributedLogsScheduling.getTolerations());
});
pod.setScheduling(scheduling);
spec.setPod(pod);
final StackGresClusterInitData initData = new StackGresClusterInitData();
final StackGresClusterScriptEntry script = new StackGresClusterScriptEntry();
script.setName("distributed-logs-template");
script.setDatabase("template1");
script.setScript(Unchecked.supplier(() -> Resources.asCharSource(StackGresDistributedLogsUtil.class.getResource("/distributed-logs-template.sql"), StandardCharsets.UTF_8).read()).get());
initData.setScripts(ImmutableList.of(script));
spec.setInitData(initData);
final StackGresClusterNonProduction nonProduction = new StackGresClusterNonProduction();
nonProduction.setDisableClusterPodAntiAffinity(Optional.ofNullable(distributedLogs.getSpec().getNonProduction()).map(StackGresDistributedLogsNonProduction::getDisableClusterPodAntiAffinity).orElse(false));
spec.setNonProduction(nonProduction);
final StackGresClusterSpecMetadata metadata = new StackGresClusterSpecMetadata();
final StackGresClusterSpecAnnotations annotations = new StackGresClusterSpecAnnotations();
Optional.of(distributedLogs).map(StackGresDistributedLogs::getSpec).map(StackGresDistributedLogsSpec::getMetadata).map(StackGresDistributedLogsSpecMetadata::getAnnotations).ifPresent(distributedLogsAnnotations -> {
annotations.setAllResources(distributedLogsAnnotations.getAllResources());
annotations.setClusterPods(distributedLogsAnnotations.getPods());
annotations.setPrimaryService(distributedLogsAnnotations.getServices());
annotations.setReplicasService(distributedLogsAnnotations.getServices());
});
metadata.setAnnotations(annotations);
spec.setMetadata(metadata);
spec.setToInstallPostgresExtensions(Optional.ofNullable(distributedLogs.getSpec()).map(StackGresDistributedLogsSpec::getToInstallPostgresExtensions).orElse(null));
distributedLogsCluster.setSpec(spec);
return distributedLogsCluster;
}
use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs in project stackgres by ongres.
the class DistributedLogsResourceScanner method getDeployedResources.
@Override
public List<HasMetadata> getDeployedResources(StackGresDistributedLogs config) {
try (KubernetesClient client = clientFactory.create()) {
final String namespace = config.getMetadata().getNamespace();
List<HasMetadata> resources = IN_NAMESPACE_RESOURCE_OPERATIONS.values().stream().flatMap(resourceOperationGetter -> resourceOperationGetter.apply(client).inNamespace(namespace).withLabels(labelFactory.genericLabels(config)).list().getItems().stream()).filter(resource -> resource.getMetadata().getOwnerReferences().stream().anyMatch(ownerReference -> ownerReference.getKind().equals(StackGresDistributedLogs.KIND) && ownerReference.getName().equals(config.getMetadata().getName()))).collect(Collectors.toUnmodifiableList());
return resources;
}
}
use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs in project stackgres by ongres.
the class ContextUtil method toPostgresContext.
public static PostgresContainerContext toPostgresContext(DistributedLogsContainerContext context) {
StackGresDistributedLogs distributedLogs = context.getDistributedLogsContext().getSource();
List<StackGresClusterInstalledExtension> installedExtensions = Optional.ofNullable(distributedLogs.getSpec()).map(StackGresDistributedLogsSpec::getToInstallPostgresExtensions).stream().flatMap(Collection::stream).collect(Collectors.toUnmodifiableList());
return ImmutablePostgresContainerContext.builder().from(context).postgresMajorVersion(StackGresDistributedLogsUtil.getPostgresMajorVersion()).postgresVersion(StackGresDistributedLogsUtil.getPostgresVersion()).imageBuildMajorVersion(StackGresDistributedLogsUtil.getPostgresBuildMajorVersion()).addAllInstalledExtensions(installedExtensions).build();
}
Aggregations