fix: MariaDB compatibility for JSON queries and native password auth. Fixes #15413#15936
Conversation
e3fd6fc to
7007a62
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this comment.
Claude Code review
Found 9 issues:
- Container-leak risk in test setup helpers — both
setupMySQLArchiveTestandsetupMySQLContainerstart a testcontainers container, then callrequire.NoErroron several subsequent steps. If any of those fail, the container is never terminated because the cleanup closure is only invoked once the caller defers it. Should registert.Cleanup(func() { testcontainers.TerminateContainer(c) })immediately after container start. (bug — resource leak)
argo-workflows/persist/sqldb/workflow_archive_mysql_test.go
Lines 36 to 81 in 7007a62
argo-workflows/util/sqldb/sqldb_test.go
Lines 29 to 61 in 7007a62
- Test scaffolding duplicated verbatim across two new files —
mysqlVariantstruct,mysqlVariantsmap, and most of the container-bootstrap code are copy-pasted between the two new test files. Image tags, wait-log strings, and setup behaviour will drift independently. Extract to a shared test helper. (DRY / maintainability)
argo-workflows/persist/sqldb/workflow_archive_mysql_test.go
Lines 24 to 50 in 7007a62
argo-workflows/util/sqldb/sqldb_test.go
Lines 17 to 42 in 7007a62
//nolint:errchecksilently swallowsTerminateContainererrors — the existing pattern inworkflow/sync/database_helper_test.gologs the termination error viat.Logf. The new code swallows it entirely, which will mask container leaks in CI. (inconsistent with repo convention)
argo-workflows/util/sqldb/sqldb_test.go
Lines 58 to 62 in 7007a62
- Test assertions cover only 3 of 8 changed JSON expressions — the PR's primary fix is 8
JSON_EXTRACT/JSON_UNQUOTEexpressions.TestMySQLListWorkflowsasserts onlyProgress,Message, and one label.Annotations,Arguments,Suspend,EstimatedDuration, andResourcesDurationare never asserted.Arguments.Parameters[msg=hello]is set in the test input but never validated on the way back. A bug in any of those extractions would not be caught. (test coverage)
argo-workflows/persist/sqldb/workflow_archive_mysql_test.go
Lines 127 to 137 in 7007a62
require.Equal(t, MySQL, dbType)is tautological —CreateDBSessionWithCredsreturnsMySQLwhenevercfg.MySQL != nil; the assertion checks a Go branch, not a property of the MariaDB connection. It does not differentiate MySQL from MariaDB in any way. (ineffective assertion)
argo-workflows/util/sqldb/sqldb_test.go
Lines 73 to 84 in 7007a62
- Misleading
archive-strategylabel in test input — the test setsworkflows.argoproj.io/archive-strategy: Persistedon the input workflow, butArchiveWorkflowunconditionally overwrites the archiving-status label before persisting. The input value has no bearing on what gets stored or retrieved. (misleading test fixture)
argo-workflows/persist/sqldb/workflow_archive_mysql_test.go
Lines 100 to 110 in 7007a62
AllowNativePasswords: truehas no inline comment — the rationale (MariaDB defaults tomysql_native_password, go-sql-driver v1.9 changed the zero-value default tofalsewhen using the struct literal) is non-obvious and lives only in the PR description. A future refactor is likely to "clean it up". Add a brief comment. (maintainability)
argo-workflows/util/sqldb/sqldb.go
Lines 196 to 210 in 7007a62
- Windows skip uses runtime check instead of
//go:build !windowsbuild tag — commit 7674c7f just standardised testcontainers tests on the build-tag pattern. These new files revert to the older runtime check, inconsistent with the freshly-established convention (and still compiles the testcontainers import on Windows). (consistency)
argo-workflows/persist/sqldb/workflow_archive_mysql_test.go
Lines 84 to 92 in 7007a62
argo-workflows/util/sqldb/sqldb_test.go
Lines 64 to 72 in 7007a62
- Other docs still advertise only MySQL — the
AllowNativePasswordsfix inutil/sqldb/sqldb.goapplies to all MySQL connections, so offloading/synchronization features also now work with MariaDB.docs/memoization.md,docs/offloading-large-workflows.md,docs/synchronization.md, anddocs/synchronization-config.mdstill say "PostgreSQL or MySQL" without mentioning MariaDB. (docs scope)
argo-workflows/docs/workflow-archive.md
Lines 1 to 8 in 7007a62
🤖 Generated with Claude Code
- If this code review was useful, please react with 👍. Otherwise, react with 👎.
📝 WalkthroughWalkthroughThese changes add MariaDB (>= 10.2) support to Argo Workflows by updating JSON query syntax in archived workflow queries from PostgreSQL-style operators to MySQL-compatible equivalents, configuring MySQL DSN settings, and adding integration tests for MySQL and MariaDB database connectivity. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (4)
persist/sqldb/workflow_archive_mysql_test.go (3)
26-34: Minor:mysqlVariant/mysqlVariantsduplicated across packages.The same struct and map are defined verbatim in
util/sqldb/sqldb_test.go. Consider promoting them to a shared internal test helper package (e.g.util/sqldb/sqldbtest) to avoid drift when a new variant or wait-message is added.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@persist/sqldb/workflow_archive_mysql_test.go` around lines 26 - 34, The definitions of mysqlVariant and mysqlVariants are duplicated across tests; extract these into a shared internal test helper (e.g., a package like sqldbtest) and import it from both places. Create a single exported variable or function in the helper that returns the map (e.g., sqldbtest.MySQLVariants or sqldbtest.NewMySQLVariants()), replace the local mysqlVariant type/map usages in workflow_archive_mysql_test.go and util/sqldb/sqldb_test.go with references to that helper, and update imports accordingly so both tests consume the single source of truth.
108-134: Extend coverage: exerciseSpec.Suspendround-trip.
Spec.Suspendis explicitly projected by the MySQL branch ofListWorkflowsbut this test leaves it unset and doesn't assert on it after listing. Adding a booleanSuspendto the archived workflow and assertingwf.Spec.Suspendon the returned item would guard the projection (see the critical comment onworkflow_archive.goline 190).🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@persist/sqldb/workflow_archive_mysql_test.go` around lines 108 - 134, The test omits exercising the Spec.Suspend round-trip that the MySQL ListWorkflows projection handles; update the archived workflow creation in the test to set Spec.Suspend (e.g., true) and after calling archive.ListWorkflows assert that the returned wf.Spec.Suspend matches the value you set; this ensures the projection in ListWorkflows correctly preserves Spec.Suspend (referencing Spec.Suspend and ListWorkflows/workflow_archive projection).
85-94: Gate testcontainer-based tests behind a build tag or env flag.This test starts real MySQL and MariaDB containers, so every
go test ./persist/sqldb/...run on a developer machine without Docker (or without network access to pull the images) will fail rather than skip. Consider gating with a build tag (e.g.//go:build mysqlat the top of the file) or an env-var check so the standard unit-test run stays hermetic while CI can opt in explicitly.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@persist/sqldb/workflow_archive_mysql_test.go` around lines 85 - 94, The test TestMySQLListWorkflows (which iterates mysqlVariants and calls setupMySQLArchiveTest) runs real containerized MySQL/MariaDB and should be gated; update the file to either add a build tag (e.g. //go:build mysql) at the top or add an env-check at the start of TestMySQLListWorkflows that skips the test unless an opt-in env var (e.g. RUN_MYSQL_INTEGRATION=true) is set, so normal `go test` runs skip these container-backed tests while CI can enable them explicitly.persist/sqldb/workflow_archive.go (1)
187-194: Nit: inconsistentJSON_UNQUOTEusage for object-valued fields.
labels,annotations, andresourcesDurationare extracted with bareJSON_EXTRACT, butarguments— also a JSON object — additionally goes throughJSON_UNQUOTE. WhileJSON_UNQUOTEon JSON objects simply returns the JSON text unchanged and does not modify nested escape sequences, using it here is semantically redundant and inconsistent with the other object fields. For consistency and clarity, treatspec.argumentsthe same way asmetadata.labels/metadata.annotations.♻️ Proposed change
- db.Raw("coalesce(JSON_UNQUOTE(JSON_EXTRACT(workflow, '$.spec.arguments')), '{}') as arguments"), + db.Raw("coalesce(JSON_EXTRACT(workflow, '$.spec.arguments'), '{}') as arguments"),🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@persist/sqldb/workflow_archive.go` around lines 187 - 194, The extraction of spec.arguments is inconsistent: it uses JSON_UNQUOTE while other object-valued fields (labels, annotations, resourcesDuration) use JSON_EXTRACT. Update the db.Raw call that produces "arguments" in workflow_archive.go to mirror the other object fields by removing JSON_UNQUOTE and using coalesce(JSON_EXTRACT(workflow, '$.spec.arguments'), '{}') as arguments so the handling is consistent with labels, annotations, and resourcesduration.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@persist/sqldb/workflow_archive.go`:
- Line 190: The MySQL/MariaDB raw select for the suspend value is missing an
alias so archivedWorkflowMetadata.Suspend never gets populated; update the
db.Raw call that currently uses JSON_UNQUOTE(JSON_EXTRACT(workflow,
'$.spec.suspend')) to include "AS suspend" (matching the Postgres branch) so
GORM/upper can map to the suspend field, and add/extend TestMySQLListWorkflows
to archive a workflow with Spec.Suspend set and assert it round-trips via
ListWorkflows to catch regressions.
---
Nitpick comments:
In `@persist/sqldb/workflow_archive_mysql_test.go`:
- Around line 26-34: The definitions of mysqlVariant and mysqlVariants are
duplicated across tests; extract these into a shared internal test helper (e.g.,
a package like sqldbtest) and import it from both places. Create a single
exported variable or function in the helper that returns the map (e.g.,
sqldbtest.MySQLVariants or sqldbtest.NewMySQLVariants()), replace the local
mysqlVariant type/map usages in workflow_archive_mysql_test.go and
util/sqldb/sqldb_test.go with references to that helper, and update imports
accordingly so both tests consume the single source of truth.
- Around line 108-134: The test omits exercising the Spec.Suspend round-trip
that the MySQL ListWorkflows projection handles; update the archived workflow
creation in the test to set Spec.Suspend (e.g., true) and after calling
archive.ListWorkflows assert that the returned wf.Spec.Suspend matches the value
you set; this ensures the projection in ListWorkflows correctly preserves
Spec.Suspend (referencing Spec.Suspend and ListWorkflows/workflow_archive
projection).
- Around line 85-94: The test TestMySQLListWorkflows (which iterates
mysqlVariants and calls setupMySQLArchiveTest) runs real containerized
MySQL/MariaDB and should be gated; update the file to either add a build tag
(e.g. //go:build mysql) at the top or add an env-check at the start of
TestMySQLListWorkflows that skips the test unless an opt-in env var (e.g.
RUN_MYSQL_INTEGRATION=true) is set, so normal `go test` runs skip these
container-backed tests while CI can enable them explicitly.
In `@persist/sqldb/workflow_archive.go`:
- Around line 187-194: The extraction of spec.arguments is inconsistent: it uses
JSON_UNQUOTE while other object-valued fields (labels, annotations,
resourcesDuration) use JSON_EXTRACT. Update the db.Raw call that produces
"arguments" in workflow_archive.go to mirror the other object fields by removing
JSON_UNQUOTE and using coalesce(JSON_EXTRACT(workflow, '$.spec.arguments'),
'{}') as arguments so the handling is consistent with labels, annotations, and
resourcesduration.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 47f9ed73-795b-4c57-986e-154ed711bd60
📒 Files selected for processing (6)
.spellingdocs/workflow-archive.mdpersist/sqldb/workflow_archive.gopersist/sqldb/workflow_archive_mysql_test.goutil/sqldb/sqldb.goutil/sqldb/sqldb_test.go
b0747c0 to
35e5b12
Compare
|
Thanks for the review. All feedback addressed in the latest push:
All tests pass locally against MySQL 8.4 and MariaDB 11.4. |
8e4647b to
a80e0fe
Compare
a80e0fe to
33a3128
Compare
…tibility. Fixes argoproj#15413 Signed-off-by: Mario Apostolov <mario.apostolov@mariadb.com>
…goproj#15413 Signed-off-by: Mario Apostolov <mario.apostolov@mariadb.com>
…edback Signed-off-by: Mario Apostolov <mario.apostolov@mariadb.com>
33a3128 to
7d41175
Compare
Fixes #15413
Motivation
The MySQL branch of ListWorkflows uses
->and->>JSON operators which are not supported by MariaDB, causing SQL syntax errors when listing archived workflows.Additionally,
go-sql-driver/mysqlv1.9.x changed the default ofAllowNativePasswordstofalse, which prevents connections to MariaDB since it usesmysql_native_passwordby default.Modifications
JSON_EXTRACT()/JSON_UNQUOTE()instead of->/->>in the MySQL branch of ListWorkflows (compatible with MySQL 5.7+ and MariaDB 10.2+)AllowNativePasswords: truein the MySQL driver configVerification
Ran
goimports,go vet, and the full test suites for the affected packages. All existing and new tests pass. No regressions.Documentation
Updated docs/workflow-archive.md to include MariaDB (>= 10.2) as a supported database.
Summary by CodeRabbit
Release Notes
New Features
Documentation
Improvements