Skip to content

Commit e382069

Browse files
authored
Merge pull request openstack-k8s-operators#373 from stuggi/db_order
Create database before config rendering
2 parents a2e8f61 + 71f71e9 commit e382069

File tree

2 files changed

+219
-200
lines changed

2 files changed

+219
-200
lines changed

controllers/keystoneapi_controller.go

Lines changed: 63 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -462,65 +462,6 @@ func (r *KeystoneAPIReconciler) reconcileInit(
462462
return rbacResult, nil
463463
}
464464

465-
//
466-
// create service DB instance
467-
//
468-
db := mariadbv1.NewDatabase(
469-
instance.Name,
470-
instance.Spec.DatabaseUser,
471-
instance.Spec.Secret,
472-
map[string]string{
473-
"dbName": instance.Spec.DatabaseInstance,
474-
},
475-
)
476-
// create or patch the DB
477-
ctrlResult, err := db.CreateOrPatchDB(
478-
ctx,
479-
helper,
480-
)
481-
if err != nil {
482-
instance.Status.Conditions.Set(condition.FalseCondition(
483-
condition.DBReadyCondition,
484-
condition.ErrorReason,
485-
condition.SeverityWarning,
486-
condition.DBReadyErrorMessage,
487-
err.Error()))
488-
return ctrl.Result{}, err
489-
}
490-
if (ctrlResult != ctrl.Result{}) {
491-
instance.Status.Conditions.Set(condition.FalseCondition(
492-
condition.DBReadyCondition,
493-
condition.RequestedReason,
494-
condition.SeverityInfo,
495-
condition.DBReadyRunningMessage))
496-
return ctrlResult, nil
497-
}
498-
499-
// wait for the DB to be setup
500-
ctrlResult, err = db.WaitForDBCreated(ctx, helper)
501-
if err != nil {
502-
instance.Status.Conditions.Set(condition.FalseCondition(
503-
condition.DBReadyCondition,
504-
condition.ErrorReason,
505-
condition.SeverityWarning,
506-
condition.DBReadyErrorMessage,
507-
err.Error()))
508-
return ctrlResult, err
509-
}
510-
if (ctrlResult != ctrl.Result{}) {
511-
instance.Status.Conditions.Set(condition.FalseCondition(
512-
condition.DBReadyCondition,
513-
condition.RequestedReason,
514-
condition.SeverityInfo,
515-
condition.DBReadyRunningMessage))
516-
return ctrlResult, nil
517-
}
518-
// update Status.DatabaseHostname, used to bootstrap/config the service
519-
instance.Status.DatabaseHostname = db.GetDatabaseHostname()
520-
instance.Status.Conditions.MarkTrue(condition.DBReadyCondition, condition.DBReadyMessage)
521-
522-
// create service DB - end
523-
524465
//
525466
// run keystone db sync
526467
//
@@ -533,7 +474,7 @@ func (r *KeystoneAPIReconciler) reconcileInit(
533474
5*time.Second,
534475
dbSyncHash,
535476
)
536-
ctrlResult, err = dbSyncjob.DoJob(
477+
ctrlResult, err := dbSyncjob.DoJob(
537478
ctx,
538479
helper,
539480
)
@@ -789,6 +730,65 @@ func (r *KeystoneAPIReconciler) reconcileNormal(
789730

790731
// run check OpenStack secret - end
791732

733+
//
734+
// create service DB instance
735+
//
736+
db := mariadbv1.NewDatabase(
737+
instance.Name,
738+
instance.Spec.DatabaseUser,
739+
instance.Spec.Secret,
740+
map[string]string{
741+
"dbName": instance.Spec.DatabaseInstance,
742+
},
743+
)
744+
// create or patch the DB
745+
ctrlResult, err := db.CreateOrPatchDB(
746+
ctx,
747+
helper,
748+
)
749+
if err != nil {
750+
instance.Status.Conditions.Set(condition.FalseCondition(
751+
condition.DBReadyCondition,
752+
condition.ErrorReason,
753+
condition.SeverityWarning,
754+
condition.DBReadyErrorMessage,
755+
err.Error()))
756+
return ctrl.Result{}, err
757+
}
758+
if (ctrlResult != ctrl.Result{}) {
759+
instance.Status.Conditions.Set(condition.FalseCondition(
760+
condition.DBReadyCondition,
761+
condition.RequestedReason,
762+
condition.SeverityInfo,
763+
condition.DBReadyRunningMessage))
764+
return ctrlResult, nil
765+
}
766+
767+
// wait for the DB to be setup
768+
ctrlResult, err = db.WaitForDBCreated(ctx, helper)
769+
if err != nil {
770+
instance.Status.Conditions.Set(condition.FalseCondition(
771+
condition.DBReadyCondition,
772+
condition.ErrorReason,
773+
condition.SeverityWarning,
774+
condition.DBReadyErrorMessage,
775+
err.Error()))
776+
return ctrlResult, err
777+
}
778+
if (ctrlResult != ctrl.Result{}) {
779+
instance.Status.Conditions.Set(condition.FalseCondition(
780+
condition.DBReadyCondition,
781+
condition.RequestedReason,
782+
condition.SeverityInfo,
783+
condition.DBReadyRunningMessage))
784+
return ctrlResult, nil
785+
}
786+
// update Status.DatabaseHostname, used to bootstrap/config the service
787+
instance.Status.DatabaseHostname = db.GetDatabaseHostname()
788+
instance.Status.Conditions.MarkTrue(condition.DBReadyCondition, condition.DBReadyMessage)
789+
790+
// create service DB - end
791+
792792
//
793793
// create RabbitMQ transportURL CR and get the actual URL from the associated secret that is created
794794
//
@@ -1172,7 +1172,9 @@ func (r *KeystoneAPIReconciler) generateServiceConfigMaps(
11721172
// custom.conf is going to /etc/<service>/<service>.conf.d
11731173
// all other files get placed into /etc/<service> to allow overwrite of e.g. policy.json
11741174
// TODO: make sure custom.conf can not be overwritten
1175-
customData := map[string]string{common.CustomServiceConfigFileName: instance.Spec.CustomServiceConfig}
1175+
customData := map[string]string{
1176+
common.CustomServiceConfigFileName: instance.Spec.CustomServiceConfig,
1177+
}
11761178
for key, data := range instance.Spec.DefaultConfigOverwrite {
11771179
customData[key] = data
11781180
}

0 commit comments

Comments
 (0)