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
1 change: 1 addition & 0 deletions .github/workflows/reviewdog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ jobs:
with:
github_token: ${{ secrets.github_token }}
locale: "US"
ignore: "labelled"
reporter: github-pr-check

alex:
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ check-envtest: get-pgmonitor get-external-snapshotter
$(GO_TEST) -count=1 -cover -tags=envtest ./...

# The "PGO_TEST_TIMEOUT_SCALE" environment variable (default: 1) can be set to a
# positive number that extends test timeouts. The following runs tests with
# positive number that extends test timeouts. The following runs tests with
# timeouts that are 20% longer than normal:
# make check-envtest-existing PGO_TEST_TIMEOUT_SCALE=1.2
.PHONY: check-envtest-existing
Expand All @@ -234,6 +234,10 @@ check-kuttl: ## example command: make check-kuttl KUTTL_TEST='
${KUTTL_TEST} \
--config testing/kuttl/kuttl-test.yaml

.PHONY: test-docker
test-docker: ## Run tests in Docker environment (use TEST_MODE=ci|all|specific, TEST_NAME=<test>, TEST_PACKAGE=<package>)
@./hack/test-docker.sh $(if $(TEST_MODE),-m $(TEST_MODE)) $(if $(TEST_NAME),-t $(TEST_NAME)) $(if $(TEST_PACKAGE),-p $(TEST_PACKAGE)) $(if $(VERBOSE),-v)

