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();
}
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);
}
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();
}
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();
}
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();
}
Aggregations