Skip to content

Commit

Permalink
Migration resource is created
Browse files Browse the repository at this point in the history
  • Loading branch information
marccampbell committed Jan 19, 2020
1 parent 48005dd commit b00a390
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
4 changes: 0 additions & 4 deletions pkg/controller/migration/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
schemasv1alpha3 "github.com/schemahero/schemahero/pkg/apis/schemas/v1alpha3"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
)

func (r *ReconcileMigration) applyPod(database *databasesv1alpha3.Database, table *schemasv1alpha3.Table) (*corev1.Pod, error) {
Expand Down Expand Up @@ -105,9 +104,6 @@ func (r *ReconcileMigration) applyPod(database *databasesv1alpha3.Database, tabl
},
},
}
if err := controllerutil.SetControllerReference(table, pod, r.scheme); err != nil {
return nil, errors.Wrap(err, "failed to set controller ref")
}

return pod, nil
}
4 changes: 0 additions & 4 deletions pkg/controller/table/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
kuberneteserrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
)

func (r *ReconcileTable) planConfigMap(database *databasesv1alpha3.Database, table *schemasv1alpha3.Table) (*corev1.ConfigMap, error) {
Expand Down Expand Up @@ -134,9 +133,6 @@ func (r *ReconcileTable) planPod(database *databasesv1alpha3.Database, table *sc
},
},
}
if err := controllerutil.SetControllerReference(table, pod, r.scheme); err != nil {
return nil, errors.Wrap(err, "failed to set controller ref")
}

return pod, nil
}
Expand Down
25 changes: 19 additions & 6 deletions pkg/controller/table/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes"
"sigs.k8s.io/controller-runtime/pkg/client/config"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/reconcile"
)

Expand Down Expand Up @@ -129,13 +128,31 @@ func (r *ReconcileTable) reconcilePod(pod *corev1.Pod) (reconcile.Result, error)

// Delete the pod and config map
if err := r.Delete(context.Background(), pod); err != nil {
return reconcile.Result{}, err
return reconcile.Result{}, errors.Wrap(err, "failed to delete pod from plan phase")
}

configMapName := ""
for _, volume := range pod.Spec.Volumes {
if volume.Name == "specs" && volume.ConfigMap != nil {
configMapName = volume.ConfigMap.Name
}
}
configMap := corev1.ConfigMap{}
err = r.Get(context.Background(), types.NamespacedName{Name: configMapName, Namespace: pod.Namespace}, &configMap)
if err != nil {
return reconcile.Result{}, errors.Wrap(err, "failed to get config map from plan phase")
}

if err := r.Delete(context.Background(), &configMap); err != nil {
return reconcile.Result{}, errors.Wrap(err, "failed to delete config map from plan phase")
}

return reconcile.Result{}, nil
}

func (r *ReconcileTable) plan(database *databasesv1alpha3.Database, table *schemasv1alpha3.Table) error {
logger.Debug("deploying plan")

configMap, err := r.planConfigMap(database, table)
if err != nil {
return errors.Wrap(err, "failed to get config map object for plan")
Expand All @@ -145,10 +162,6 @@ func (r *ReconcileTable) plan(database *databasesv1alpha3.Database, table *schem
return errors.Wrap(err, "failed to get pod for plan")
}

if err := controllerutil.SetControllerReference(pod, configMap, r.scheme); err != nil {
return errors.Wrap(err, "failed to set controller reference")
}

if err := r.ensureTableConfigMap(configMap); err != nil {
return errors.Wrap(err, "failed to create config map for plan")
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/table/table_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package table

import (
"context"
"fmt"
"time"

"github.com/pkg/errors"
Expand Down Expand Up @@ -103,6 +104,7 @@ type ReconcileTable struct {
func (r *ReconcileTable) Reconcile(request reconcile.Request) (reconcile.Result, error) {
instance, instanceErr := r.getInstance(request)
if instanceErr == nil {
fmt.Printf("instance\n")
result, err := r.reconcileInstance(instance)
if err != nil {
logger.Error(err)
Expand Down

0 comments on commit b00a390

Please sign in to comment.