diff --git a/.github/workflows/render.yml b/.github/workflows/render.yml index 501c6cd..1bd4692 100644 --- a/.github/workflows/render.yml +++ b/.github/workflows/render.yml @@ -2,6 +2,8 @@ name: Render Helm chart on: push: + branches: [main] + pull_request: jobs: render: @@ -18,8 +20,43 @@ jobs: with: version: latest - - name: Lint chart - run: helm lint . + - name: Run chart tests + run: ./test/test.sh - - name: Render chart - run: helm template control . + validate-configs: + runs-on: blacksmith-4vcpu-ubuntu-2404 + timeout-minutes: 30 + permissions: + contents: read + env: + CONTROL2_IMAGE: ghcr.io/pgdogdev/pgdog-enterprise/control:main-ent + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Install Helm + uses: azure/setup-helm@v4 + with: + version: latest + + - name: Install yq + uses: mikefarah/yq@master + + - name: Pull control2 image + run: docker pull "$CONTROL2_IMAGE" + + - name: Validate generated control configs + run: | + set -eo pipefail + for values_file in test/values-*.yaml; do + name=$(basename "$values_file" .yaml | sed 's/values-//') + echo "==> Validating control config for $name..." + rm -f /tmp/control.toml + ./test/generate-config.sh "$values_file" /tmp/control.toml + docker run --rm \ + -v /tmp/control.toml:/tmp/control.toml:ro \ + "$CONTROL2_IMAGE" \ + /usr/local/bin/control2 configcheck --config /tmp/control.toml + done + echo "==> All control configs valid!" diff --git a/Chart.yaml b/Chart.yaml index da2a25b..918e1af 100644 --- a/Chart.yaml +++ b/Chart.yaml @@ -2,5 +2,5 @@ apiVersion: v2 name: pgdog-control description: PgDog Control type: application -version: 0.2.11 +version: 0.2.12 appVersion: "1a6d7fd0" diff --git a/templates/configmap.yaml b/templates/configmap.yaml index 295662a..92cfdbd 100644 --- a/templates/configmap.yaml +++ b/templates/configmap.yaml @@ -84,6 +84,9 @@ data: {{- with .evict_after_secs }} evict_after_secs = {{ . }} {{- end }} + {{- with .process_notify_interval_secs }} + process_notify_interval_secs = {{ . }} + {{- end }} {{- with .metrics_retention_secs }} metrics_retention_secs = {{ . }} {{- end }} @@ -91,7 +94,15 @@ data: query_history_limit = {{ .query_history_limit }} {{- end }} {{- if hasKey . "autoreload" }} - autoreload = {{ .autoreload }} + autoreload = {{ .autoreload | quote }} + {{- end }} + {{- end }} + + {{- with $config.autoscaling }} + + [autoscaling] + {{- if hasKey . "pool_size" }} + pool_size = {{ .pool_size }} {{- end }} {{- end }} diff --git a/test/generate-config.sh b/test/generate-config.sh new file mode 100755 index 0000000..ca43a44 --- /dev/null +++ b/test/generate-config.sh @@ -0,0 +1,27 @@ +#!/bin/bash +set -eo pipefail + +TEST_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +CHART_DIR="$TEST_DIR/.." + +if [ -z "$1" ]; then + echo "Usage: $0 [output-file]" + echo "Example: $0 values-full.yaml control.toml" + exit 1 +fi + +VALUES_FILE="$1" + +output=$(helm template test-release "$CHART_DIR" -f "$VALUES_FILE" \ + | yq -r 'select(.kind == "ConfigMap" and has("data") and .data["control.toml"]) | .data["control.toml"]') + +if [ -z "$output" ]; then + echo "FAIL: control.toml not found in rendered ConfigMap" + exit 1 +fi + +if [ -z "$2" ]; then + echo "$output" +else + echo "$output" > "$2" +fi diff --git a/test/test.sh b/test/test.sh new file mode 100755 index 0000000..9bef6a6 --- /dev/null +++ b/test/test.sh @@ -0,0 +1,18 @@ +#!/bin/bash +set -eo pipefail + +TEST_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +CHART_DIR="$TEST_DIR/.." + +echo "==> Linting Helm chart..." +helm lint "$CHART_DIR" + +for values_file in "$TEST_DIR"/values-*.yaml; do + name=$(basename "$values_file" .yaml | sed 's/values-//') + echo "" + echo "==> Rendering $name..." + helm template test-release "$CHART_DIR" -f "$values_file" > /dev/null +done + +echo "" +echo "==> All chart tests passed!" diff --git a/test/values-autoscaling.yaml b/test/values-autoscaling.yaml new file mode 100644 index 0000000..32932f7 --- /dev/null +++ b/test/values-autoscaling.yaml @@ -0,0 +1,6 @@ +control: + config: + store: + process_notify_interval_secs: 30 + autoscaling: + pool_size: true diff --git a/test/values-default.yaml b/test/values-default.yaml new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/test/values-default.yaml @@ -0,0 +1 @@ +{} diff --git a/test/values-full.yaml b/test/values-full.yaml new file mode 100644 index 0000000..4e271fa --- /dev/null +++ b/test/values-full.yaml @@ -0,0 +1,72 @@ +control: + aws: + roleArn: arn:aws:iam::123456789012:role/pgdog-control + region: us-west-2 + rbac: + writeNamespaces: + - pgdog + - pgdog-staging + config: + api: + pgdog: + ip_allowlist: + enabled: true + allowed_cidrs: + - 10.0.0.0/8 + - 192.168.0.0/16 + rds: + refresh_interval_secs: 45 + autodiscovery: true + kube: + refresh_interval_secs: 10 + dns: + refresh_interval_secs: 20 + cloudwatch: + refresh_interval_secs: 60 + lookback_secs: 1800 + period_secs: 60 + store: + tick_secs: 1 + stale_after_secs: 5 + evict_after_secs: 60 + process_notify_interval_secs: 30 + metrics_retention_secs: 600 + query_history_limit: 500 + autoreload: "immediately" + autoscaling: + pool_size: true + helm: + chart: pgdog + repo: pgdogdev + repo_url: https://helm.pgdog.dev + auth: + cookie_secret: test-cookie-secret + redirect_base_url: https://control.example.com + cookie_secure: true + session_max_age_days: 14 + state_max_age_min: 5 + github: + client_id: github-client + client_secret: github-secret + allowed_orgs: + - pgdogdev + google: + client_id: google-client + client_secret: google-secret + allowed_domains: + - example.com + alerts: + evaluation_window_secs: 120 + thresholds: + clients_waiting: 10 + cpu: 90.0 + memory: 2048 + server_connections: 100 + incident_io: + api_key: incident-token + slack: + bot_token: slack-token + channel: "#alerts" + redis: + url: redis://redis.example.com:6379 + save_interval_secs: 30 diff --git a/values.yaml b/values.yaml index 651757e..a24b032 100644 --- a/values.yaml +++ b/values.yaml @@ -101,9 +101,12 @@ control: # tick_secs: 1 # stale_after_secs: 5 # evict_after_secs: 60 + # process_notify_interval_secs: 60 # metrics_retention_secs: 300 # query_history_limit: 1000 # autoreload: off + autoscaling: {} + # pool_size: false helm: {} # chart: pgdog # repo: pgdogdev