use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsPersistentVolume in project stackgres by ongres.
the class DistributedLogsStatefulSet method generateResource.
@Override
public Stream<HasMetadata> generateResource(StackGresDistributedLogsContext context) {
final StackGresDistributedLogs cluster = context.getSource();
final ObjectMeta metadata = cluster.getMetadata();
final String name = metadata.getName();
final String namespace = metadata.getNamespace();
final StackGresDistributedLogsPersistentVolume persistentVolume = cluster.getSpec().getPersistentVolume();
StorageConfig dataStorageConfig = ImmutableStorageConfig.builder().size(persistentVolume.getSize()).storageClass(Optional.ofNullable(persistentVolume.getStorageClass()).orElse(null)).build();
final PersistentVolumeClaimSpecBuilder volumeClaimSpec = new PersistentVolumeClaimSpecBuilder().withAccessModes("ReadWriteOnce").withResources(dataStorageConfig.getResourceRequirements()).withStorageClassName(dataStorageConfig.getStorageClass());
final Map<String, String> labels = labelFactory.clusterLabels(cluster);
final Map<String, String> podLabels = labelFactory.statefulSetPodLabels(cluster);
Map<String, VolumePair> availableVolumesPairs = volumeDiscoverer.discoverVolumes(context);
Map<String, Volume> availableVolumes = availableVolumesPairs.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, vp -> vp.getValue().getVolume()));
final PodTemplateResult buildPodTemplate = podTemplateSpecFactory.getPodTemplateSpec(ImmutableDistributedLogsContainerContext.builder().distributedLogsContext(context).availableVolumes(availableVolumes).dataVolumeName(dataName(cluster)).build());
StatefulSet clusterStatefulSet = new StatefulSetBuilder().withNewMetadata().withNamespace(namespace).withName(name).withLabels(labels).endMetadata().withNewSpec().withReplicas(1).withSelector(new LabelSelectorBuilder().addToMatchLabels(podLabels).build()).withUpdateStrategy(new StatefulSetUpdateStrategyBuilder().withType("OnDelete").build()).withServiceName(name).withTemplate(buildPodTemplate.getSpec()).withVolumeClaimTemplates(Stream.of(Stream.of(new PersistentVolumeClaimBuilder().withNewMetadata().withNamespace(namespace).withName(dataName(cluster)).withLabels(labels).endMetadata().withSpec(volumeClaimSpec.build()).build())).flatMap(s -> s).toArray(PersistentVolumeClaim[]::new)).endSpec().build();
var volumeDependencies = buildPodTemplate.claimedVolumes().stream().map(availableVolumesPairs::get).filter(Objects::nonNull).map(VolumePair::getSource).filter(Optional::isPresent).map(Optional::get);
return Stream.concat(Stream.of(clusterStatefulSet), volumeDependencies);
}
use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsPersistentVolume in project stackgres by ongres.
the class DistributedLogsTransformer method getCustomResourcePersistentVolume.
private StackGresDistributedLogsPersistentVolume getCustomResourcePersistentVolume(DistributedLogsPersistentVolume source) {
StackGresDistributedLogsPersistentVolume transformation = new StackGresDistributedLogsPersistentVolume();
transformation.setSize(source.getSize());
transformation.setStorageClass(source.getStorageClass());
return transformation;
}
use of io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsPersistentVolume in project stackgres by ongres.
the class DistributedLogsTransformer method getResourcePersistentVolume.
private DistributedLogsPersistentVolume getResourcePersistentVolume(StackGresDistributedLogsPersistentVolume source) {
DistributedLogsPersistentVolume transformation = new DistributedLogsPersistentVolume();
transformation.setSize(source.getSize());
transformation.setStorageClass(source.getStorageClass());
return transformation;
}
Aggregations