From f5d656464f96b26fbe0792225940aa91caff0bcd Mon Sep 17 00:00:00 2001 From: "David J. M. Karlsen" Date: Sun, 12 Nov 2023 22:50:05 +0100 Subject: [PATCH] Support for pausing migrations (#50) --- api/v1alpha1/migration_types.go | 13 +++++++++++++ internal/controller/migration_controller.go | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/api/v1alpha1/migration_types.go b/api/v1alpha1/migration_types.go index 98fd543..2820285 100644 --- a/api/v1alpha1/migration_types.go +++ b/api/v1alpha1/migration_types.go @@ -18,12 +18,18 @@ package v1alpha1 import ( "fmt" + "strconv" "github.com/samber/lo" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) +const ( + prefix = "flyway-operator.davidkarlsen.com" + paused = prefix + "/" + "paused" +) + // MigrationStatus defines the observed state of Migration type MigrationStatus struct { // +patchMergeKey=type @@ -41,6 +47,13 @@ func (m *Migration) SetConditions(conditions []metav1.Condition) { m.Status.Conditions = conditions } +func (m *Migration) IsPaused() bool { + filtered := lo.PickBy(m.Annotations, func(key, value string) bool { + return key == paused && value == strconv.FormatBool(true) + }) + return len(filtered) > 0 +} + //+kubebuilder:object:root=true //+kubebuilder:subresource:status diff --git a/internal/controller/migration_controller.go b/internal/controller/migration_controller.go index 1d4d025..f94a86c 100644 --- a/internal/controller/migration_controller.go +++ b/internal/controller/migration_controller.go @@ -20,6 +20,7 @@ import ( "context" "errors" "fmt" + flywayv1alpha1 "github.com/davidkarlsen/flyway-operator/api/v1alpha1" "github.com/redhat-cop/operator-utils/pkg/util" "github.com/redhat-cop/operator-utils/pkg/util/crud" @@ -78,6 +79,11 @@ func (r *MigrationReconciler) Reconcile(ctx context.Context, req ctrl.Request) ( return r.ManageError(ctx, migration, err) } + if migration.IsPaused() { + logger.Info("Migration is paused - not creating flyway migration job.") + return r.ManageSuccess(ctx, migration) + } + existingJob, err := r.getExistingJob(ctx, migration) if err != nil { return r.ManageError(ctx, migration, err)