Skip to content

Commit

Permalink
fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tzneal committed Mar 28, 2022
1 parent c74aee6 commit 40e8a5d
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pkg/cloudprovider/requirements.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func Compatible(it InstanceType, requirements v1alpha5.Requirements) bool {
}

func FilterInstanceTypes(instanceTypes []InstanceType, requirements v1alpha5.Requirements, requests v1.ResourceList) []InstanceType {
result := []InstanceType{}
var result []InstanceType
for _, instanceType := range instanceTypes {
if !Compatible(instanceType, requirements) {
continue
Expand Down
5 changes: 0 additions & 5 deletions pkg/controllers/provisioning/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package provisioning
import (
"context"
"fmt"
"sync/atomic"

"github.com/imdario/mergo"
"github.com/prometheus/client_golang/prometheus"
Expand Down Expand Up @@ -173,15 +172,11 @@ func (p *Provisioner) launch(ctx context.Context, node *scheduling.Node) error {
func (p *Provisioner) bind(ctx context.Context, node *v1.Node, pods []*v1.Pod) (err error) {
defer metrics.Measure(bindTimeHistogram.WithLabelValues(injection.GetNamespacedName(ctx).Name))()
// Bind pods
var bound int64
workqueue.ParallelizeUntil(ctx, len(pods), len(pods), func(i int) {
if err := p.coreV1Client.Pods(pods[i].Namespace).Bind(ctx, &v1.Binding{TypeMeta: pods[i].TypeMeta, ObjectMeta: pods[i].ObjectMeta, Target: v1.ObjectReference{Name: node.Name}}, metav1.CreateOptions{}); err != nil {
logging.FromContext(ctx).Errorf("Failed to bind %s/%s to %s, %s", pods[i].Namespace, pods[i].Name, node.Name, err)
} else {
atomic.AddInt64(&bound, 1)
}
})
logging.FromContext(ctx).Infof("Bound %d pod(s) to node %s", bound, node.Name)
return nil
}

Expand Down
10 changes: 7 additions & 3 deletions pkg/controllers/provisioning/scheduling/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,20 @@ type Node struct {

func NewNode(constraints *v1alpha5.Constraints, daemonResources v1.ResourceList, instanceTypes []cloudprovider.InstanceType) *Node {
return &Node{
Constraints: constraints,
Constraints: constraints.DeepCopy(),
InstanceTypeOptions: instanceTypes,
requests: daemonResources,
}
}

func (n *Node) Add(pod *v1.Pod) error {
podRequirements := v1alpha5.NewPodRequirements(pod)
if err := n.Constraints.Requirements.Compatible(podRequirements); err != nil {
return err

if len(n.Pods) != 0 {
// TODO: remove this check for n.Pods once we properly support hostname topology spread
if err := n.Constraints.Requirements.Compatible(podRequirements); err != nil {
return err
}
}
requirements := n.Constraints.Requirements.Add(podRequirements.Requirements...)
requests := resources.Merge(n.requests, resources.RequestsForPods(pod))
Expand Down
7 changes: 6 additions & 1 deletion pkg/controllers/provisioning/scheduling/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func (s *Scheduler) Solve(ctx context.Context, provisioner *v1alpha5.Provisioner
return nil, fmt.Errorf("constructing nodeset, %w", err)
}

unschedulableCount := 0
for _, pod := range pods {
isScheduled := false
for _, node := range nodeSet.nodes {
Expand All @@ -92,13 +93,17 @@ func (s *Scheduler) Solve(ctx context.Context, provisioner *v1alpha5.Provisioner
if !isScheduled {
n := NewNode(constraints, nodeSet.daemonResources, instanceTypes)
if err := n.Add(pod); err != nil {
unschedulableCount++
logging.FromContext(ctx).With("pod", client.ObjectKeyFromObject(pod)).Errorf("Scheduling pod, %s", err)
} else {
nodeSet.Add(n)
}
}
}
logging.FromContext(ctx).Infof("Scheduled %d pods onto %d nodes", len(pods), len(nodeSet.nodes))

if unschedulableCount != 0 {
logging.FromContext(ctx).Errorf("Failed to schedule %d pods", unschedulableCount)
}
return nodeSet.nodes, nil
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/utils/resources/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ func Cmp(lhs resource.Quantity, rhs resource.Quantity) int {
return lhs.Cmp(rhs)
}

// Fits returns true if the candidate set of resources is less than or equal to the total set of resources.
func Fits(candidate, total v1.ResourceList) bool {
for resourceName, quantity := range candidate {
if Cmp(candidate[resourceName], quantity) < 0 {
if Cmp(quantity, total[resourceName]) > 0 {
return false
}
}
Expand Down

0 comments on commit 40e8a5d

Please sign in to comment.