Skip to content

Commit

Permalink
Support for pausing migrations (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkarlsen authored Nov 12, 2023
1 parent 94ba93a commit f5d6564
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
13 changes: 13 additions & 0 deletions api/v1alpha1/migration_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
6 changes: 6 additions & 0 deletions internal/controller/migration_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f5d6564

Please sign in to comment.