From 8931e1fbb00b189ac4af61395240175e51bb517e Mon Sep 17 00:00:00 2001 From: "Dat. Ba Dao" Date: Fri, 17 Nov 2023 23:25:50 +0700 Subject: [PATCH] controllers/migration: remove transient for checksum error (#103) --- controllers/atlasmigration_controller.go | 3 +++ controllers/atlasmigration_controller_test.go | 14 ++++++++++++++ controllers/common.go | 8 ++++++++ 3 files changed, 25 insertions(+) diff --git a/controllers/atlasmigration_controller.go b/controllers/atlasmigration_controller.go index e3611f24..3bbfb29a 100644 --- a/controllers/atlasmigration_controller.go +++ b/controllers/atlasmigration_controller.go @@ -225,6 +225,9 @@ func (r *AtlasMigrationReconciler) reconcile(ctx context.Context, dir, envName s // Check if there are any pending migration files status, err := c.MigrateStatus(ctx, &atlas.MigrateStatusParams{Env: envName}) if err != nil { + if isChecksumErr(err) { + return nil, err + } return nil, transient(err) } if len(status.Pending) == 0 { diff --git a/controllers/atlasmigration_controller_test.go b/controllers/atlasmigration_controller_test.go index bf183559..864f0ab7 100644 --- a/controllers/atlasmigration_controller_test.go +++ b/controllers/atlasmigration_controller_test.go @@ -365,6 +365,20 @@ func TestReconcile_Transient(t *testing.T) { }, tt.events()) } +func TestReconcile_InvalidChecksum(t *testing.T) { + tt := migrationCliTest(t) + am := tt.getAtlasMigration() + am.Spec.Dir.Local = map[string]string{ + "1.sql": "foo", + "atlas.sum": `invalid checksum`, + } + tt.k8s.put(am) + result, err := tt.r.Reconcile(context.Background(), migrationReq()) + require.NoError(t, err) + require.EqualValues(t, reconcile.Result{}, result) + require.Contains(t, am.Status.Conditions[0].Message, "checksum mismatch") +} + func TestReconcile_reconcile(t *testing.T) { tt := migrationCliTest(t) tt.initDefaultMigrationDir() diff --git a/controllers/common.go b/controllers/common.go index b2e71e83..191b4cb6 100644 --- a/controllers/common.go +++ b/controllers/common.go @@ -113,6 +113,14 @@ func isSQLErr(err error) bool { return strings.Contains(err.Error(), "sql/migrate: execute: executing statement") } +// isChecksumErr returns true if the error is a checksum error. +func isChecksumErr(err error) bool { + if err == nil { + return false + } + return strings.Contains(err.Error(), "checksum mismatch") +} + // transientError is an error that should be retried. type transientError struct { err error