Skip to content

Commit f5d6564

Browse files
authored
Support for pausing migrations (#50)
1 parent 94ba93a commit f5d6564

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

api/v1alpha1/migration_types.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,18 @@ package v1alpha1
1818

1919
import (
2020
"fmt"
21+
"strconv"
2122

2223
"github.com/samber/lo"
2324
v1 "k8s.io/api/core/v1"
2425
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2526
)
2627

28+
const (
29+
prefix = "flyway-operator.davidkarlsen.com"
30+
paused = prefix + "/" + "paused"
31+
)
32+
2733
// MigrationStatus defines the observed state of Migration
2834
type MigrationStatus struct {
2935
// +patchMergeKey=type
@@ -41,6 +47,13 @@ func (m *Migration) SetConditions(conditions []metav1.Condition) {
4147
m.Status.Conditions = conditions
4248
}
4349

50+
func (m *Migration) IsPaused() bool {
51+
filtered := lo.PickBy(m.Annotations, func(key, value string) bool {
52+
return key == paused && value == strconv.FormatBool(true)
53+
})
54+
return len(filtered) > 0
55+
}
56+
4457
//+kubebuilder:object:root=true
4558
//+kubebuilder:subresource:status
4659

internal/controller/migration_controller.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"errors"
2222
"fmt"
23+
2324
flywayv1alpha1 "github.com/davidkarlsen/flyway-operator/api/v1alpha1"
2425
"github.com/redhat-cop/operator-utils/pkg/util"
2526
"github.com/redhat-cop/operator-utils/pkg/util/crud"
@@ -78,6 +79,11 @@ func (r *MigrationReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
7879
return r.ManageError(ctx, migration, err)
7980
}
8081

82+
if migration.IsPaused() {
83+
logger.Info("Migration is paused - not creating flyway migration job.")
84+
return r.ManageSuccess(ctx, migration)
85+
}
86+
8187
existingJob, err := r.getExistingJob(ctx, migration)
8288
if err != nil {
8389
return r.ManageError(ctx, migration, err)

0 commit comments

Comments
 (0)