@@ -397,72 +397,20 @@ func (r *NeutronAPIReconciler) reconcileInit(
397397 Log := r .GetLogger (ctx )
398398 Log .Info ("Reconciling Service init" )
399399
400- // create neutron DB instance
401- //
402- db := mariadbv1 .NewDatabaseWithNamespace (
403- neutronapi .Database ,
404- instance .Spec .DatabaseUser ,
405- instance .Spec .Secret ,
406- map [string ]string {
407- "dbName" : instance .Spec .DatabaseInstance ,
408- },
409- neutronapi .Database ,
410- instance .Namespace ,
411- )
412- // create or patch the DB
413- ctrlResult , err := db .CreateOrPatchDBByName (
414- ctx ,
415- helper ,
416- instance .Spec .DatabaseInstance ,
417- )
400+ db , result , err := r .ensureDB (ctx , helper , instance )
418401 if err != nil {
419- instance .Status .Conditions .Set (condition .FalseCondition (
420- condition .DBReadyCondition ,
421- condition .ErrorReason ,
422- condition .SeverityWarning ,
423- condition .DBReadyErrorMessage ,
424- err .Error ()))
425402 return ctrl.Result {}, err
403+ } else if (result != ctrl.Result {}) {
404+ return result , nil
426405 }
427- if (ctrlResult != ctrl.Result {}) {
428- instance .Status .Conditions .Set (condition .FalseCondition (
429- condition .DBReadyCondition ,
430- condition .RequestedReason ,
431- condition .SeverityInfo ,
432- condition .DBReadyRunningMessage ))
433- return ctrlResult , nil
434- }
435- // wait for the DB to be setup
436- ctrlResult , err = db .WaitForDBCreatedWithTimeout (ctx , helper , time .Second * 5 )
437- if err != nil {
438- instance .Status .Conditions .Set (condition .FalseCondition (
439- condition .DBReadyCondition ,
440- condition .ErrorReason ,
441- condition .SeverityWarning ,
442- condition .DBReadyErrorMessage ,
443- err .Error ()))
444- return ctrlResult , err
445- }
446- if (ctrlResult != ctrl.Result {}) {
447- instance .Status .Conditions .Set (condition .FalseCondition (
448- condition .DBReadyCondition ,
449- condition .RequestedReason ,
450- condition .SeverityInfo ,
451- condition .DBReadyRunningMessage ))
452- return ctrlResult , nil
453- }
454- // update Status.DatabaseHostname, used to bootstrap/config the service
455- instance .Status .DatabaseHostname = db .GetDatabaseHostname ()
456- instance .Status .Conditions .MarkTrue (condition .DBReadyCondition , condition .DBReadyMessage )
457- // create neutron DB - end
458406
459407 // Create Secrets required as input for the Service and calculate an overall hash of hashes
460408 //
461409
462410 //
463411 // create Secret required for neutronapi and dbsync input. It contains minimal neutron config required
464412 // to get the service up, user can add additional files to be added to the service.
465- err = r .generateServiceSecrets (ctx , helper , instance , ospSecret , & secretVars )
413+ err = r .generateServiceSecrets (ctx , helper , instance , ospSecret , & secretVars , db )
466414 if err != nil {
467415 instance .Status .Conditions .Set (condition .FalseCondition (
468416 condition .ServiceConfigReadyCondition ,
@@ -1404,6 +1352,7 @@ func (r *NeutronAPIReconciler) generateServiceSecrets(
14041352 instance * neutronv1beta1.NeutronAPI ,
14051353 ospSecret * corev1.Secret ,
14061354 envVars * map [string ]env.Setter ,
1355+ db * mariadbv1.Database ,
14071356) error {
14081357 // Create/update secrets from templates
14091358 cmLabels := labels .GetLabels (instance , labels .GetGroupLabel (neutronapi .ServiceName ), map [string ]string {})
@@ -1425,13 +1374,19 @@ func (r *NeutronAPIReconciler) generateServiceSecrets(
14251374 if err != nil {
14261375 return err
14271376 }
1428-
1377+ var tlsCfg * tls.Service
1378+ if instance .Spec .TLS .Ca .CaBundleSecretName != "" {
1379+ tlsCfg = & tls.Service {}
1380+ }
14291381 // customData hold any customization for the service.
14301382 // 02-neutron-custom.conf is going to /etc/<service>.conf.d
14311383 // 01-neutron.conf is going to /etc/<service>.conf.d such that it gets loaded before custom one
14321384 // all other files get placed into /etc/<service> to allow overwrite of e.g. logging.conf or policy.json
14331385 // TODO: make sure custom.conf can not be overwritten
1434- customData := map [string ]string {"02-neutron-custom.conf" : instance .Spec .CustomServiceConfig }
1386+ customData := map [string ]string {
1387+ "02-neutron-custom.conf" : instance .Spec .CustomServiceConfig ,
1388+ "my.cnf" : db .GetDatabaseClientConfig (tlsCfg ), //(mschuppert) for now just get the default my.cnf
1389+ }
14351390 for key , data := range instance .Spec .DefaultConfigOverwrite {
14361391 customData [key ] = data
14371392 }
@@ -1602,3 +1557,68 @@ func (r *NeutronAPIReconciler) getNeutronMemcached(
16021557 }
16031558 return memcached , err
16041559}
1560+
1561+ // ensureDB - create neutron DB instance
1562+ func (r * NeutronAPIReconciler ) ensureDB (
1563+ ctx context.Context ,
1564+ h * helper.Helper ,
1565+ instance * neutronv1beta1.NeutronAPI ,
1566+ ) (* mariadbv1.Database , ctrl.Result , error ) {
1567+ db := mariadbv1 .NewDatabaseWithNamespace (
1568+ neutronapi .Database ,
1569+ instance .Spec .DatabaseUser ,
1570+ instance .Spec .Secret ,
1571+ map [string ]string {
1572+ "dbName" : instance .Spec .DatabaseInstance ,
1573+ },
1574+ neutronapi .Database ,
1575+ instance .Namespace ,
1576+ )
1577+ // create or patch the DB
1578+ ctrlResult , err := db .CreateOrPatchDBByName (
1579+ ctx ,
1580+ h ,
1581+ instance .Spec .DatabaseInstance ,
1582+ )
1583+ if err != nil {
1584+ instance .Status .Conditions .Set (condition .FalseCondition (
1585+ condition .DBReadyCondition ,
1586+ condition .ErrorReason ,
1587+ condition .SeverityWarning ,
1588+ condition .DBReadyErrorMessage ,
1589+ err .Error ()))
1590+ return db , ctrl.Result {}, err
1591+ }
1592+ if (ctrlResult != ctrl.Result {}) {
1593+ instance .Status .Conditions .Set (condition .FalseCondition (
1594+ condition .DBReadyCondition ,
1595+ condition .RequestedReason ,
1596+ condition .SeverityInfo ,
1597+ condition .DBReadyRunningMessage ))
1598+ return db , ctrlResult , nil
1599+ }
1600+ // wait for the DB to be setup
1601+ ctrlResult , err = db .WaitForDBCreatedWithTimeout (ctx , h , time .Second * 5 )
1602+ if err != nil {
1603+ instance .Status .Conditions .Set (condition .FalseCondition (
1604+ condition .DBReadyCondition ,
1605+ condition .ErrorReason ,
1606+ condition .SeverityWarning ,
1607+ condition .DBReadyErrorMessage ,
1608+ err .Error ()))
1609+ return db , ctrlResult , err
1610+ }
1611+ if (ctrlResult != ctrl.Result {}) {
1612+ instance .Status .Conditions .Set (condition .FalseCondition (
1613+ condition .DBReadyCondition ,
1614+ condition .RequestedReason ,
1615+ condition .SeverityInfo ,
1616+ condition .DBReadyRunningMessage ))
1617+ return db , ctrlResult , nil
1618+ }
1619+ // update Status.DatabaseHostname, used to bootstrap/config the service
1620+ instance .Status .DatabaseHostname = db .GetDatabaseHostname ()
1621+ instance .Status .Conditions .MarkTrue (condition .DBReadyCondition , condition .DBReadyMessage )
1622+
1623+ return db , ctrlResult , nil
1624+ }
0 commit comments