Skip to content

Commit

Permalink
pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bwagner5 committed Nov 24, 2021
1 parent eeff35f commit 562d4e8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
8 changes: 4 additions & 4 deletions pkg/controllers/provisioning/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func (p *Provisioner) Batch(ctx context.Context) (pods []*v1.Pod) {
idle := time.NewTimer(MinBatchDuration)
start := time.Now()
defer func() {
pods = p.RemoveScheduled(ctx, pods)
pods = p.FilterProvisionable(ctx, pods)
logging.FromContext(ctx).Infof("Batched %d pods in %s", len(pods), time.Since(start))
}()
for {
Expand All @@ -141,16 +141,16 @@ func (p *Provisioner) Batch(ctx context.Context) (pods []*v1.Pod) {
}
}

// RemoveScheduled removes pods that have been assigned a node.
// FilterProvisionable removes pods that have been assigned a node.
// This check is needed to prevent duplicate binds when a pod is scheduled to a node
// between the time it was ingested into the scheduler and the time it is included
// in a provisioner batch.
func (p *Provisioner) RemoveScheduled(ctx context.Context, pods []*v1.Pod) []*v1.Pod {
func (p *Provisioner) FilterProvisionable(ctx context.Context, pods []*v1.Pod) []*v1.Pod {
unscheduled := []*v1.Pod{}
for _, pod := range pods {
candidate := pod
if err := p.kubeClient.Get(ctx, types.NamespacedName{Namespace: pod.Namespace, Name: pod.Name}, candidate); err != nil {
logging.FromContext(ctx).Errorf("Checking if pod \"%s\" is provisionable", pod)
logging.FromContext(ctx).Errorf("Unexpected error retrieving pod \"%s/%s\" while checking if it is provisionable", pod.Namespace, pod.Name)
}
if !isProvisionable(candidate) {
continue
Expand Down
5 changes: 1 addition & 4 deletions pkg/controllers/scheduling/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,7 @@ func (c *Controller) Schedule(ctx context.Context, pod *v1.Pod) error {
}

func isProvisionable(p *v1.Pod) bool {
if p.Spec.NodeName != "" || !pod.FailedToSchedule(p) || pod.IsOwnedByDaemonSet(p) || pod.IsOwnedByNode(p) {
return false
}
return true
return p.Spec.NodeName == "" && pod.FailedToSchedule(p) && !pod.IsOwnedByDaemonSet(p) && !pod.IsOwnedByNode(p)
}

func validate(p *v1.Pod) error {
Expand Down

0 comments on commit 562d4e8

Please sign in to comment.