From 5d8d27a71bc0d9e628c3b27cb5fd0ab78ff619d4 Mon Sep 17 00:00:00 2001
From: Ellis Tarn <ellistarn@gmail.com>
Date: Wed, 8 Sep 2021 14:44:04 -0700
Subject: [PATCH] Added success logging to the provisioner

---
 pkg/controllers/allocation/controller.go | 8 +++++++-
 pkg/controllers/allocation/filter.go     | 5 -----
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/pkg/controllers/allocation/controller.go b/pkg/controllers/allocation/controller.go
index 669b38ea1878..8fc0961f7b0f 100644
--- a/pkg/controllers/allocation/controller.go
+++ b/pkg/controllers/allocation/controller.go
@@ -77,7 +77,11 @@ func NewController(kubeClient client.Client, coreV1Client corev1.CoreV1Interface
 
 // Reconcile executes an allocation control loop for the resource
 func (c *Controller) Reconcile(ctx context.Context, req reconcile.Request) (reconcile.Result, error) {
-	ctx = logging.WithLogger(ctx, logging.FromContext(ctx).Named("Allocation"))
+	ctx = logging.WithLogger(ctx, logging.FromContext(ctx).Named(fmt.Sprintf("allocation.provisioner/%s", req.Name)))
+	logging.FromContext(ctx).Infof("Starting provisioning loop")
+	defer func() {
+		logging.FromContext(ctx).Infof("Watching for pod events")
+	}()
 
 	// 1. Fetch provisioner
 	provisioner, err := c.provisionerFor(ctx, req.NamespacedName)
@@ -91,6 +95,7 @@ func (c *Controller) Reconcile(ctx context.Context, req reconcile.Request) (reco
 	}
 
 	// 2. Wait on a pod batch
+	logging.FromContext(ctx).Infof("Waiting to batch additional pods")
 	c.Batcher.Wait(provisioner)
 
 	// 3. Filter pods
@@ -98,6 +103,7 @@ func (c *Controller) Reconcile(ctx context.Context, req reconcile.Request) (reco
 	if err != nil {
 		return result.RetryIfError(ctx, fmt.Errorf("filtering pods, %w", err))
 	}
+	logging.FromContext(ctx).Infof("Found %d provisionable pods", len(pods))
 	if len(pods) == 0 {
 		return reconcile.Result{}, nil
 	}
diff --git a/pkg/controllers/allocation/filter.go b/pkg/controllers/allocation/filter.go
index cb7cfc31c74e..9d504645bd51 100644
--- a/pkg/controllers/allocation/filter.go
+++ b/pkg/controllers/allocation/filter.go
@@ -38,10 +38,6 @@ func (f *Filter) GetProvisionablePods(ctx context.Context, provisioner *v1alpha3
 	if err := f.KubeClient.List(ctx, pods, client.MatchingFields{"spec.nodeName": ""}); err != nil {
 		return nil, fmt.Errorf("listing unscheduled pods, %w", err)
 	}
-	if len(pods.Items) == 0 {
-		return nil, nil
-	}
-
 	// 2. Filter pods that aren't provisionable
 	provisionable := []*v1.Pod{}
 	for _, p := range pods.Items {
@@ -53,7 +49,6 @@ func (f *Filter) GetProvisionablePods(ctx context.Context, provisioner *v1alpha3
 		}
 		provisionable = append(provisionable, ptr.Pod(p))
 	}
-	logging.FromContext(ctx).Infof("Found %d provisionable pods", len(provisionable))
 	return provisionable, nil
 }