use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsSpec in project stackgres by ongres.
the class DistributedLogsTransformer method getCustomResourceSpec.
private StackGresDistributedLogsSpec getCustomResourceSpec(DistributedLogsSpec source) {
StackGresDistributedLogsSpec transformation = new StackGresDistributedLogsSpec();
transformation.setPersistentVolume(getCustomResourcePersistentVolume(source.getPersistentVolume()));
transformation.setPostgresServices(new DistributedLogsPostgresServicesConverter().to(source.getPostgresServices()));
transformation.setNonProduction(getCustomResourceNonProduction(source.getNonProduction()));
transformation.setScheduling(Optional.ofNullable(source.getScheduling()).map(sourceScheduling -> {
StackGresDistributedLogsPodScheduling targetScheduling = new StackGresDistributedLogsPodScheduling();
targetScheduling.setNodeSelector(sourceScheduling.getNodeSelector());
targetScheduling.setTolerations(sourceScheduling.getTolerations());
return targetScheduling;
}).orElse(null));
Optional.ofNullable(source.getMetadata()).map(DistributedLogsSpecMetadata::getAnnotations).ifPresent(sourceAnnotations -> {
transformation.setMetadata(new StackGresDistributedLogsSpecMetadata());
final StackGresDistributedLogsSpecAnnotations targetAnnotations = new StackGresDistributedLogsSpecAnnotations();
transformation.getMetadata().setAnnotations(targetAnnotations);
if (sourceAnnotations.getAllResources() != null) {
targetAnnotations.setAllResources(sourceAnnotations.getAllResources());
}
if (sourceAnnotations.getPods() != null) {
targetAnnotations.setPods(sourceAnnotations.getPods());
}
if (sourceAnnotations.getServices() != null) {
targetAnnotations.setServices(sourceAnnotations.getServices());
}
});
return transformation;
}
use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsSpec 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;
}
Aggregations