Skip to content

Commit

Permalink
Update the migration with the executed at timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
marccampbell committed Apr 7, 2020
1 parent 5234883 commit 705ed7e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/controller/migration/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func getApplyPod(migrationID string, namespace string, connectionURI string, dat
}

labels := make(map[string]string)
labels["schemahero-name"] = table.Name
labels["schemahero-name"] = migrationID
labels["schemahero-namespace"] = table.Namespace
labels["schemahero-role"] = "apply"

Expand Down
22 changes: 22 additions & 0 deletions pkg/controller/migration/reconcile_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package migration

import (
"context"
"time"

"github.com/pkg/errors"
schemasv1alpha3 "github.com/schemahero/schemahero/pkg/apis/schemas/v1alpha3"
"github.com/schemahero/schemahero/pkg/logger"
"go.uber.org/zap"
corev1 "k8s.io/api/core/v1"
Expand All @@ -18,6 +20,11 @@ func (r *ReconcileMigration) reconcilePod(ctx context.Context, pod *corev1.Pod)
return reconcile.Result{}, nil
}

migrationID, ok := podLabels["schemahero-name"]
if !ok {
return reconcile.Result{}, nil
}

if role != "" && role != "apply" {
// make sure we are filtering to relevant events
return reconcile.Result{}, nil
Expand All @@ -33,6 +40,21 @@ func (r *ReconcileMigration) reconcilePod(ctx context.Context, pod *corev1.Pod)
return reconcile.Result{}, nil
}

// the migration has completed
// so lets store the executed at timestamp on the status
var instance schemasv1alpha3.Migration
err := r.Get(ctx, types.NamespacedName{
Name: migrationID,
Namespace: pod.Namespace,
}, &instance)
if err != nil {
return reconcile.Result{}, errors.Wrap(err, "failed to get migration")
}
instance.Status.ExecutedAt = time.Now().Unix()
if err := r.Update(ctx, &instance); err != nil {
return reconcile.Result{}, errors.Wrap(err, "failed to update migration")
}

// delete related configmaps
// we don't have owner refs on this because we create them in the wrong order
// it would be better and more reliable to change this so that the config map
Expand Down

0 comments on commit 705ed7e

Please sign in to comment.