Skip to content

Commit 619d2c8

Browse files
committed
DNM - testing CI
iteratively adding elements from PR openstack-k8s-operators#260 to see what's making it hang
1 parent 8c6251d commit 619d2c8

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

controllers/mariadbaccount_controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ func (r *MariaDBAccountReconciler) SetupWithManager(mgr ctrl.Manager) error {
6363
func (r *MariaDBAccountReconciler) Reconcile(ctx context.Context, req ctrl.Request) (result ctrl.Result, _err error) {
6464
log := GetLog(ctx, "MariaDBAccount")
6565

66+
log.Info("this is a test")
67+
6668
var err error
6769

6870
instance := &databasev1beta1.MariaDBAccount{}

controllers/mariadbdatabase_controller.go

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import (
2727
ctrl "sigs.k8s.io/controller-runtime"
2828
"sigs.k8s.io/controller-runtime/pkg/client"
2929
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
30+
"sigs.k8s.io/controller-runtime/pkg/handler"
31+
"sigs.k8s.io/controller-runtime/pkg/reconcile"
3032

3133
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
3234
helper "github.com/openstack-k8s-operators/lib-common/modules/common/helper"
@@ -145,7 +147,7 @@ func (r *MariaDBDatabaseReconciler) Reconcile(ctx context.Context, req ctrl.Requ
145147

146148
// here we know that Galera exists so add a finalizer to ourselves and to the db CR. Before this point there is no reason to have a finalizer on ourselves as nothing to cleanup.
147149
if instance.DeletionTimestamp.IsZero() || isNewInstance { // this condition can be removed if you wish as it is always true at this point otherwise we would returned earlier.
148-
if controllerutil.AddFinalizer(dbGalera, fmt.Sprintf("%s-%s", helper.GetFinalizer(), instance.Name)) {
150+
if dbGalera.DeletionTimestamp.IsZero() && controllerutil.AddFinalizer(dbGalera, fmt.Sprintf("%s-%s", helper.GetFinalizer(), instance.Name)) {
149151
err := r.Update(ctx, dbGalera)
150152
if err != nil {
151153
return ctrl.Result{}, err
@@ -245,8 +247,42 @@ func (r *MariaDBDatabaseReconciler) Reconcile(ctx context.Context, req ctrl.Requ
245247

246248
// SetupWithManager -
247249
func (r *MariaDBDatabaseReconciler) SetupWithManager(mgr ctrl.Manager) error {
250+
updateStatusFn := func(ctx context.Context, o client.Object) []reconcile.Request {
251+
log := GetLog(ctx, "MariaDBDatabase")
252+
253+
result := []reconcile.Request{}
254+
255+
mariaDBDatabases := &databasev1beta1.MariaDBDatabaseList{}
256+
257+
listOpts := []client.ListOption{
258+
client.InNamespace(o.GetNamespace()),
259+
}
260+
if err := r.Client.List(ctx, mariaDBDatabases, listOpts...); err != nil {
261+
log.Error(err, "Unable to retrieve MariaDBDatabase CRs %w")
262+
return nil
263+
}
264+
265+
for _, cr := range mariaDBDatabases.Items {
266+
267+
if o.GetName() == cr.GetLabels()["dbName"] {
268+
name := client.ObjectKey{
269+
Namespace: o.GetNamespace(),
270+
Name: cr.Name,
271+
}
272+
log.Info(fmt.Sprintf("Galera %s is used by MariaDBDatabase CR %s", o.GetName(), cr.Name))
273+
result = append(result, reconcile.Request{NamespacedName: name})
274+
}
275+
}
276+
277+
if len(result) > 0 {
278+
return result
279+
}
280+
return nil
281+
}
282+
248283
return ctrl.NewControllerManagedBy(mgr).
249284
For(&databasev1beta1.MariaDBDatabase{}).
285+
Watches(&databasev1beta1.Galera{}, handler.EnqueueRequestsFromMapFunc(updateStatusFn)).
250286
Complete(r)
251287
}
252288

0 commit comments

Comments
 (0)