Repository navigation
Conversation
2ea859e to
ca873e4
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Critical migration defects break custom-CA connectivity, rollback migrations, and legacy adoption, while incomplete validation can accept cross-schema foreign keys and disruptive triggers.
5 open issues
What changed in this PR
Replaces startup GORM AutoMigrate with embedded, versioned PostgreSQL migrations applied by the new results-admin CLI and a release-time Kubernetes Job. The API server and retention agent instead perform read-only schema compatibility checks.
Changes:
- Adds baseline migrations, legacy-schema adoption, structural validation, locking, and recovery commands.
- Integrates migration execution into deployment, image publishing, configuration, and installation.
- Adds PostgreSQL migration coverage, migration-immutability checks in CI, and operational documentation.
This pull request requires changes. Unresolved findings affect custom-CA upgrades, rollback migration Jobs, legacy-schema adoption, and structural validation. Test safety, operational warnings, and documentation also need attention.
Vendored files are listed for completeness; third-party implementations were excluded from code review.
| File | Description |
|---|---|
.github/workflows/presubmit-ci.yaml |
Adds PostgreSQL migration tests and migration-immutability checks. |
AGENTS.md |
Documents schema administration and migration guidance. |
cmd/api/README.md |
Documents the schema-version override. |
cmd/api/main.go |
Checks schema compatibility before starting the API. |
cmd/results-admin/main.go |
Implements database administration commands. |
cmd/results-admin/main_test.go |
Tests CLI validation and connection-string escaping. |
cmd/retention-policy-agent/main.go |
Checks schema compatibility before starting retention. |
config/base/db-migrate.yaml |
Defines the release migration Job. |
config/base/env/config |
Replaces AutoMigrate configuration with the version override. |
config/base/kustomization.yaml |
Includes the migration Job. |
docs/README.md |
Links database migration documentation. |
docs/database-migrations.md |
Documents installation, upgrades, administration, and recovery. |
docs/external-database.md |
Adds migration Job configuration and database-switch procedures. |
docs/install.md |
Explains migration behavior during installation. |
go.mod |
Adds migration dependencies and refreshes indirect dependencies. |
pkg/api/server/config/config.go |
Adds the version override and obsolete-setting warning. |
pkg/api/server/db/migrations/001_baseline.down.sql |
Defines guarded baseline removal. |
pkg/api/server/db/migrations/001_baseline.up.sql |
Defines the established PostgreSQL schema. |
pkg/api/server/db/migrations/README.md |
Documents migration development rules and testing. |
pkg/api/server/db/migrations/admin.go |
Implements retries, locking, adoption, migration, and repair operations. |
pkg/api/server/db/migrations/migrations.go |
Embeds migrations and implements schema compatibility checks. |
pkg/api/server/db/migrations/postgres_test.go |
Tests migration, adoption, drift, dirty-state, and locking behavior. |
pkg/api/server/db/migrations/structure.go |
Validates baseline structure for adoption and diagnostics. |
pkg/api/server/test/db.go |
Centralizes SQLite test-schema creation. |
pkg/api/server/v1alpha2/logs_test.go |
Removes obsolete AutoMigrate configuration from log tests. |
pkg/api/server/v1alpha2/plugin/plugin_logs_test.go |
Removes obsolete AutoMigrate configuration from plugin tests. |
pkg/api/server/v1alpha2/records_test.go |
Uses explicitly initialized test databases. |
pkg/api/server/v1alpha2/results_test.go |
Uses explicitly initialized test databases. |
pkg/api/server/v1alpha2/server.go |
Removes application-startup AutoMigrate. |
pkg/internal/test/clients.go |
Removes obsolete AutoMigrate configuration from test clients. |
tekton/publish.yaml |
Publishes the results-admin image. |
test/e2e/01-install.sh |
Waits for migration completion before application readiness. |
test/e2e/blob-logs/vector-minio-config.yaml |
Removes the obsolete AutoMigrate setting. |
test/e2e/db/README.md |
Marks deployed-schema verification as active. |
test/e2e/db/db_test.go |
Updates comments describing database test coverage. |
test/e2e/db/migrations_test.go |
Verifies deployed schema version and baseline structure. |
test/e2e/db/schema_test.go |
Attributes schema creation to release migrations. |
test/e2e/gcs-emulator.yaml |
Removes the obsolete AutoMigrate setting. |
test/e2e/loki_vector/loki-vector-api-config.yaml |
Removes the obsolete AutoMigrate setting. |
vendor/modules.txt |
Updates the vendored dependency inventory. |
vendor/go.opentelemetry.io/otel/semconv/v1.41.0/rpcconv/metric.go |
Refreshes vendored RPC metric conventions. |
vendor/go.opentelemetry.io/otel/semconv/v1.40.0/schema.go |
Removes the superseded schema declaration. |
vendor/go.opentelemetry.io/otel/semconv/v1.40.0/README.md |
Removes superseded convention documentation. |
vendor/go.opentelemetry.io/otel/semconv/v1.40.0/MIGRATION.md |
Removes superseded convention migration guidance. |
vendor/go.opentelemetry.io/otel/semconv/v1.40.0/exception.go |
Removes superseded exception conventions. |
vendor/go.opentelemetry.io/otel/semconv/v1.40.0/error_type.go |
Removes superseded error-type helpers. |
vendor/go.opentelemetry.io/otel/semconv/v1.40.0/doc.go |
Removes superseded package documentation. |
vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/version.go |
Updates the vendored instrumentation version. |
vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/stats_handler.go |
Refreshes vendored gRPC instrumentation. |
vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/internal/parse.go |
Updates semantic-convention references. |
vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/interceptor.go |
Updates semantic-convention imports. |
vendor/go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc/config.go |
Refreshes vendored instrumentation configuration. |
vendor/github.com/jackc/pgerrcode/README.md |
Adds PostgreSQL error-code package documentation. |
vendor/github.com/jackc/pgerrcode/LICENSE |
Adds dependency licensing. |
vendor/github.com/jackc/pgerrcode/gen.rb |
Includes PostgreSQL error-code generation tooling. |
vendor/github.com/golang-migrate/migrate/v4/util.go |
Adds migration-library utilities. |
vendor/github.com/golang-migrate/migrate/v4/source/parse.go |
Adds migration-filename parsing. |
vendor/github.com/golang-migrate/migrate/v4/source/migration.go |
Adds migration-source indexing. |
vendor/github.com/golang-migrate/migrate/v4/source/iofs/README.md |
Adds embedded-filesystem driver documentation. |
vendor/github.com/golang-migrate/migrate/v4/source/iofs/iofs.go |
Adds embedded-filesystem migration loading. |
vendor/github.com/golang-migrate/migrate/v4/source/iofs/doc.go |
Adds filesystem-driver package documentation. |
vendor/github.com/golang-migrate/migrate/v4/source/errors.go |
Adds migration-source errors. |
vendor/github.com/golang-migrate/migrate/v4/source/driver.go |
Adds migration-source interfaces. |
vendor/github.com/golang-migrate/migrate/v4/SECURITY.md |
Includes upstream security guidance. |
vendor/github.com/golang-migrate/migrate/v4/README.md |
Includes migration-library documentation. |
vendor/github.com/golang-migrate/migrate/v4/MIGRATIONS.md |
Includes migration-format guidance. |
vendor/github.com/golang-migrate/migrate/v4/migration.go |
Adds migration representation and buffering. |
vendor/github.com/golang-migrate/migrate/v4/Makefile |
Includes upstream build tooling. |
vendor/github.com/golang-migrate/migrate/v4/log.go |
Adds the migration logging interface. |
vendor/github.com/golang-migrate/migrate/v4/LICENSE |
Adds migration-library licensing. |
vendor/github.com/golang-migrate/migrate/v4/internal/url/url.go |
Adds migration URL utilities. |
vendor/github.com/golang-migrate/migrate/v4/GETTING_STARTED.md |
Includes dependency setup guidance. |
vendor/github.com/golang-migrate/migrate/v4/FAQ.md |
Includes migration reference documentation. |
vendor/github.com/golang-migrate/migrate/v4/Dockerfile.github-actions |
Includes upstream Actions container packaging. |
vendor/github.com/golang-migrate/migrate/v4/Dockerfile.circleci |
Includes upstream CI container packaging. |
vendor/github.com/golang-migrate/migrate/v4/Dockerfile |
Includes upstream container packaging. |
vendor/github.com/golang-migrate/migrate/v4/docker-deploy.sh |
Includes upstream image-publishing tooling. |
vendor/github.com/golang-migrate/migrate/v4/database/util.go |
Adds database-driver locking utilities. |
vendor/github.com/golang-migrate/migrate/v4/database/pgx/v5/README.md |
Documents the PostgreSQL migration driver. |
vendor/github.com/golang-migrate/migrate/v4/database/multistmt/parse.go |
Adds SQL statement parsing. |
vendor/github.com/golang-migrate/migrate/v4/database/error.go |
Adds migration database errors. |
vendor/github.com/golang-migrate/migrate/v4/database/driver.go |
Adds migration database-driver interfaces. |
vendor/github.com/golang-migrate/migrate/v4/CONTRIBUTING.md |
Includes upstream contributor documentation. |
vendor/github.com/golang-migrate/migrate/v4/.goreleaser.yml |
Includes upstream release configuration. |
vendor/github.com/golang-migrate/migrate/v4/.golangci.yml |
Includes upstream lint configuration. |
vendor/github.com/golang-migrate/migrate/v4/.gitignore |
Includes upstream repository ignore rules. |
vendor/github.com/golang-migrate/migrate/v4/.dockerignore |
Includes upstream container ignore rules. |
vendor/github.com/felixge/httpsnoop/wrap_generated_lt_1.8.go |
Removes an obsolete generated HTTP wrapper. |
vendor/github.com/felixge/httpsnoop/wrap_generated_gteq_1.8.go |
Removes a superseded generated HTTP wrapper. |
vendor/github.com/felixge/httpsnoop/capture_metrics.go |
Refreshes vendored HTTP metric capture. |
Review effort: Max
| volumeMounts: | ||
| - name: config | ||
| mountPath: /etc/tekton/results | ||
| readOnly: true |
| if s.Dirty { | ||
| return fmt.Errorf("schema version %d is dirty: a migration failed or is still running; repair it before migrating", s.Version) | ||
| } | ||
| if target != 0 && target < uint(s.Version) { //nolint:gosec // migration versions are small | ||
| return fmt.Errorf("target version %d is below current version %d; downgrades are not supported", target, s.Version) | ||
| } |
| CASE k.confdeltype WHEN 'c' THEN 'CASCADE' ELSE k.confdeltype::text END) | ||
| FROM pg_constraint k | ||
| JOIN pg_class c ON c.oid = k.conrelid | ||
| LEFT JOIN pg_class rc ON rc.oid = k.confrelid |
| if kind == "f" && definition == baselineForeignKey && validated && !foreignKey { | ||
| foreignKey = true | ||
| return nil | ||
| } | ||
| diff("constraint %s on %s: unexpected (type %s, validated %t)", name, table, kind, validated) |
| diff("missing foreign key %s", baselineForeignKey) | ||
| } | ||
|
|
||
| if len(diffs) == 0 { |
|
@olegbet: changing LGTM is restricted to collaborators DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: olegbet The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Replace GORM AutoMigrate on API server startup with versioned SQL migrations managed by golang-migrate and applied by a dedicated results-admin command, run as a Kubernetes Job in each release. Schema versioning: - Embed the migrations in pkg/api/server/db/migrations. 001_baseline creates the established results and records schema. - Record the schema version and dirty flag in schema_migrations. - Declare compatibility with a single RequiredSchemaVersion constant. A process starts when the effective schema version (the recorded version, or one less while it is dirty) is at or above it. Migrations are additive, so several releases can share a schema, rollback needs no downgrade, and a pod restarting during a long migration still starts. - The API server and retention policy agent run a read-only check at startup and exit with an actionable message when it fails. There is no structural validation at startup. - DB_SCHEMA_REQUIRED_VERSION_OVERRIDE deliberately replaces the required version, with a warning on every start. results-admin: - New binary and image with status, check [--structural], migrate-up, migrate-to and force --repaired commands, using an advisory lock and bounded connect, lock and statement timeouts. - migrate-up adopts a database created by GORM AutoMigrate after verifying that its tables match the baseline exactly, and fails with the list of differences otherwise. Upgrading needs no manual step. - --wait-for-database retries while the database is not reachable yet and re-reads the configuration before each retry. Deployment: - Add the tekton-results-db-migrate Job to the release. It waits up to 10 minutes for the database and is removed 6 hours after finishing. - Remove DB_ENABLE_AUTO_MIGRATION; it is ignored with a warning. - Publish the results-admin image and wait for the Job in the e2e install script. Tests and CI: - Unit tests for the embedded migrations, compatibility rule, CLI and connection retries; PostgreSQL tests (build tag e2e) for migration, adoption, drift, dirty state, force and lock timeouts. - New db-migrations presubmit job runs the PostgreSQL tests and rejects changes to published migration files. Docs: add docs/database-migrations.md and update the install, external database and API configuration docs. Signed-off-by: Emil Natan <ena@redhat.com> Assisted-by: GitHub Copilot CLI (Claude Opus 5.5) <noreply@anthropic.com>
ca873e4 to
d943aad
Compare

Replace GORM AutoMigrate on API server startup with versioned SQL migrations managed by golang-migrate and applied by a dedicated results-admin command, run as a Kubernetes Job in each release.
Schema versioning:
results-admin:
Deployment:
Tests and CI:
Docs: add docs/database-migrations.md and update the install, external database and API configuration docs.
Assisted-by: GitHub Copilot CLI (Claude Opus 5.5) noreply@anthropic.com
Changes
/kind feature
Submitter Checklist
These are the criteria that every PR should meet, please check them off as you review them:
/kind <type>. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tepRelease Notes