Skip to content

Commit

Permalink
ddl in config map for apply
Browse files Browse the repository at this point in the history
  • Loading branch information
marccampbell committed Mar 22, 2020
1 parent 5d0d6c2 commit d6bea07
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
24 changes: 21 additions & 3 deletions pkg/controller/migration/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,26 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func getApplyPod(connectionURI string, driver string, database *databasesv1alpha3.Database, table *schemasv1alpha3.Table) (*corev1.Pod, error) {
func getApplyConfigMap(migrationID string, namespace string, preparedStatement string) (*corev1.ConfigMap, error) {
data := make(map[string]string)
data["ddl.sql"] = preparedStatement

configMap := &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: migrationID,
Namespace: namespace,
},
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "ConfigMap",
},
Data: data,
}

return configMap, nil
}

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

Expand All @@ -27,7 +46,6 @@ func getApplyPod(connectionURI string, driver string, database *databasesv1alpha
labels["schemahero-role"] = "apply"

name := fmt.Sprintf("%s-apply", table.Name)
configMapName := table.Name

args := []string{
"apply",
Expand Down Expand Up @@ -73,7 +91,7 @@ func getApplyPod(connectionURI string, driver string, database *databasesv1alpha
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: configMapName,
Name: migrationID,
},
},
},
Expand Down
10 changes: 9 additions & 1 deletion pkg/controller/migration/reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ func (r *ReconcileMigration) reconcileInstance(instance *schemasv1alpha3.Migrati
return reconcile.Result{}, errors.Wrap(err, "failed to get connection uri")
}

pod, err := getApplyPod(connectionURI, instance.Namespace, nil, nil)
configMap, err := getApplyConfigMap(instance.Name, instance.Namespace, instance.Spec.GeneratedDDL)
if err != nil {
return reconcile.Result{}, errors.Wrap(err, "failed to get apply config map")
}
if err := r.Create(context.Background(), configMap); err != nil {
return reconcile.Result{}, errors.Wrap(err, "failed to create config map")
}

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

0 comments on commit d6bea07

Please sign in to comment.