Skip to content

Commit

Permalink
feat: added SGShardedCluster
Browse files Browse the repository at this point in the history
  • Loading branch information
teoincontatto committed Mar 21, 2023
1 parent 574a1ec commit 9c4c452
Show file tree
Hide file tree
Showing 382 changed files with 15,625 additions and 1,307 deletions.
2 changes: 1 addition & 1 deletion doc/content/en/06-crd-reference/01-sgcluster/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: SGCluster
weight: 1
url: reference/crd/sgcluster
description: Details about SGCluster configurations
description: Details about SGCluster
showToc: true
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: SGInstanceProfile
weight: 2
url: reference/crd/sginstanceprofile
description: Details about SGInstanceProfile configurations
description: Details about SGInstanceProfile
---

The `SGInstanceProfile` custom resource represents the CPU and memory resources assigned to each pod of the Postgres cluster.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: SGPostgresConfig
weight: 3
url: reference/crd/sgpgconfig
description: Details about SGPostgresConfig configurations
description: Details about SGPostgresConfig
---

The `SGPostgresConfig` custom resource represents the PostgreSQL configuration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: SGPoolingConfig
weight: 4
url: reference/crd/sgpoolingconfig
description: Details about SGPoolingConfig configurations
description: Details about SGPoolingConfig
---

The `SGPoolingConfig` custom resource represents the configuration of the connection pooling, in particular of PgBouncer.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: SGBackupConfig
weight: 5
url: reference/crd/sgbackupconfig
description: Details about SGBackupConfig configurations
description: Details about SGBackupConfig
showToc: true
---

Expand Down
2 changes: 1 addition & 1 deletion doc/content/en/06-crd-reference/06-sgbackup/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: SGBackup
weight: 7
url: reference/crd/sgbackup
description: Details about SGBackup configurations
description: Details about SGBackup
showToc: true
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: SGDistributedLogs
weight: 8
url: reference/crd/sgdistributedlogs
description: Details about SGDistributedLogs configurations
description: Details about SGDistributedLogs
showToc: true
---

Expand Down
2 changes: 1 addition & 1 deletion doc/content/en/06-crd-reference/09-sgdbops/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: SGDbOps
weight: 9
url: reference/crd/sgdbops
description: Details about SGDbOps configurations
description: Details about SGDbOps
showToc: true
---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: SGObjectStorage
weight: 10
url: reference/crd/sgobjectstorage
description: Details about SGObjectStorage configurations
description: Details about SGObjectStorage
showToc: true
---

Expand Down
2 changes: 1 addition & 1 deletion doc/content/en/06-crd-reference/11-sgscript/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
title: SGScript
weight: 11
url: reference/crd/sgscript
description: Details about SGScript configurations
description: Details about SGScript
showToc: true
---

Expand Down
171 changes: 171 additions & 0 deletions doc/content/en/06-crd-reference/12-sgshardedcluster/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
---
title: SGShardedCluster
weight: 12
url: reference/crd/sgshardedcluster
description: Details about SGShardedCluster
showToc: true
---

StackGres PostgreSQL sharded clusters are created using the `SGShardedCluster` custom resource.

___

**Kind:** SGShardedCluster

**listKind:** SGShardedClusterList

**plural:** sgshardedclusters

**singular:** sgshardedcluster
___

**Spec**