.PHONY: generate-kuttl
generate-kuttl: export KUTTL_PG_UPGRADE_FROM_VERSION ?= 15
generate-kuttl: export KUTTL_PG_UPGRADE_TO_VERSION ?= 16
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ This is a fork of the [Percona Operator for PostgreSQL](https://github.com/perco

For our purposes, `flyio-2.6.0` is roughly our main branch.

## Installing/updating on an FKS cluster

Update the image spec on `operator/cw-operator.yaml` to point at a newly built and pushed operator image (see GitHub Actions for the build and push image name).

See [mpg-console](https://github.com/superfly/mpg-console) for the instructions to install/update on an FKS cluster (hint: `mpg operator install`).

# Percona Operator for PostgreSQL

![Percona Kubernetes Operators](kubernetes.svg)
Expand Down
164 changes: 164 additions & 0 deletions TESTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# Testing Guide

This document describes how to run tests for the Percona PostgreSQL Operator locally using the Docker-based testing environment.

## Overview

The operator has several types of tests:

- **CI Tests**: Basic tests that run in CI/CD pipelines
- **Full Test Suite**: Complete test coverage including envtest
- **Specific Tests**: Individual test cases for debugging

All tests can be run locally using Docker to ensure a consistent testing environment.

## Quick Start

### Prerequisites

- Docker installed and running
- Bash shell (macOS/Linux)

### Basic Usage

```bash
# Run CI tests (default)
./test.sh

# Run all tests
./test.sh -m all

# Run a specific test
./test.sh -m specific -t TestReconcilePostgresClusterDataSource

# Show help
./test.sh -h
```

## Detailed Usage

### Test Modes

The test script supports three modes:

1. **All Mode** (`-m all`): Runs the complete test suite with envtest
2. **Specific Mode** (`-m specific`): Runs individual test cases

### Command Line Options

```bash
./test.sh [OPTIONS]

OPTIONS:
-m, --mode MODE Test mode: ci, all, or specific (default: ci)
-t, --test TEST Specific test to run (for specific mode)
-p, --package PACKAGE Specific package to test (default: ./internal/controller/postgrescluster)
-v, --verbose Enable verbose output
-b, --build-only Only build the Docker image, don't run tests
-h, --help Show help message
```

### Examples

```bash
# Run CI tests
./test.sh

# Run full test suite with verbose output
./test.sh -m all -v

# Run specific test in default package
./test.sh -m specific -t TestReconcilePostgresClusterDataSource

# Run specific test in custom package
./test.sh -m specific -t TestSomeFunction -p ./pkg/some/package

# Just build the test environment (useful for debugging)
./test.sh -b

# Run test with verbose output
./test.sh -m specific -t TestReconcilePostgresClusterDataSource -v
```

## Using Make

You can also run tests using Make targets:

```bash
# Run CI tests
make test-docker

# Run all tests
make test-docker TEST_MODE=all

# Run specific test
make test-docker TEST_MODE=specific TEST_NAME=TestReconcilePostgresClusterDataSource

# Run with verbose output
make test-docker TEST_MODE=specific TEST_NAME=TestReconcilePostgresClusterDataSource VERBOSE=1

# Run test in specific package
make test-docker TEST_MODE=specific TEST_NAME=TestSomeTest TEST_PACKAGE=./pkg/some/package
```

## Test Environment

The Docker test environment includes:

- Ubuntu latest base image
- Go 1.24.3
- All required dependencies (build tools, Git, curl, etc.)
- Pre-configured envtest with Kubernetes 1.32
- All necessary Go modules and tools

The environment is built from `Dockerfile.test` and provides:

- Consistent testing environment across different machines
- Isolated test execution

Check warning on line 117 in TESTING.md

View workflow job for this annotation

GitHub Actions / runner / alex

[alex] reported by reviewdog 🐶 Be careful with `execution`, it’s profane in some cases execution retext-profanities Raw Output: 117:17-117:26 warning Be careful with `execution`, it’s profane in some cases execution retext-profanities
- All dependencies pre-installed
- Environment variables properly configured

## Debugging Failed Tests

Check warning on line 121 in TESTING.md

View workflow job for this annotation

GitHub Actions / runner / alex

[alex] reported by reviewdog 🐶 Be careful with `Failed`, it’s profane in some cases failed retext-profanities Raw Output: 121:14-121:20 warning Be careful with `Failed`, it’s profane in some cases failed retext-profanities

When a test fails, you can:

1. **Run with verbose output**:
```bash
./test.sh -m specific -t TestFailingTest -v
```

2. **Build the environment and run interactively**:
```bash
./test.sh -b
docker run --rm -it pgo-test bash
```

3. **Run the test manually inside the container**:
```bash
source <(/workspace/hack/tools/setup-envtest --bin-dir=/workspace/hack/tools/envtest use 1.32 --print=env)
PGO_NAMESPACE='postgres-operator' \
QUERIES_CONFIG_DIR='/workspace/hack/tools/queries' \
CGO_ENABLED=1 go test -v -count=1 -tags=envtest ./internal/controller/postgrescluster -run TestFailingTest
```

## Running Tests Natively (Without Docker)

If you prefer to run tests natively without Docker:

```bash
# Set up envtest
make tools/setup-envtest
make get-pgmonitor get-external-snapshotter

# Run basic tests
make check

# Run tests with envtest
make check-envtest

# Run specific test natively
source <(hack/tools/setup-envtest --bin-dir=hack/tools/envtest use 1.32 --print=env)
PGO_NAMESPACE='postgres-operator' \
QUERIES_CONFIG_DIR='hack/tools/queries' \
CGO_ENABLED=1 go test -v -count=1 -tags=envtest ./internal/controller/postgrescluster -run TestSpecificTest
```
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.1
controller-gen.kubebuilder.io/version: v0.16.5
name: pgupgrades.postgres-operator.crunchydata.com
spec:
group: postgres-operator.crunchydata.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.1
controller-gen.kubebuilder.io/version: v0.16.5
name: postgresclusters.postgres-operator.crunchydata.com
spec:
group: postgres-operator.crunchydata.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.1
controller-gen.kubebuilder.io/version: v0.16.5
name: perconapgbackups.pgv2.percona.com
spec:
group: pgv2.percona.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.1
controller-gen.kubebuilder.io/version: v0.16.5
name: perconapgclusters.pgv2.percona.com
spec:
group: pgv2.percona.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.1
controller-gen.kubebuilder.io/version: v0.16.5
name: perconapgrestores.pgv2.percona.com
spec:
group: pgv2.percona.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.1
controller-gen.kubebuilder.io/version: v0.16.5
name: perconapgupgrades.pgv2.percona.com
spec:
group: pgv2.percona.com
Expand Down
2 changes: 1 addition & 1 deletion config/bundle/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ resources:
images:
- name: postgres-operator
newName: perconalab/percona-postgresql-operator
newTag: flyio-2-6-0-sidecars
newTag: main
8 changes: 4 additions & 4 deletions config/crd/bases/pgv2.percona.com_perconapgclusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.1
controller-gen.kubebuilder.io/version: v0.16.5
name: perconapgbackups.pgv2.percona.com
spec:
group: pgv2.percona.com
Expand Down Expand Up @@ -408,7 +408,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.1
controller-gen.kubebuilder.io/version: v0.16.5
name: perconapgclusters.pgv2.percona.com
spec:
group: pgv2.percona.com
Expand Down Expand Up @@ -20896,7 +20896,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.1
controller-gen.kubebuilder.io/version: v0.16.5
name: perconapgrestores.pgv2.percona.com
spec:
group: pgv2.percona.com
Expand Down Expand Up @@ -20994,7 +20994,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.1
controller-gen.kubebuilder.io/version: v0.16.5
name: perconapgupgrades.pgv2.percona.com
spec:
group: pgv2.percona.com
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.1
controller-gen.kubebuilder.io/version: v0.16.5
labels:
app.kubernetes.io/name: pgo
app.kubernetes.io/version: latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.1
controller-gen.kubebuilder.io/version: v0.16.5
labels:
app.kubernetes.io/name: pgo
app.kubernetes.io/version: latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.1
controller-gen.kubebuilder.io/version: v0.16.5
labels:
app.kubernetes.io/name: pgo
app.kubernetes.io/version: latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.16.1
controller-gen.kubebuilder.io/version: v0.16.5
labels:
app.kubernetes.io/name: pgo
app.kubernetes.io/version: 5.4.2
Expand Down
2 changes: 1 addition & 1 deletion config/cw-bundle/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ resources:
images:
- name: postgres-operator
newName: perconalab/percona-postgresql-operator
newTag: flyio-2-6-0-sidecars
newTag: main
2 changes: 1 addition & 1 deletion config/manager/cluster/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ patchesStrategicMerge:
images:
- name: postgres-operator
newName: perconalab/percona-postgresql-operator
newTag: flyio-2-6-0-sidecars
newTag: main
2 changes: 1 addition & 1 deletion config/manager/namespace/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ patchesStrategicMerge:
images:
- name: postgres-operator
newName: perconalab/percona-postgresql-operator
newTag: flyio-2-6-0-sidecars
newTag: main
Loading
Loading