diff --git a/controllers/barbican_controller.go b/controllers/barbican_controller.go index d106b83..2b45927 100644 --- a/controllers/barbican_controller.go +++ b/controllers/barbican_controller.go @@ -738,6 +738,7 @@ func (r *BarbicanReconciler) reconcileInit( return rbacResult, nil } + Log.Info(fmt.Sprintf(">>>>>>>>>> DEBUG INIT: DB")) // // create service DB instance // @@ -755,6 +756,7 @@ func (r *BarbicanReconciler) reconcileInit( helper, ) if err != nil { + Log.Info(fmt.Sprintf(">>>>>>>>>> DEBUG INIT: DB ERROR")) instance.Status.Conditions.Set(condition.FalseCondition( condition.DBReadyCondition, condition.ErrorReason, @@ -763,6 +765,7 @@ func (r *BarbicanReconciler) reconcileInit( err.Error())) return ctrl.Result{}, err } + Log.Info(fmt.Sprintf(">>>>>>>>>> DEBUG INIT: DB WORKS")) if (ctrlResult != ctrl.Result{}) { instance.Status.Conditions.Set(condition.FalseCondition( condition.DBReadyCondition, @@ -774,6 +777,7 @@ func (r *BarbicanReconciler) reconcileInit( // wait for the DB to be setup ctrlResult, err = db.WaitForDBCreated(ctx, helper) if err != nil { + Log.Info(fmt.Sprintf(">>>>>>>>>> DEBUG INIT: DB CREATION ERROR")) instance.Status.Conditions.Set(condition.FalseCondition( condition.DBReadyCondition, condition.ErrorReason, @@ -782,7 +786,9 @@ func (r *BarbicanReconciler) reconcileInit( err.Error())) return ctrlResult, err } + Log.Info(fmt.Sprintf(">>>>>>>>>> DEBUG INIT: DB CREATED")) if (ctrlResult != ctrl.Result{}) { + Log.Info(fmt.Sprintf(">>>>>>>>>> DEBUG INIT: DB RESULT ERROR")) instance.Status.Conditions.Set(condition.FalseCondition( condition.DBReadyCondition, condition.RequestedReason, @@ -790,9 +796,11 @@ func (r *BarbicanReconciler) reconcileInit( condition.DBReadyRunningMessage)) return ctrlResult, nil } + Log.Info(fmt.Sprintf(">>>>>>>>>> DEBUG INIT: DB MARK AS TRUE")) // update Status.DatabaseHostname, used to config the service instance.Status.DatabaseHostname = db.GetDatabaseHostname() instance.Status.Conditions.MarkTrue(condition.DBReadyCondition, condition.DBReadyMessage) + Log.Info(fmt.Sprintf(">>>>>>>>>> DEBUG INIT: DB MARKED AS TRUE")) // create service DB - end // diff --git a/tests/functional/barbican_controller_test.go b/tests/functional/barbican_controller_test.go index 237e64d..0cf6420 100644 --- a/tests/functional/barbican_controller_test.go +++ b/tests/functional/barbican_controller_test.go @@ -11,6 +11,7 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" //rabbit //"k8s.io/utils/ptr" + barbicanv1beta1 "github.com/openstack-k8s-operators/barbican-operator/api/v1beta1" ) var _ = Describe("Barbican controller", func() { @@ -203,4 +204,74 @@ var _ = Describe("Barbican controller", func() { BarbicanKeystoneListenerNotExists(barbicanName) }) }) + + When("DB sync is completed", func() { + BeforeEach(func() { + DeferCleanup(k8sClient.Delete, ctx, CreateBarbicanMessageBusSecret(barbicanName.Namespace, "rabbitmq-secret")) + DeferCleanup(th.DeleteInstance, CreateBarbican(barbicanName, GetDefaultBarbicanSpec())) + //DeferCleanup(th.DeleteInstance, keystone.CreateKeystoneAPI(barbicanName.Namespace)) + DeferCleanup(k8sClient.Delete, ctx, CreateKeystoneAPISecret(namespace, SecretName)) + + DeferCleanup( + k8sClient.Delete, ctx, CreateBarbicanSecret(barbicanName.Namespace, SecretName)) + + DeferCleanup( + mariadb.DeleteDBService, + mariadb.CreateDBService( + namespace, + GetBarbican(barbicanName).Spec.DatabaseInstance, + corev1.ServiceSpec{ + Ports: []corev1.ServicePort{{Port: 3306}}, + }, + ), + ) + infra.SimulateTransportURLReady(barbicanTransportURL) + DeferCleanup(keystone.DeleteKeystoneAPI, keystone.CreateKeystoneAPI(barbicanName.Namespace)) + mariadb.SimulateMariaDBDatabaseCompleted(barbicanName) + th.SimulateJobSuccess(dbSyncJobName) + }) + + It("should have db sync ready condition", func() { + th.ExpectCondition( + barbicanName, + ConditionGetterFunc(BarbicanConditionGetter), + condition.ReadyCondition, + corev1.ConditionFalse, + ) + + th.ExpectCondition( + barbicanName, + ConditionGetterFunc(BarbicanConditionGetter), + barbicanv1beta1.BarbicanRabbitMQTransportURLReadyCondition, + corev1.ConditionTrue, + ) + + /* + th.ExpectCondition( + barbicanName, + ConditionGetterFunc(BarbicanConditionGetter), + condition.DBSyncReadyCondition, + corev1.ConditionTrue, + ) + th.ExpectCondition( + barbicanName, + ConditionGetterFunc(BarbicanConditionGetter), + condition.ExposeServiceReadyCondition, + corev1.ConditionTrue, + ) + th.ExpectCondition( + barbicanName, + ConditionGetterFunc(BarbicanConditionGetter), + condition.BootstrapReadyCondition, + corev1.ConditionFalse, + ) + */ + th.ExpectCondition( + barbicanName, + ConditionGetterFunc(BarbicanConditionGetter), + condition.NetworkAttachmentsReadyCondition, + corev1.ConditionUnknown, + ) + }) + }) }) diff --git a/tests/functional/base_test.go b/tests/functional/base_test.go index 6c52671..9597c40 100644 --- a/tests/functional/base_test.go +++ b/tests/functional/base_test.go @@ -81,6 +81,16 @@ func CreateBarbicanMessageBusSecret(namespace string, name string) *corev1.Secre return s } +func CreateBarbicanSecret(namespace string, name string) *corev1.Secret { + return th.CreateSecret( + types.NamespacedName{Namespace: namespace, Name: name}, + map[string][]byte{ + "BarbicanDatabasePassword": []byte("12345678"), + "BarbicanPassword": []byte("12345678"), + }, + ) +} + /* func CreateKeystoneAPISecret(namespace string, name string) *corev1.Secret { return th.CreateSecret(