Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The primary moving parts are:
- Uses the `gcloud` cli to list any primary dbs that match the `PRIMARY_INSTANCE_PREFIX` env
variable as a prefix. (i.e. a prefix of `metadata-` matches `metadata-4093504851`)
- Lists all currently active read replicas of the primary database, excluding any
that have a GCP label matching `REPLICA_SKIP_LABEL` set to `true` (see
that have any GCP label listed in `REPLICA_SKIP_LABEL` set to `true` (see
`discovery.replicaSkipLabel`)
- Uses the [envtpl](https://github.com/subfuzion/envtpl) tool to fill out [pgpool.conf.tmpl](conf/pgpool.conf.tmpl)
and copy the result into `/etc/pgpool/pgpool.conf` if it differs from what is already there.
Expand Down Expand Up @@ -46,6 +46,7 @@ instance no matter what. This is configureable at deploy time as

Old Version | New Version | Upgrade Guide
--- | --- | ---
v1.5.0 | v1.6.0 | [link](UPGRADE.md#v150--v160)
v1.4.1 | v1.5.0 | [link](UPGRADE.md#v141--v150)
v1.4.0 | v1.4.1 | [link](UPGRADE.md#v140--v141)
v1.3.3 | v1.4.0 | [link](UPGRADE.md#v133--v140)
Expand Down Expand Up @@ -80,7 +81,7 @@ helm repo update
```sh
export RELEASE_NAME=my-pgpool-service # a name (you will need 1 installed chart for each primary DB)
export NAMESPACE=my-k8s-namespace # a kubernetes namespace
export CHART_VERSION=1.5.0 # a chart version: https://github.com/odenio/pgpool-cloudsql/releases
export CHART_VERSION=1.6.0 # a chart version: https://github.com/odenio/pgpool-cloudsql/releases
export VALUES_FILE=./my_values.yaml # your values file

helm install \
Expand Down Expand Up @@ -191,7 +192,7 @@ Parameter | Description | Default
Parameter | Description | Default
--- | --- | ---
`discovery.primaryInstancePrefix` | *REQUIRED* Search sting used to find the primary instance ID; is fed to `gcloud sql instances list --filter name:${PRIMARY_INSTANCE_PREFIX}`. *Must* match only one instance. | (none)
`discovery.replicaSkipLabel` | If set, replicas that have this GCP instance label set to `"true"` will be excluded from pgpool's backend pool. This is useful for dedicating specific read replicas to other consumers (e.g. analytics) without pgpool load-balancing application traffic to them. | `""`
`discovery.replicaSkipLabel` | If set, replicas that have any listed GCP instance label set to `"true"` will be excluded from pgpool's backend pool. Provide either a single label or a comma-separated list. This is useful for dedicating specific read replicas to other consumers (e.g. analytics) without pgpool load-balancing application traffic to them. | `""`
`discovery.pruneThreshold` | Threshold in seconds after which an undiscoverable (missing or not in state `RUNNABLE`) replica will be removed from the generated configuration file. | `900`

<hr>
Expand Down Expand Up @@ -408,4 +409,3 @@ But there was some good news: the
[pgpool2_exporter](https://github.com/pgpool/pgpool2_exporter) is a standalone
binary that scrapes and parses the data returned by the "sql-like" commands and
exports it as a prometheus-compatible `/metrics` endpoint.

19 changes: 15 additions & 4 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Upgrading Steps

## `v1.5.0` → `v1.6.0`

### New features

The discovery container now accepts multiple skip labels in
`discovery.replicaSkipLabel` as a comma-separated list. Any replica with one of
those labels set to `"true"` will be excluded from pgpool's backend pool.

Existing single-label configurations continue to work unchanged.

## `v1.4.1` → `v1.5.0`

### New features
Expand All @@ -9,9 +19,10 @@ backend pool by GCP instance label. This is useful when you have dedicated
read replicas that serve a specific consumer (e.g. an analytics engine) and
you don't want pgpool load-balancing general application traffic to them.

To use this feature, apply a GCP label to the CloudSQL instance you want to
exclude (e.g. `pgpool-cloudsql-skip: "true"`), and set the
`discovery.replicaSkipLabel` chart value to the label key:
To use this feature, apply one or more GCP labels to the CloudSQL instance you
want to exclude (e.g. `pgpool-cloudsql-skip: "true"`), and set the
`discovery.replicaSkipLabel` chart value to the label key or comma-separated
label keys:

```yaml
discovery:
Expand All @@ -24,7 +35,7 @@ When unset (the default), all replicas of the primary are included as before.

Parameter | Description | Default
--- | --- | ---
`discovery.replicaSkipLabel` | If set, replicas with this GCP instance label set to `"true"` are excluded from pgpool's backend pool. | `""`
`discovery.replicaSkipLabel` | If set, replicas with any listed GCP instance label set to `"true"` are excluded from pgpool's backend pool. Provide either a single label or a comma-separated list. | `""`

## `v1.4.0` → `v1.4.1`

Expand Down
12 changes: 11 additions & 1 deletion bin/discovery.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,17 @@ while true; do

replica_filter="region:${REGION} AND masterInstanceName:${PROJECT_ID}:${primary_name} AND state:RUNNABLE"
if [[ -n "${REPLICA_SKIP_LABEL:-}" ]]; then
replica_filter+=" AND NOT labels.${REPLICA_SKIP_LABEL}=true"
# Support either a single label or a comma-separated list in REPLICA_SKIP_LABEL.
IFS=',' read -r -a replica_skip_labels <<<"${REPLICA_SKIP_LABEL}"
for replica_skip_label in "${replica_skip_labels[@]}"; do
# Trim surrounding whitespace and ignore empty entries so values like
# "foo, bar, ,baz" generate only the intended filter clauses.
replica_skip_label="${replica_skip_label#"${replica_skip_label%%[![:space:]]*}"}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're my kind of madman, but maybe a comment to explain what this and the next line are doing?

replica_skip_label="${replica_skip_label%"${replica_skip_label##*[![:space:]]}"}"
if [[ -n "${replica_skip_label}" ]]; then
replica_filter+=" AND NOT labels.${replica_skip_label}=true"
fi
done
fi

mapfile -t current_replicas < <(
Expand Down
2 changes: 1 addition & 1 deletion charts/pgpool-cloudsql/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ apiVersion: v2
description: the pgpool-ii connection pooling postgres proxy with automatic discovery of GCP CloudSQL backends
name: pgpool-cloudsql
type: application
version: 1.5.0
version: 1.6.0
Comment thread
n-oden marked this conversation as resolved.
keywords:
- postgresql
- pgpool
Expand Down
7 changes: 4 additions & 3 deletions charts/pgpool-cloudsql/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,11 @@ discovery:
# `--filter name:${primaryInstancePrefix}` option and MUST match one and only one
# non-replica instance.
primaryInstancePrefix: "" # REQUIRED!
# If set, replicas that have this GCP label set to "true" will be excluded from
# pgpool's backend pool. This is useful for dedicating specific read replicas to
# If set, replicas that have any of these GCP labels set to "true" will be
# excluded from pgpool's backend pool. Provide either a single label or a
# comma-separated list. This is useful for dedicating specific read replicas to
# other consumers (e.g. analytics) without pgpool load-balancing application
# traffic to them. The label must be applied to the CloudSQL instance in GCP.
# traffic to them. The labels must be applied to the CloudSQL instance in GCP.
replicaSkipLabel: ""
# The Google Cloud region where discovery logic looks for databases.
# if "true" it's the same pod's region,
Expand Down
Loading