Search in sources :

Example 1 with StackGresClusterPod

use of io.stackgres.common.crd.sgcluster.StackGresClusterPod in project stackgres by ongres.

the class AbstractEnvoy method buildSource.

@NotNull
public HasMetadata buildSource(StackGresClusterContext context) {
    final StackGresCluster stackGresCluster = context.getSource();
    boolean disablePgBouncer = Optional.ofNullable(stackGresCluster.getSpec()).map(StackGresClusterSpec::getPod).map(StackGresClusterPod::getDisableConnectionPooling).orElse(false);
    final String envoyConfPath = getEnvoyConfigPath(stackGresCluster, disablePgBouncer);
    YAMLMapper yamlMapper = yamlMapperProvider.yamlMapper();
    final ObjectNode envoyConfig;
    try {
        envoyConfig = (ObjectNode) yamlMapper.readTree(Envoy.class.getResource(envoyConfPath));
    } catch (Exception ex) {
        throw new IllegalStateException("couldn't read envoy config file", ex);
    }
    Seq.seq(envoyConfig.get("static_resources").get("listeners")).map(listener -> listener.get("address").get("socket_address")).cast(ObjectNode.class).forEach(socketAddress -> socketAddress.put("port_value", LISTEN_SOCKET_ADDRESS_PORT_MAPPING.get(socketAddress.get("port_value").asText())));
    Seq.seq(envoyConfig.get("static_resources").get("clusters")).flatMap(cluster -> Seq.seq(cluster.get("load_assignment").get("endpoints").elements())).flatMap(endpoint -> Seq.seq(endpoint.get("lb_endpoints").elements())).map(endpoint -> endpoint.get("endpoint").get("address").get("socket_address")).cast(ObjectNode.class).forEach(socketAddress -> socketAddress.put("port_value", CLUSTER_SOCKET_ADDRESS_PORT_MAPPING.get(socketAddress.get("port_value").asText())));
    final Map<String, String> data;
    try {
        data = ImmutableMap.of("default_envoy.yaml", yamlMapper.writeValueAsString(envoyConfig));
    } catch (Exception ex) {
        throw new IllegalStateException("couldn't parse envoy config file", ex);
    }
    String namespace = stackGresCluster.getMetadata().getNamespace();
    String configMapName = AbstractEnvoy.configName(context);
    return new ConfigMapBuilder().withNewMetadata().withNamespace(namespace).withName(configMapName).withLabels(labelFactory.clusterLabels(stackGresCluster)).endMetadata().withData(data).build();
}
Also used : VolumeMount(io.fabric8.kubernetes.api.model.VolumeMount) StackGresContext(io.stackgres.common.StackGresContext) VolumeFactory(io.stackgres.operator.conciliation.factory.VolumeFactory) ConfigMapVolumeSourceBuilder(io.fabric8.kubernetes.api.model.ConfigMapVolumeSourceBuilder) Container(io.fabric8.kubernetes.api.model.Container) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) LoggerFactory(org.slf4j.LoggerFactory) Seq(org.jooq.lambda.Seq) StackgresClusterContainers(io.stackgres.common.StackgresClusterContainers) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Inject(javax.inject.Inject) StatefulSetDynamicVolumes(io.stackgres.operator.conciliation.factory.cluster.StatefulSetDynamicVolumes) EnvoyUtil(io.stackgres.common.EnvoyUtil) ImmutableVolumePair(io.stackgres.operator.conciliation.factory.ImmutableVolumePair) VolumeMountBuilder(io.fabric8.kubernetes.api.model.VolumeMountBuilder) StackGresClusterPod(io.stackgres.common.crd.sgcluster.StackGresClusterPod) VolumePair(io.stackgres.operator.conciliation.factory.VolumePair) YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) ContainerFactory(io.stackgres.operator.conciliation.factory.ContainerFactory) Volume(io.fabric8.kubernetes.api.model.Volume) StackGresClusterContainerContext(io.stackgres.operator.conciliation.factory.cluster.StackGresClusterContainerContext) Logger(org.slf4j.Logger) ImmutableMap(com.google.common.collect.ImmutableMap) StackGresClusterContext(io.stackgres.operator.conciliation.cluster.StackGresClusterContext) LabelFactoryForCluster(io.stackgres.common.LabelFactoryForCluster) VolumeBuilder(io.fabric8.kubernetes.api.model.VolumeBuilder) YamlMapperProvider(io.stackgres.common.YamlMapperProvider) ResourceUtil(io.stackgres.operatorframework.resource.ResourceUtil) HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) StackGresComponent(io.stackgres.common.StackGresComponent) StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) List(java.util.List) Stream(java.util.stream.Stream) Optional(java.util.Optional) NotNull(org.jetbrains.annotations.NotNull) ContainerPortBuilder(io.fabric8.kubernetes.api.model.ContainerPortBuilder) StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) YAMLMapper(com.fasterxml.jackson.dataformat.yaml.YAMLMapper) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with StackGresClusterPod

