Skip to content

Commit

Permalink
Working on commit
Browse files Browse the repository at this point in the history
  • Loading branch information
marccampbell committed Mar 22, 2020
1 parent d47cccc commit 5d0d6c2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
25 changes: 1 addition & 24 deletions pkg/controller/migration/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@ package migration
import (
"fmt"

"github.com/pkg/errors"
databasesv1alpha3 "github.com/schemahero/schemahero/pkg/apis/databases/v1alpha3"
schemasv1alpha3 "github.com/schemahero/schemahero/pkg/apis/schemas/v1alpha3"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func (r *ReconcileMigration) applyPod(database *databasesv1alpha3.Database, table *schemasv1alpha3.Table) (*corev1.Pod, error) {
func getApplyPod(connectionURI string, driver string, database *databasesv1alpha3.Database, table *schemasv1alpha3.Table) (*corev1.Pod, error) {
imageName := "schemahero/schemahero:alpha"
nodeSelector := make(map[string]string)
driver := ""
connectionURI := ""

if database.Spec.SchemaHero != nil {
if database.Spec.SchemaHero.Image != "" {
Expand All @@ -24,26 +21,6 @@ func (r *ReconcileMigration) applyPod(database *databasesv1alpha3.Database, tabl
nodeSelector = database.Spec.SchemaHero.NodeSelector
}

if database.Spec.Connection.Postgres != nil {
driver = "postgres"
uri, err := r.readConnectionURI(database.Namespace, database.Spec.Connection.Postgres.URI)
if err != nil {
return nil, errors.Wrap(err, "failed to read postgres connection uri")
}
connectionURI = uri
} else if database.Spec.Connection.Mysql != nil {
driver = "mysql"
uri, err := r.readConnectionURI(database.Namespace, database.Spec.Connection.Mysql.URI)
if err != nil {
return nil, errors.Wrap(err, "failed to read mysql connection uri")
}
connectionURI = uri
}

if driver == "" {
return nil, errors.New("unknown database driver")
}

labels := make(map[string]string)
labels["schemahero-name"] = table.Name
labels["schemahero-namespace"] = table.Namespace
Expand Down
21 changes: 21 additions & 0 deletions pkg/controller/migration/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package migration
import (
"context"

"github.com/pkg/errors"
"github.com/schemahero/schemahero/pkg/apis/databases/v1alpha3"
schemasv1alpha3 "github.com/schemahero/schemahero/pkg/apis/schemas/v1alpha3"
"github.com/schemahero/schemahero/pkg/logger"
"go.uber.org/zap"
Expand All @@ -26,6 +28,25 @@ func (r *ReconcileMigration) reconcileInstance(instance *schemasv1alpha3.Migrati
zap.String("name", instance.Name),
zap.String("tableName", instance.Spec.TableName))

if instance.Status.ApprovedAt > 0 && instance.Status.ExecutedAt == 0 {
// TODO incomplete code
connectionURI, err := r.readConnectionURI(instance.Name, v1alpha3.ValueOrValueFrom{})
if err != nil {
return reconcile.Result{}, errors.Wrap(err, "failed to get connection uri")
}

pod, err := getApplyPod(connectionURI, instance.Namespace, nil, nil)
if err != nil {
return reconcile.Result{}, errors.Wrap(err, "failed to get apply pod")
}

if err := r.Create(context.Background(), pod); err != nil {
return reconcile.Result{}, errors.Wrap(err, "failed to create apply pod")
}

return reconcile.Result{}, nil
}

return reconcile.Result{}, nil
}

Expand Down

0 comments on commit 5d0d6c2

Please sign in to comment.