Skip to content

Commit

Permalink
controllers/migration: remove transient for checksum error (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
datdao authored Nov 17, 2023
1 parent 2aa7416 commit 8931e1f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions controllers/atlasmigration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
14 changes: 14 additions & 0 deletions controllers/atlasmigration_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 8 additions & 0 deletions controllers/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8931e1f

Please sign in to comment.