Skip to content

Commit

Permalink
Merge pull request #141 from schemahero/0.8.0-alpha.2
Browse files Browse the repository at this point in the history
Clean up config map from apply phase
  • Loading branch information
marccampbell committed Apr 5, 2020
2 parents 88c618d + ff2d33e commit d843d2e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pkg/controller/migration/reconcile_pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/schemahero/schemahero/pkg/logger"
"go.uber.org/zap"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)

Expand All @@ -32,6 +33,28 @@ func (r *ReconcileMigration) reconcilePod(ctx context.Context, pod *corev1.Pod)
return reconcile.Result{}, nil
}

// 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
// has an owner ref set to the pod on creation
for _, vol := range pod.Spec.Volumes {
if vol.Name == "input" {
configMapVolumeSource := vol.VolumeSource.ConfigMap
if configMapVolumeSource != nil {
var configMap corev1.ConfigMap
err := r.Get(ctx, types.NamespacedName{
Name: configMapVolumeSource.Name,
Namespace: pod.Namespace,
}, &configMap)
if err == nil {
if err := r.Delete(ctx, &configMap); err != nil {
return reconcile.Result{}, errors.Wrap(err, "failed to delete apply config map")
}
}
}
}
}

// delete it
if err := r.Delete(ctx, pod); err != nil {
return reconcile.Result{}, errors.Wrap(err, "failed to delete apply pod")
Expand Down

0 comments on commit d843d2e

Please sign in to comment.