use of io.stackgres.common.crd.sgcluster.StackGresClusterPod in project stackgres by ongres.

the class ClusterResourceMockedTest method checkDto.

@Override
protected void checkDto(ClusterDto dto, StackGresCluster resource) {
    if (resource.getMetadata() != null) {
        assertNotNull(dto.getMetadata());
        assertEquals(resource.getMetadata().getNamespace(), dto.getMetadata().getNamespace());
        assertEquals(resource.getMetadata().getName(), dto.getMetadata().getName());
        assertEquals(resource.getMetadata().getUid(), dto.getMetadata().getUid());
    } else {
        assertNull(dto.getMetadata());
    }
    final StackGresClusterSpec resourceSpec = resource.getSpec();
    final ClusterSpec dtoSpec = dto.getSpec();
    if (resourceSpec != null) {
        assertNotNull(dtoSpec);
        assertEquals(resourceSpec.getInstances(), dtoSpec.getInstances());
        assertEquals(resourceSpec.getPostgres().getVersion(), dtoSpec.getPostgres().getVersion());
        assertEquals(resourceSpec.getPrometheusAutobind(), dtoSpec.getPrometheusAutobind());
        assertEquals(resourceSpec.getResourceProfile(), dtoSpec.getSgInstanceProfile());
        final ClusterConfiguration dtoClusterConfigurations = dtoSpec.getConfigurations();
        final StackGresClusterConfiguration resourceClusterConfiguration = resourceSpec.getConfiguration();
        if (resourceClusterConfiguration != null) {
            assertNotNull(dtoClusterConfigurations);
            assertEquals(resourceClusterConfiguration.getBackupConfig(), dtoClusterConfigurations.getSgBackupConfig());
            assertEquals(resourceClusterConfiguration.getConnectionPoolingConfig(), dtoClusterConfigurations.getSgPoolingConfig());
            assertEquals(resourceClusterConfiguration.getPostgresConfig(), dtoClusterConfigurations.getSgPostgresConfig());
        } else {
            assertNull(dtoClusterConfigurations);
        }
        final ClusterPod dtoSpecPods = dtoSpec.getPods();
        final StackGresClusterPod resourcePod = resourceSpec.getPod();
        if (resourcePod != null) {
            assertNotNull(dtoSpecPods);
            assertEquals(resourcePod.getDisableConnectionPooling(), dtoSpecPods.getDisableConnectionPooling());
            assertEquals(resourcePod.getDisableMetricsExporter(), dtoSpecPods.getDisableMetricsExporter());
            assertEquals(resourcePod.getDisablePostgresUtil(), dtoSpecPods.getDisablePostgresUtil());
            final ClusterPodPersistentVolume resourcePV = dtoSpecPods.getPersistentVolume();
            final StackGresPodPersistentVolume dtoPV = resourcePod.getPersistentVolume();
            if (dtoPV != null) {
                assertNotNull(resourcePV);
                assertEquals(dtoPV.getSize(), resourcePV.getSize());
                assertEquals(dtoPV.getStorageClass(), resourcePV.getStorageClass());
            } else {
                assertNull(resourcePV);
            }
            if (resourceSpec.getMetadata() != null) {
                assertNotNull(dtoSpec.getMetadata());
                assertEquals(resourceSpec.getMetadata().getLabels().getClusterPods(), dtoSpec.getMetadata().getLabels().getClusterPods());
            } else {
                assertNull(dtoSpec.getMetadata());
            }
            if (resourcePod.getScheduling() != null) {
                assertNotNull(dtoSpecPods.getScheduling());
                assertEquals(resourcePod.getScheduling().getNodeSelector(), dtoSpecPods.getScheduling().getNodeSelector());
                assertEquals(resourcePod.getScheduling().getNodeAffinity(), dtoSpecPods.getScheduling().getNodeAffinity());
            } else {
                assertNull(dtoSpecPods.getScheduling());
            }
        } else {
            assertNull(dtoSpecPods);
        }
        if (resourceSpec.getDistributedLogs() != null) {
            assertNotNull(dtoSpec.getDistributedLogs());
            assertEquals(resourceSpec.getDistributedLogs().getDistributedLogs(), dtoSpec.getDistributedLogs().getDistributedLogs());
        } else {
            assertNull(dtoSpec.getDistributedLogs());
        }
        final StackGresClusterInitData resourceInitData = resourceSpec.getInitData();
        if (resourceInitData != null) {
            final ClusterInitData dtoInitData = dtoSpec.getInitData();
            assertNotNull(dtoInitData);
            if (resourceInitData.getRestore() != null) {
                assertNotNull(dtoInitData.getRestore());
                assertEquals(resourceInitData.getRestore().getFromBackup().getUid(), dtoInitData.getRestore().getFromBackup().getUid());
                assertEquals(resourceInitData.getRestore().getDownloadDiskConcurrency(), dtoInitData.getRestore().getDownloadDiskConcurrency());
            } else {
                assertNull(dtoInitData.getRestore());
            }
            if (resourceInitData.getScripts() != null) {
                assertNotNull(dtoInitData.getScripts());
                Seq.zip(resourceInitData.getScripts(), dtoInitData.getScripts()).forEach(tuple -> {
                    assertEquals(tuple.v1.getDatabase(), tuple.v2.getDatabase());
                    assertEquals(tuple.v2.getName(), tuple.v2.getName());
                    assertEquals(tuple.v2.getScript(), tuple.v2.getScript());
                    final StackGresClusterScriptFrom resourceScriptFrom = tuple.v1.getScriptFrom();
                    final ClusterScriptFrom dtoScriptFrom = tuple.v2.getScriptFrom();
                    if (resourceScriptFrom != null) {
                        assertNotNull(dtoScriptFrom);
                        if (resourceScriptFrom.getSecretKeyRef() != null) {
                            assertNotNull(dtoScriptFrom.getSecretKeyRef());
                            assertEquals(resourceScriptFrom.getSecretKeyRef().getKey(), dtoScriptFrom.getSecretKeyRef().getKey());
                            assertEquals(resourceScriptFrom.getSecretKeyRef().getName(), dtoScriptFrom.getSecretKeyRef().getName());
                        } else {
                            assertNull(dtoScriptFrom.getSecretKeyRef());
                        }
                        if (resourceScriptFrom.getConfigMapKeyRef() != null) {
                            assertNotNull(dtoScriptFrom.getConfigMapKeyRef());
                            assertEquals(resourceScriptFrom.getConfigMapKeyRef().getKey(), dtoScriptFrom.getConfigMapKeyRef().getKey());
                            assertEquals(resourceScriptFrom.getConfigMapKeyRef().getName(), dtoScriptFrom.getConfigMapKeyRef().getName());
                            assertEquals(configMap.getData().get(resourceScriptFrom.getConfigMapKeyRef().getKey()), dtoScriptFrom.getConfigMapScript());
                        } else {
                            assertNull(dtoScriptFrom.getConfigMapKeyRef());
                        }
                    } else {
                        assertNull(dtoScriptFrom);
                    }
                });
            }
        }
    } else {
        assertNull(dtoSpec);
    }
    if (dto.getPods() != null) {
        assertEquals(1, dto.getPodsReady());
        assertEquals(2, dto.getPods().size());
        assertEquals(4, dto.getPods().get(0).getContainers());
        assertEquals(4, dto.getPods().get(0).getContainersReady());
        assertEquals("10.244.3.23", dto.getPods().get(0).getIp());
        assertEquals("stackgres-0", dto.getPods().get(0).getName());
        assertEquals("stackgres", dto.getPods().get(0).getNamespace());
        assertEquals("primary", dto.getPods().get(0).getRole());
        assertEquals("Active", dto.getPods().get(0).getStatus());
        assertEquals(4, dto.getPods().get(0).getComponentVersions().size());
        assertEquals("12.2", dto.getPods().get(0).getComponentVersions().get("postgresql"));
        assertEquals("1.6.4", dto.getPods().get(0).getComponentVersions().get("patroni"));
        assertEquals("1.13.1", dto.getPods().get(0).getComponentVersions().get("envoy"));
        assertEquals("0.8", dto.getPods().get(0).getComponentVersions().get("prometheus-postgres-exporter"));
        assertEquals(4, dto.getPods().get(1).getContainers());
        assertEquals(0, dto.getPods().get(1).getContainersReady());
        assertNull(dto.getPods().get(1).getIp());
        assertEquals("stackgres-1", dto.getPods().get(1).getName());
        assertEquals("stackgres", dto.getPods().get(1).getNamespace());
        assertNull(dto.getPods().get(1).getRole());
        assertEquals("Pending", dto.getPods().get(1).getStatus());
        assertEquals(4, dto.getPods().get(1).getComponentVersions().size());
        assertEquals("12.2", dto.getPods().get(1).getComponentVersions().get("postgresql"));
        assertEquals("1.6.4", dto.getPods().get(1).getComponentVersions().get("patroni"));
        assertEquals("1.13.1", dto.getPods().get(1).getComponentVersions().get("envoy"));
        assertEquals("0.8", dto.getPods().get(1).getComponentVersions().get("prometheus-postgres-exporter"));
    }
    if (dto.getInfo() != null) {
        String appendDns = "." + resource.getMetadata().getNamespace() + ".svc.cluster.local";
        String expectedPrimaryDns = PatroniUtil.readWriteName(resource.getMetadata().getName()) + appendDns;
        String expectedReplicasDns = "f4611c56942064ed5a468d8ce0a894ec.us-east-1.elb.amazonaws.com";
        assertEquals(expectedPrimaryDns, dto.getInfo().getPrimaryDns());
        assertEquals(expectedReplicasDns, dto.getInfo().getReplicasDns());
        assertEquals("postgres", dto.getInfo().getSuperuserUsername());
        assertEquals("superuser-password", dto.getInfo().getSuperuserPasswordKey());
        assertEquals(resource.getMetadata().getName(), dto.getInfo().getSuperuserSecretName());
    }
}
Also used : StackGresClusterInitData(io.stackgres.common.crd.sgcluster.StackGresClusterInitData) ClusterInitData(io.stackgres.apiweb.dto.cluster.ClusterInitData) StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) StackGresClusterPod(io.stackgres.common.crd.sgcluster.StackGresClusterPod) StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) ClusterSpec(io.stackgres.apiweb.dto.cluster.ClusterSpec) ClusterConfiguration(io.stackgres.apiweb.dto.cluster.ClusterConfiguration) StackGresClusterConfiguration(io.stackgres.common.crd.sgcluster.StackGresClusterConfiguration) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) StackGresClusterPod(io.stackgres.common.crd.sgcluster.StackGresClusterPod) ClusterPod(io.stackgres.apiweb.dto.cluster.ClusterPod) StackGresPodPersistentVolume(io.stackgres.common.crd.sgcluster.StackGresPodPersistentVolume) ClusterPodPersistentVolume(io.stackgres.apiweb.dto.cluster.ClusterPodPersistentVolume) StackGresClusterInitData(io.stackgres.common.crd.sgcluster.StackGresClusterInitData) StackGresClusterScriptFrom(io.stackgres.common.crd.sgcluster.StackGresClusterScriptFrom) StackGresClusterConfiguration(io.stackgres.common.crd.sgcluster.StackGresClusterConfiguration) StackGresClusterScriptFrom(io.stackgres.common.crd.sgcluster.StackGresClusterScriptFrom) ClusterScriptFrom(io.stackgres.apiweb.dto.cluster.ClusterScriptFrom)

