Search in sources :

Example 41 with StackGresCluster

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

the class PatroniServices method createPatroniRestService.

private Service createPatroniRestService(StackGresClusterContext context) {
    final StackGresCluster cluster = context.getSource();
    final Map<String, String> clusterLabels = labelFactory.clusterLabels(cluster);
    return new ServiceBuilder().withNewMetadata().withNamespace(cluster.getMetadata().getNamespace()).withName(restName(context)).withLabels(clusterLabels).endMetadata().withNewSpec().withPorts(new ServicePortBuilder().withProtocol("TCP").withName(PATRONI_RESTAPI_PORT_NAME).withPort(PATRONI_SERVICE_PORT).withTargetPort(new IntOrString(PATRONI_RESTAPI_PORT_NAME)).build()).withSelector(labelFactory.patroniClusterLabels(cluster)).withType(StackGresPostgresServiceType.CLUSTER_IP.toString()).endSpec().build();
}
Also used : StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder)

Example 42 with StackGresCluster

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

the class PatroniServices method configName.

public String configName(ClusterContext clusterContext) {
    final StackGresCluster cluster = clusterContext.getCluster();
    final String scope = labelFactory.clusterScope(cluster);
    return ResourceUtil.resourceName(scope + PatroniUtil.CONFIG_SERVICE);
}
Also used : StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) IntOrString(io.fabric8.kubernetes.api.model.IntOrString)

Example 43 with StackGresCluster

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

the class PatroniServices method createPatroniService.

private Service createPatroniService(StackGresClusterContext context) {
    StackGresCluster cluster = context.getSource();
    final Map<String, String> primaryLabels = labelFactory.patroniPrimaryLabels(cluster);
    Map<String, String> annotations = Optional.ofNullable(cluster.getSpec()).map(StackGresClusterSpec::getMetadata).map(StackGresClusterSpecMetadata::getAnnotations).map(StackGresClusterSpecAnnotations::getPrimaryService).orElse(Map.of());
    String serviceType = Optional.ofNullable(cluster.getSpec()).map(StackGresClusterSpec::getPostgresServices).map(StackGresClusterPostgresServices::getPrimary).map(StackGresPostgresService::getType).orElse(StackGresPostgresServiceType.CLUSTER_IP.toString());
    return new ServiceBuilder().withNewMetadata().withNamespace(cluster.getMetadata().getNamespace()).withName(name(context)).withLabels(primaryLabels).withAnnotations(annotations).endMetadata().withNewSpec().withPorts(new ServicePortBuilder().withProtocol("TCP").withName(PatroniConfigMap.POSTGRES_PORT_NAME).withPort(PatroniUtil.POSTGRES_SERVICE_PORT).withTargetPort(new IntOrString(PatroniConfigMap.POSTGRES_PORT_NAME)).build(), new ServicePortBuilder().withProtocol("TCP").withName(PatroniConfigMap.POSTGRES_REPLICATION_PORT_NAME).withPort(PatroniUtil.REPLICATION_SERVICE_PORT).withTargetPort(new IntOrString(PatroniConfigMap.POSTGRES_REPLICATION_PORT_NAME)).build()).withType(serviceType).endSpec().build();
}
Also used : StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) ServicePortBuilder(io.fabric8.kubernetes.api.model.ServicePortBuilder) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) StackGresClusterSpecMetadata(io.stackgres.common.crd.sgcluster.StackGresClusterSpecMetadata) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) StackGresClusterPostgresServices(io.stackgres.common.crd.sgcluster.StackGresClusterPostgresServices) ServiceBuilder(io.fabric8.kubernetes.api.model.ServiceBuilder)

Example 44 with StackGresCluster

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

the class ResetPatroniInit method getContainer.

