Skip to content

Commit

Permalink
Added success logging to the provisioner
Browse files Browse the repository at this point in the history
  • Loading branch information
ellistarn committed Sep 8, 2021
1 parent eb5139e commit 5d8d27a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
8 changes: 7 additions & 1 deletion pkg/controllers/allocation/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -91,13 +95,15 @@ 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
pods, err := c.Filter.GetProvisionablePods(ctx, provisioner)
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
}
Expand Down
5 changes: 0 additions & 5 deletions pkg/controllers/allocation/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down

0 comments on commit 5d8d27a

Please sign in to comment.