Example 3 with StackGresClusterPod

use of io.stackgres.common.crd.sgcluster.StackGresClusterPod in project stackgres by ongres.

the class StackGresClusterPodFixture method build.

public StackGresClusterPod build() {
    StackGresClusterPod pod = new StackGresClusterPod();
    pod.setScheduling(scheduling);
    return pod;
}
Also used : StackGresClusterPod(io.stackgres.common.crd.sgcluster.StackGresClusterPod)

Example 4 with StackGresClusterPod

use of io.stackgres.common.crd.sgcluster.StackGresClusterPod in project stackgres by ongres.

the class ClusterTransformer method getResourceSpec.

private ClusterSpec getResourceSpec(StackGresClusterSpec source) {
    if (source == null) {
        return null;
    }
    ClusterSpec transformation = new ClusterSpec();
    transformation.setPostgres(new ClusterPostgres());
    transformation.getPostgres().setVersion(source.getPostgres().getVersion());
    transformation.getPostgres().setExtensions(Optional.ofNullable(source.getPostgres().getExtensions()).stream().flatMap(List::stream).map(this::getResourceExtension).collect(ImmutableList.toImmutableList()));
    final StackGresClusterSsl sourceClusterSsl = source.getPostgres().getSsl();
    if (sourceClusterSsl != null) {
        transformation.getPostgres().setSsl(new ClusterSsl());
        transformation.getPostgres().getSsl().setEnabled(sourceClusterSsl.getEnabled());
        transformation.getPostgres().getSsl().setCertificateSecretKeySelector(sourceClusterSsl.getCertificateSecretKeySelector());
        transformation.getPostgres().getSsl().setPrivateKeySecretKeySelector(sourceClusterSsl.getPrivateKeySecretKeySelector());
    }
    transformation.setConfigurations(new ClusterConfiguration());
    transformation.getConfigurations().setSgBackupConfig(source.getConfiguration().getBackupConfig());
    transformation.getConfigurations().setSgPoolingConfig(source.getConfiguration().getConnectionPoolingConfig());
    transformation.setInstances(source.getInstances());
    transformation.setNonProduction(getResourceNonProduction(source.getNonProduction()));
    transformation.getConfigurations().setSgPostgresConfig(source.getConfiguration().getPostgresConfig());
    transformation.setPrometheusAutobind(source.getPrometheusAutobind());
    transformation.setSgInstanceProfile(source.getResourceProfile());
    final StackGresClusterInitData sourceInitData = source.getInitData();
    if (sourceInitData != null) {
        ClusterInitData targetInitData = new ClusterInitData();
        transformation.setInitData(targetInitData);
        final StackGresClusterRestore sourceRestore = sourceInitData.getRestore();
        if (sourceRestore != null) {
            targetInitData.setRestore(getResourceRestore(sourceRestore));
        }
        if (sourceInitData.getScripts() != null) {
            targetInitData.setScripts(sourceInitData.getScripts().stream().map(sourceEntry -> {
                ClusterScriptEntry targetEntry = new ClusterScriptEntry();
                targetEntry.setScript(sourceEntry.getScript());
                targetEntry.setDatabase(sourceEntry.getDatabase());
                targetEntry.setName(sourceEntry.getName());
                if (sourceEntry.getScriptFrom() != null) {
                    targetEntry.setScriptFrom(new ClusterScriptFrom());
                    targetEntry.getScriptFrom().setSecretKeyRef(sourceEntry.getScriptFrom().getSecretKeyRef());
                    targetEntry.getScriptFrom().setConfigMapKeyRef(sourceEntry.getScriptFrom().getConfigMapKeyRef());
                }
                return targetEntry;
            }).collect(ImmutableList.toImmutableList()));
        }
    }
    final ClusterPod targetPod = new ClusterPod();
    final StackGresClusterPod sourcePod = source.getPod();
    transformation.setPods(targetPod);
    targetPod.setPersistentVolume(new ClusterPodPersistentVolume());
    targetPod.getPersistentVolume().setStorageClass(sourcePod.getPersistentVolume().getStorageClass());
    targetPod.getPersistentVolume().setSize(sourcePod.getPersistentVolume().getSize());
    targetPod.setDisableConnectionPooling(sourcePod.getDisableConnectionPooling());
    targetPod.setDisableMetricsExporter(sourcePod.getDisableMetricsExporter());
    targetPod.setDisablePostgresUtil(sourcePod.getDisablePostgresUtil());
    final StackGresClusterSpecMetadata specMetadata = source.getMetadata();
    if (specMetadata != null) {
        transformation.setMetadata(new ClusterSpecMetadata());
        final StackGresClusterSpecAnnotations sourceAnnotations = specMetadata.getAnnotations();
        if (specMetadata.getAnnotations() != null) {
            ClusterSpecAnnotations targetAnnotations = new ClusterSpecAnnotations();
            targetAnnotations.setAllResources(sourceAnnotations.getAllResources());
            targetAnnotations.setClusterPods(sourceAnnotations.getClusterPods());
            targetAnnotations.setServices(sourceAnnotations.getServices());
            targetAnnotations.setPrimaryService(sourceAnnotations.getPrimaryService());
            targetAnnotations.setReplicasService(sourceAnnotations.getReplicasService());
            transformation.getMetadata().setAnnotations(targetAnnotations);
        }
        final StackGresClusterSpecLabels sourceLabels = specMetadata.getLabels();
        if (sourceLabels != null) {
            ClusterSpecLabels targetLabels = new ClusterSpecLabels();
            targetLabels.setClusterPods(sourceLabels.getClusterPods());
            transformation.getMetadata().setLabels(targetLabels);
        }
    }
    final StackGresClusterPostgresServices sourcePostgresServices = source.getPostgresServices();
    if (sourcePostgresServices != null) {
        transformation.setPostgresServices(new ClusterPostgresServices());
        final ClusterPostgresServices targetPostgresService = transformation.getPostgresServices();
        final StackGresPostgresService sourcePrimaryService = sourcePostgresServices.getPrimary();
        if (sourcePrimaryService != null) {
            targetPostgresService.setPrimary(new PostgresService());
            targetPostgresService.getPrimary().setType(sourcePrimaryService.getType());
            targetPostgresService.getPrimary().setEnabled(sourcePrimaryService.getEnabled());
        }
        final StackGresPostgresService sourceReplicaService = sourcePostgresServices.getReplicas();
        if (sourceReplicaService != null) {
            targetPostgresService.setReplicas(new PostgresService());
            targetPostgresService.getReplicas().setEnabled(sourceReplicaService.getEnabled());
            targetPostgresService.getReplicas().setType(sourceReplicaService.getType());
        }
    }
    targetPod.setScheduling(Optional.ofNullable(sourcePod.getScheduling()).map(sourcePodScheduling -> {
        return new ClusterPodSchedulingConverter().from(sourcePodScheduling);
    }).orElse(null));
    transformation.setDistributedLogs(getResourceDistributedLogs(source.getDistributedLogs()));
    if (source.getToInstallPostgresExtensions() != null) {
        transformation.setToInstallPostgresExtensions(source.getToInstallPostgresExtensions().stream().map(this::getClusterInstalledExtension).collect(ImmutableList.toImmutableList()));
    }
    return transformation;
}
Also used : StackGresClusterInitData(io.stackgres.common.crd.sgcluster.StackGresClusterInitData) ClusterInitData(io.stackgres.apiweb.dto.cluster.ClusterInitData) StackGresClusterScriptEntry(io.stackgres.common.crd.sgcluster.StackGresClusterScriptEntry) ClusterScriptEntry(io.stackgres.apiweb.dto.cluster.ClusterScriptEntry) StackGresClusterRestore(io.stackgres.common.crd.sgcluster.StackGresClusterRestore) ClusterPodSchedulingConverter(io.stackgres.apiweb.transformer.converter.cluster.ClusterPodSchedulingConverter) StackGresClusterPostgresServices(io.stackgres.common.crd.sgcluster.StackGresClusterPostgresServices) ClusterPostgresServices(io.stackgres.apiweb.dto.cluster.ClusterPostgresServices) StackGresClusterPod(io.stackgres.common.crd.sgcluster.StackGresClusterPod) StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) ClusterSpec(io.stackgres.apiweb.dto.cluster.ClusterSpec) StackGresClusterConfiguration(io.stackgres.common.crd.sgcluster.StackGresClusterConfiguration) ClusterConfiguration(io.stackgres.apiweb.dto.cluster.ClusterConfiguration) ClusterSpecAnnotations(io.stackgres.apiweb.dto.cluster.ClusterSpecAnnotations) StackGresClusterSpecAnnotations(io.stackgres.common.crd.sgcluster.StackGresClusterSpecAnnotations) StackGresPostgresService(io.stackgres.common.crd.postgres.service.StackGresPostgresService) PostgresService(io.stackgres.apiweb.app.postgres.service.PostgresService) ClusterPod(io.stackgres.apiweb.dto.cluster.ClusterPod) StackGresClusterPod(io.stackgres.common.crd.sgcluster.StackGresClusterPod) StackGresClusterPostgres(io.stackgres.common.crd.sgcluster.StackGresClusterPostgres) ClusterPostgres(io.stackgres.apiweb.dto.cluster.ClusterPostgres) StackGresClusterSpecMetadata(io.stackgres.common.crd.sgcluster.StackGresClusterSpecMetadata) ClusterSpecMetadata(io.stackgres.apiweb.dto.cluster.ClusterSpecMetadata) StackGresClusterSpecAnnotations(io.stackgres.common.crd.sgcluster.StackGresClusterSpecAnnotations) StackGresClusterSsl(io.stackgres.common.crd.sgcluster.StackGresClusterSsl) ClusterSsl(io.stackgres.apiweb.dto.cluster.ClusterSsl) StackGresClusterSsl(io.stackgres.common.crd.sgcluster.StackGresClusterSsl) StackGresClusterSpecLabels(io.stackgres.common.crd.sgcluster.StackGresClusterSpecLabels) StackGresClusterInitData(io.stackgres.common.crd.sgcluster.StackGresClusterInitData) ClusterPodPersistentVolume(io.stackgres.apiweb.dto.cluster.ClusterPodPersistentVolume) StackGresClusterSpecMetadata(io.stackgres.common.crd.sgcluster.StackGresClusterSpecMetadata) StackGresPostgresService(io.stackgres.common.crd.postgres.service.StackGresPostgresService) StackGresClusterScriptFrom(io.stackgres.common.crd.sgcluster.StackGresClusterScriptFrom) ClusterScriptFrom(io.stackgres.apiweb.dto.cluster.ClusterScriptFrom) StackGresClusterSpecLabels(io.stackgres.common.crd.sgcluster.StackGresClusterSpecLabels) ClusterSpecLabels(io.stackgres.apiweb.dto.cluster.ClusterSpecLabels) StackGresClusterPostgresServices(io.stackgres.common.crd.sgcluster.StackGresClusterPostgresServices)

