Search in sources :

Example 6 with StackGresDistributedLogsSpec

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;
}
Also used : DistributedLogsPostgresServicesConverter(io.stackgres.apiweb.transformer.distributedlogs.DistributedLogsPostgresServicesConverter) StackGresDistributedLogsSpec(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsSpec) StackGresDistributedLogsPodScheduling(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsPodScheduling) StackGresDistributedLogsSpecAnnotations(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsSpecAnnotations) StackGresDistributedLogsSpecMetadata(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsSpecMetadata)

Example 7 with StackGresDistributedLogsSpec

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;
}
Also used : StackGresClusterPodScheduling(io.stackgres.common.crd.sgcluster.StackGresClusterPodScheduling) StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) StackGresDistributedLogsSpec(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsSpec) StackGresDistributedLogs(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs) StackGresClusterScriptEntry(io.stackgres.common.crd.sgcluster.StackGresClusterScriptEntry) StackGresClusterPod(io.stackgres.common.crd.sgcluster.StackGresClusterPod) StackGresClusterPostgres(io.stackgres.common.crd.sgcluster.StackGresClusterPostgres) StackGresDistributedLogsNonProduction(io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsNonProduction) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StackGresClusterNonProduction(io.stackgres.common.crd.sgcluster.StackGresClusterNonProduction) StackGresClusterSpecAnnotations(io.stackgres.common.crd.sgcluster.StackGresClusterSpecAnnotations) StackGresPodPersistentVolume(io.stackgres.common.crd.sgcluster.StackGresPodPersistentVolume) StackGresClusterInitData(io.stackgres.common.crd.sgcluster.StackGresClusterInitData) StackGresClusterSpecMetadata(io.stackgres.common.crd.sgcluster.StackGresClusterSpecMetadata)

Aggregations

StackGresDistributedLogsSpec (io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsSpec)7 StackGresDistributedLogs (io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogs)3 StackGresDistributedLogsPodScheduling (io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsPodScheduling)3 ImmutableList (com.google.common.collect.ImmutableList)2 DistributedLogsPostgresServicesConverter (io.stackgres.apiweb.transformer.distributedlogs.DistributedLogsPostgresServicesConverter)2 StackGresClusterPostgresServices (io.stackgres.common.crd.sgcluster.StackGresClusterPostgresServices)2 StackGresDistributedLogsNonProduction (io.stackgres.common.crd.sgdistributedlogs.StackGresDistributedLogsNonProduction)2 StackGresDistributedLogsSpecFixture (io.stackgres.common.fixture.StackGresDistributedLogsSpecFixture)2 List (java.util.List)2 Optional (java.util.Optional)2 Test (org.junit.jupiter.api.Test)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 JsonMapper (com.fasterxml.jackson.databind.json.JsonMapper)1 JsonPointer (com.github.fge.jackson.jsonpointer.JsonPointer)1 JsonPatchOperation (com.github.fge.jsonpatch.JsonPatchOperation)1 AffinityBuilder (io.fabric8.kubernetes.api.model.AffinityBuilder)1 Container (io.fabric8.kubernetes.api.model.Container)1 LabelSelectorBuilder (io.fabric8.kubernetes.api.model.LabelSelectorBuilder)1 LabelSelectorRequirementBuilder (io.fabric8.kubernetes.api.model.LabelSelectorRequirementBuilder)1 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)1