@Override
public Container getContainer(StackGresClusterContainerContext context) {
    final StackGresClusterContext clusterContext = context.getClusterContext();
    String primaryInstance = Optional.of(clusterContext.getSource()).map(StackGresCluster::getStatus).map(StackGresClusterStatus::getDbOps).map(StackGresClusterDbOpsStatus::getMajorVersionUpgrade).map(StackGresClusterDbOpsMajorVersionUpgradeStatus::getPrimaryInstance).orElseThrow();
    return new ContainerBuilder().withName("reset-patroni-initialize").withImage(StackGresComponent.KUBECTL.findLatestImageName()).withImagePullPolicy("IfNotPresent").withCommand("/bin/sh", "-ex", ClusterStatefulSetPath.TEMPLATES_PATH.path() + "/" + ClusterStatefulSetPath.LOCAL_BIN_RESET_PATRONI_INITIALIZE_SH_PATH.filename()).addToEnv(new EnvVarBuilder().withName("PRIMARY_INSTANCE").withValue(primaryInstance).build(), new EnvVarBuilder().withName("POD_NAME").withValueFrom(new EnvVarSourceBuilder().withFieldRef(new ObjectFieldSelector("v1", "metadata.name")).build()).build(), new EnvVarBuilder().withName("CLUSTER_NAMESPACE").withValue(clusterContext.getCluster().getMetadata().getNamespace()).build(), new EnvVarBuilder().withName("PATRONI_ENDPOINT_NAME").withValue(patroniServices.configName(clusterContext)).build()).addAllToEnv(patroniEnvironmentVariables.createResource(clusterContext)).withVolumeMounts(new VolumeMountBuilder().withName(PatroniStaticVolume.USER.getVolumeName()).withMountPath("/etc/passwd").withSubPath("etc/passwd").withReadOnly(true).build()).addAllToVolumeMounts(templateMounts.getVolumeMounts(context)).addToVolumeMounts(new VolumeMountBuilder().withName(PatroniStaticVolume.LOCAL_BIN.getVolumeName()).withMountPath("/usr/local/bin/dbops/major-version-upgrade/reset-patroni-initialize.sh").withSubPath("reset-patroni-initialize.sh").withReadOnly(true).build()).addAllToVolumeMounts(postgresDataMounts.getVolumeMounts(context)).build();
}
Also used : StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) ObjectFieldSelector(io.fabric8.kubernetes.api.model.ObjectFieldSelector) ContainerBuilder(io.fabric8.kubernetes.api.model.ContainerBuilder) EnvVarSourceBuilder(io.fabric8.kubernetes.api.model.EnvVarSourceBuilder) StackGresClusterDbOpsStatus(io.stackgres.common.crd.sgcluster.StackGresClusterDbOpsStatus) StackGresClusterContext(io.stackgres.operator.conciliation.cluster.StackGresClusterContext) VolumeMountBuilder(io.fabric8.kubernetes.api.model.VolumeMountBuilder) EnvVarBuilder(io.fabric8.kubernetes.api.model.EnvVarBuilder)

Example 45 with StackGresCluster

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

the class BackupConfigMap method buildSource.

@NotNull
public HasMetadata buildSource(StackGresClusterContext context) {
    final Map<String, String> data = new HashMap<>();
    final StackGresCluster cluster = context.getCluster();
    context.getBackupConfig().ifPresent(backupConfig -> {
        data.put("BACKUP_CONFIG_RESOURCE_VERSION", backupConfig.getMetadata().getResourceVersion());
        data.putAll(getBackupEnvVars(context, cluster.getMetadata().getNamespace(), cluster.getMetadata().getName(), backupConfig.getSpec()));
    });
    return new ConfigMapBuilder().withNewMetadata().withNamespace(cluster.getMetadata().getNamespace()).withName(name(context)).withLabels(labelFactory.patroniClusterLabels(cluster)).endMetadata().withData(StackGresUtil.addMd5Sum(data)).build();
}
Also used : StackGresCluster(io.stackgres.common.crd.sgcluster.StackGresCluster) HashMap(java.util.HashMap) ConfigMapBuilder(io.fabric8.kubernetes.api.model.ConfigMapBuilder) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

StackGresCluster (io.stackgres.common.crd.sgcluster.StackGresCluster)127 Test (org.junit.jupiter.api.Test)48 Optional (java.util.Optional)32 List (java.util.List)31 StackGresClusterSpec (io.stackgres.common.crd.sgcluster.StackGresClusterSpec)27 StackGresClusterInstalledExtension (io.stackgres.common.crd.sgcluster.StackGresClusterInstalledExtension)25 ImmutableList (com.google.common.collect.ImmutableList)24 Inject (javax.inject.Inject)22 ArrayList (java.util.ArrayList)19 StackGresClusterStatus (io.stackgres.common.crd.sgcluster.StackGresClusterStatus)18 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)15 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)15 StackGresComponent (io.stackgres.common.StackGresComponent)15 StackGresClusterPodStatus (io.stackgres.common.crd.sgcluster.StackGresClusterPodStatus)14 ExtensionInstaller (io.stackgres.common.extension.ExtensionManager.ExtensionInstaller)14 StackGresClusterReview (io.stackgres.operator.common.StackGresClusterReview)13 Collectors (java.util.stream.Collectors)13 BeforeEach (org.junit.jupiter.api.BeforeEach)13 ExtensionUninstaller (io.stackgres.common.extension.ExtensionManager.ExtensionUninstaller)12 JsonUtil (io.stackgres.testutil.JsonUtil)12