Example 5 with StackGresClusterPod

use of io.stackgres.common.crd.sgcluster.StackGresClusterPod in project stackgres by ongres.

the class DefaultProfileMutator method mutate.

@Override
public List<JsonPatchOperation> mutate(StackGresClusterReview review) {
    if (review.getRequest().getOperation() == Operation.CREATE) {
        ImmutableList.Builder<JsonPatchOperation> operations = ImmutableList.builder();
        final StackGresClusterSpec spec = review.getRequest().getObject().getSpec();
        StackGresClusterPod pod = spec.getPod();
        final JsonPointer clusterPodPointer = CLUSTER_CONFIG_POINTER.append("pod");
        if (pod == null) {
            pod = new StackGresClusterPod();
            spec.setPod(pod);
            operations.add(new AddOperation(clusterPodPointer, FACTORY.objectNode()));
        }
        if (pod.getPersistentVolume() == null) {
            operations.add(new AddOperation(clusterPodPointer.append("persistentVolume"), FACTORY.objectNode()));
        }
        operations.addAll(super.mutate(review));
        return operations.build();
    }
    return ImmutableList.of();
}
Also used : StackGresClusterSpec(io.stackgres.common.crd.sgcluster.StackGresClusterSpec) ImmutableList(com.google.common.collect.ImmutableList) StackGresClusterPod(io.stackgres.common.crd.sgcluster.StackGresClusterPod) JsonPointer(com.github.fge.jackson.jsonpointer.JsonPointer) AddOperation(com.github.fge.jsonpatch.AddOperation) JsonPatchOperation(com.github.fge.jsonpatch.JsonPatchOperation)