| <div style="width:12rem">Property</div> | Required | Updatable | <div style="width:5rem">Type</div> | Default | Description |
|:-------------------------------------------------------------------------------------------|----------|-----------|:-----------------------------------|:------------------|:-------------------------------------------------------------------|
| type ||| string | | {{< crd-field-description SGShardedCluster.spec.type >}} |
| database ||| string | | {{< crd-field-description SGShardedCluster.spec.database >}} |
| [postgres](#postgres) | || object | | {{< crd-field-description SGShardedCluster.spec.postgres >}} |
| [coordinator](#coordinator) ||| object | | {{< crd-field-description SGShardedCluster.spec.coordinator >}} |
| [shards](#shards) ||| object | | {{< crd-field-description SGShardedCluster.spec.shards >}} |
| prometheusAutobind | || boolean | false | {{< crd-field-description SGShardedCluster.spec.prometheusAutobind >}} |
| [nonProductionOptions](#non-production-options) | || array | | {{< crd-field-description SGShardedCluster.spec.nonProductionOptions >}} |

Example:

```yaml
apiVersion: stackgres.io/v1alpha1
kind: SGShardedCluster
metadata:
name: stackgres
spec:
postgres:
version: 'latest'
coordinator:
instances: 1
pods:
persistentVolume:
size: '5Gi'
shards:
clusters: 2
instancesPerCluster: 1
pods:
persistentVolume:
size: '5Gi'
```
## Postgres
| <div style="width:6rem">Property</div> | Required | Updatable | <div style="width:4rem">Type</div> | Default | Description |
|:---------------------------------------|----------|-----------|:-----------------------------------|:---------|:-----------------------------------------------------------------|
| version | ✓ | ✓ | string | | {{< crd-field-description SGShardedCluster.spec.postgres.version >}} |
## Coordinator
| <div style="width:12rem">Property</div> | Required | Updatable | <div style="width:5rem">Type</div> | Default | Description |
|:-------------------------------------------------------------------------------------------|----------|-----------|:-----------------------------------|:------------------|:-------------------------------------------------------------------|
| instances | ✓ | ✓ | integer | | {{< crd-field-description SGShardedCluster.spec.coordinator.instances >}} |
| [sgInstanceProfile]({{% relref "/06-crd-reference/02-sginstanceprofile" %}}) | | ✓ | string | will be generated | {{< crd-field-description SGShardedCluster.spec.coordinator.sgInstanceProfile >}} |
| [pods](#pods) | ✓ | ✓ | object | | {{< crd-field-description SGShardedCluster.spec.coordinator.pods >}} |
| [configurations](#configurations) | | ✓ | object | | {{< crd-field-description SGShardedCluster.spec.coordinator.configurations >}} |
## Coordinator Pods
Cluster's pod configuration
| <div style="width:14rem">Property</div> | Required | Updatable | <div style="width:5rem">Type</div> | <div style="width:4rem">Default</div> | Description |
|:----------------------------------------|----------|-----------|:-----------------------------------|:--------------------------------------|:------------|
| [persistentVolume](#shards-persistent-volume) | ✓ | ✓ | object | | {{< crd-field-description SGShardedCluster.spec.coordinator.pods.persistentVolume >}} |
### SCoordinatorhards Persistent Volume
Configuration of the persistent volumes that the cluster pods are going to use.
| <div style="width:7rem">Property</div> | Required | Updatable | <div style="width:4rem">Type</div> | <div style="width:11rem">Default</div> | Description |
|:---------------------------------------|----------|-----------|:-----------------------------------|:---------------------------------------|:------------|
| size | ✓ | ✓ | string | | {{< crd-field-description SGShardedCluster.spec.coordinator.pods.persistentVolume.size >}} |
| storageClass | | ✓ | string | default storage class | {{< crd-field-description SGShardedCluster.spec.coordinator.pods.persistentVolume.storageClass >}} |
```yaml
apiVersion: stackgres.io/v1alpha1
kind: SGShardedCluster
metadata:
name: stackgres
spec:
pods:
persistentVolume:
size: '5Gi'
storageClass: default
```
## Coordinator Configurations
Custom Postgres configuration.
| <div style="width:9rem">Property</div> | Required | Updatable | <div style="width:4rem">Type</div> | Default | Description |
|:--------------------------------------------------------------------------|----------|-----------|:-----------------------------------|:------------------|:------------|
| [sgPostgresConfig]({{% relref "06-crd-reference/03-sgpostgresconfig" %}}) | | ✓ | string | will be generated | {{< crd-field-description SGShardedCluster.spec.coordinator.configurations.sgPostgresConfig >}} |
| [sgPoolingConfig]({{% relref "06-crd-reference/04-sgpoolingconfig" %}}) | | ✓ | string | will be generated | {{< crd-field-description SGShardedCluster.spec.coordinator.configurations.sgPoolingConfig >}} |
## Shards
| <div style="width:12rem">Property</div> | Required | Updatable | <div style="width:5rem">Type</div> | Default | Description |
|:-------------------------------------------------------------------------------------------|----------|-----------|:-----------------------------------|:------------------|:-------------------------------------------------------------------|
| clusters | ✓ | ✓ | integer | | {{< crd-field-description SGShardedCluster.spec.shards.clusters >}} |
| instancesPerCluster | ✓ | ✓ | integer | | {{< crd-field-description SGShardedCluster.spec.shards.instancesPerCluster >}} |
| [sgInstanceProfile]({{% relref "/06-crd-reference/02-sginstanceprofile" %}}) | | ✓ | string | will be generated | {{< crd-field-description SGShardedCluster.spec.shards.sgInstanceProfile >}} |
| [pods](#shards-pods) | ✓ | ✓ | object | | {{< crd-field-description SGShardedCluster.spec.shards.pods >}} |
| [configurations](#shards-configurations) | | ✓ | object | | {{< crd-field-description SGShardedCluster.spec.shards.configurations >}} |
## Shards Pods
Cluster's pod configuration
| <div style="width:14rem">Property</div> | Required | Updatable | <div style="width:5rem">Type</div> | <div style="width:4rem">Default</div> | Description |
|:----------------------------------------|----------|-----------|:-----------------------------------|:--------------------------------------|:------------|
| [persistentVolume](#shards-persistent-volume) | ✓ | ✓ | object | | {{< crd-field-description SGShardedCluster.spec.shards.pods.persistentVolume >}} |
### Shards Persistent Volume
Configuration of the persistent volumes that the cluster pods are going to use.
| <div style="width:7rem">Property</div> | Required | Updatable | <div style="width:4rem">Type</div> | <div style="width:11rem">Default</div> | Description |
|:---------------------------------------|----------|-----------|:-----------------------------------|:---------------------------------------|:------------|
| size | ✓ | ✓ | string | | {{< crd-field-description SGShardedCluster.spec.shards.pods.persistentVolume.size >}} |
| storageClass | | ✓ | string | default storage class | {{< crd-field-description SGShardedCluster.spec.shards.pods.persistentVolume.storageClass >}} |
```yaml
apiVersion: stackgres.io/v1alpha1
kind: SGShardedCluster
metadata:
name: stackgres
spec:
pods:
persistentVolume:
size: '5Gi'
storageClass: default
```
## Shards Configurations
Custom Postgres configuration.
| <div style="width:9rem">Property</div> | Required | Updatable | <div style="width:4rem">Type</div> | Default | Description |
|:--------------------------------------------------------------------------|----------|-----------|:-----------------------------------|:------------------|:------------|
| [sgPostgresConfig]({{% relref "06-crd-reference/03-sgpostgresconfig" %}}) | | ✓ | string | will be generated | {{< crd-field-description SGShardedCluster.spec.shards.configurations.sgPostgresConfig >}} |
| [sgPoolingConfig]({{% relref "06-crd-reference/04-sgpoolingconfig" %}}) | | ✓ | string | will be generated | {{< crd-field-description SGShardedCluster.spec.shards.configurations.sgPoolingConfig >}} |
## Non Production Options
The following options should NOT be enabled in a production environment.
| <div style="width:19rem">Property</div> | Re&shy;quired | Up&shy;datable | <div style="width:5rem">Type</div> | <div style="width:4rem">Default</div> | Description |
|:----------------------------------------|---------------|----------------|:-----------------------------------|:--------------------------------------|:------------|
| disableClusterPodAntiAffinity | | ✓ | boolean | false | {{< crd-field-description SGShardedCluster.spec.nonProductionOptions.disableClusterPodAntiAffinity >}} |
| disablePatroniResourceRequirements | | ✓ | boolean | false | {{< crd-field-description SGShardedCluster.spec.nonProductionOptions.disablePatroniResourceRequirements >}} |
| disableClusterResourceRequirements | | ✓ | boolean | false | {{< crd-field-description SGShardedCluster.spec.nonProductionOptions.disableClusterResourceRequirements >}} |
| enableSetPatroniCpuRequests | | ✓ | boolean | false | {{< crd-field-description SGShardedCluster.spec.nonProductionOptions.enableSetPatroniCpuRequests >}} |
| enableSetClusterCpuRequests | | ✓ | boolean | false | {{< crd-field-description SGShardedCluster.spec.nonProductionOptions.enableSetClusterCpuRequests >}} |
| enableSetPatroniMemoryRequests | | ✓ | boolean | false | {{< crd-field-description SGShardedCluster.spec.nonProductionOptions.enableSetPatroniMemoryRequests >}} |
| enableSetClusterMemoryRequests | | ✓ | boolean | false | {{< crd-field-description SGShardedCluster.spec.nonProductionOptions.enableSetClusterMemoryRequests >}} |
| enabledFeatureGates | | ✓ | boolean | false | {{< crd-field-description SGShardedCluster.spec.nonProductionOptions.enabledFeatureGates >}} |
77 changes: 77 additions & 0 deletions stackgres-k8s/e2e/spec/sharded-cluster
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/bin/sh

. "$SPEC_PATH/abstract/patroni"

e2e_test_extra_hash() {
"$SHELL" "$PROJECT_PATH/stackgres-k8s/ci/build/build-functions.sh" path_hash \
"$(realpath --relative-to "$PROJECT_PATH" "$SPEC_PATH/abstract/patroni")"
}

e2e_test_install() {
create_or_replace_sharded_cluster "$CLUSTER_NAME" "$CLUSTER_NAMESPACE" "3" "2"

deploy_curl_pod "$CLUSTER_NAMESPACE"

wait_pods_running "$CLUSTER_NAMESPACE" 7
wait_sharded_cluster "$CLUSTER_NAME" "$CLUSTER_NAMESPACE"
}

e2e_test() {
run_test "Checking that is possible to connect using services is working" service_check

run_test "Checking that sharded technology is working is working" sharded_check

run_test "Check that pgbouncer database is accesible using the service" pgbouncer_database_check
}

service_check() {
RESPONSE_PRIMARY="$(run_query -c "$CLUSTER_NAME-0" -h "$CLUSTER_NAME" -i 1 -p 5432)"

if [ "$RESPONSE_PRIMARY" = "1" ]
then
echo "SUCCESS: Connections are possible using services"
else
echo "FAIL: Cannot connect to primary db using a kubernetes service"
return 1
fi
}

sharded_check() {
local RESULT EXIT_CODE
try_function wait_until eval 'run_query -c "$CLUSTER_NAME-0" -h "$CLUSTER_NAME" -i 1 -p 5432 \
-d citus -q "SELECT COUNT(*) FROM master_get_active_worker_nodes()" | grep -xF 2'

if [ "$EXIT_CODE" = 0 ]
then
echo "SUCCESS: Sharding is working"
else
echo "FAIL: Sharding is not working"
return 1
fi
}

pgbouncer_database_check() {
if kubectl exec -n "$CLUSTER_NAMESPACE" "${CLUSTER_NAME}-0-0" -c "postgres-util" -- env \
PGPASSWORD="$(kubectl -n "$CLUSTER_NAMESPACE" get secrets "$CLUSTER_NAME-0" \
-o jsonpath='{.data.pgbouncer-admin-password}' | base64 -d)" \
PGCONNECT_TIMEOUT="$((5 + E2E_TIMEOUT / 10))" \
psql -t -A -U pgbouncer_admin -d pgbouncer -h "$CLUSTER_NAME" -c "SHOW FDS" >/dev/null
then
echo "SUCCESS: psql could connect to the pgbouncer database with pgobuncer_admin using service"
else
echo "FAIL: psql could not connect to the pgbouncer database with pgobuncer_admin using service"
return 1
fi

if kubectl exec -n "$CLUSTER_NAMESPACE" "${CLUSTER_NAME}-0-0" -c "postgres-util" -- env \
PGPASSWORD="$(kubectl -n "$CLUSTER_NAMESPACE" get secrets "$CLUSTER_NAME-0" \
-o jsonpath='{.data.pgbouncer-stats-password}' | base64 -d)" \
PGCONNECT_TIMEOUT="$((5 + E2E_TIMEOUT / 10))" \
psql -t -A -U pgbouncer_stats -d pgbouncer -h "$CLUSTER_NAME" -c "SHOW VERSION" >/dev/null
then
echo "SUCCESS: psql could connect to the pgbouncer database with pgobuncer_stats using service"
else
echo "FAIL: psql could not connect to the pgbouncer database with pgobuncer_stats using service"
return 1
fi
}
Loading

0 comments on commit 9c4c452

Please sign in to comment.