Skip to content

Commit

Permalink
Merge pull request #34 from kloeckner-i/METAL-2096/persist_db_info_in…
Browse files Browse the repository at this point in the history
…_status

[METAL-2096] Save database name and user info in CR status
  • Loading branch information
hyunysmile authored Jul 22, 2020
2 parents e583b53 + e514dfd commit aab4b87
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
2 changes: 2 additions & 0 deletions pkg/apis/kci/v1alpha1/database_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ type DatabaseStatus struct {
InstanceRef *DbInstance `json:"instanceRef"`
MonitorUserSecretName string `json:"monitorUserSecret,omitempty"`
ProxyStatus DatabaseProxyStatus `json:"proxyStatus,omitempty"`
DatabaseName string `json:"database"`
UserName string `json:"user"`
}

// DatabaseProxyStatus defines whether proxy for database is enabled or not
Expand Down
6 changes: 0 additions & 6 deletions pkg/controller/database/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,6 @@ func (r *ReconcileDatabase) Reconcile(request reconcile.Request) (reconcile.Resu
// when database creation failed, don't requeue request. to prevent exceeding api limit (ex: against google api)
return r.manageError(dbcr, err, false)
}
kci.AddFinalizer(&dbcr.ObjectMeta, "db."+dbcr.Name)
err = r.client.Update(context.Background(), dbcr)
if err != nil {
logrus.Errorf("error resource updating - %s", err)
return r.manageError(dbcr, err, true)
}
dbcr.Status.Phase = phaseInstanceAccessSecret
case phaseInstanceAccessSecret:
err := r.createInstanceAccessSecret(dbcr)
Expand Down
23 changes: 12 additions & 11 deletions pkg/controller/database/reconcileDatabase.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ func (r *ReconcileDatabase) createDatabase(dbcr *kciv1alpha1.Database) error {
return err
}

kci.AddFinalizer(&dbcr.ObjectMeta, "db."+dbcr.Name)
err = r.client.Update(context.Background(), dbcr)
if err != nil {
logrus.Errorf("error resource updating - %s", err)
return err
}

dbcr.Status.DatabaseName = databaseCred.Name
dbcr.Status.UserName = databaseCred.Username
logrus.Infof("DB: namespace=%s, name=%s successfully created", dbcr.Namespace, dbcr.Name)
return nil
}
Expand All @@ -124,17 +133,9 @@ func (r *ReconcileDatabase) deleteDatabase(dbcr *kciv1alpha1.Database) error {
return nil
}

// Todo: save database in info and use it for deletion, instead of re-calculating dbname for deletion info
secretData, err := generateDatabaseSecretData(dbcr)
if err != nil {
logrus.Errorf("can not generate credentials for database - %s", err)
return err
}

databaseCred, err := parseDatabaseSecretData(dbcr, secretData)
if err != nil {
// failed to parse database credential from secret
return err
databaseCred := database.Credentials{
Name: dbcr.Status.DatabaseName,
Username: dbcr.Status.UserName,
}

db, err := determinDatabaseType(dbcr, databaseCred)
Expand Down

0 comments on commit aab4b87

Please sign in to comment.