Aggregations

StackGresClusterPod (io.stackgres.common.crd.sgcluster.StackGresClusterPod)9 StackGresClusterSpec (io.stackgres.common.crd.sgcluster.StackGresClusterSpec)8 StackGresClusterInitData (io.stackgres.common.crd.sgcluster.StackGresClusterInitData)5 ClusterConfiguration (io.stackgres.apiweb.dto.cluster.ClusterConfiguration)4 ClusterInitData (io.stackgres.apiweb.dto.cluster.ClusterInitData)4 StackGresClusterConfiguration (io.stackgres.common.crd.sgcluster.StackGresClusterConfiguration)4 StackGresClusterSpecMetadata (io.stackgres.common.crd.sgcluster.StackGresClusterSpecMetadata)4 ClusterPod (io.stackgres.apiweb.dto.cluster.ClusterPod)3 ClusterSpecLabels (io.stackgres.apiweb.dto.cluster.ClusterSpecLabels)3 ClusterSpecMetadata (io.stackgres.apiweb.dto.cluster.ClusterSpecMetadata)3 StackGresClusterPodScheduling (io.stackgres.common.crd.sgcluster.StackGresClusterPodScheduling)3 StackGresClusterSpecLabels (io.stackgres.common.crd.sgcluster.StackGresClusterSpecLabels)3 StackGresPodPersistentVolume (io.stackgres.common.crd.sgcluster.StackGresPodPersistentVolume)3 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Container (io.fabric8.kubernetes.api.model.Container)2 Volume (io.fabric8.kubernetes.api.model.Volume)2 VolumeMount (io.fabric8.kubernetes.api.model.VolumeMount)2 PostgresService (io.stackgres.apiweb.app.postgres.service.PostgresService)2 ClusterPodPersistentVolume (io.stackgres.apiweb.dto.cluster.ClusterPodPersistentVolume)2