Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Remove FailedResourceType and return custom error" #19495

Merged
merged 1 commit into from
Jan 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 0 additions & 40 deletions plugin/pkg/scheduler/algorithm/predicates/error.go

This file was deleted.

11 changes: 8 additions & 3 deletions plugin/pkg/scheduler/algorithm/predicates/predicates.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ type resourceRequest struct {
memory int64
}

var FailedResourceType string

func getResourceRequest(pod *api.Pod) resourceRequest {
result := resourceRequest{}
for _, container := range pod.Spec.Containers {
Expand Down Expand Up @@ -306,7 +308,8 @@ func (r *ResourceFit) PodFitsResources(pod *api.Pod, existingPods []*api.Pod, no

if int64(len(existingPods))+1 > info.Status.Capacity.Pods().Value() {
glog.V(10).Infof("Cannot schedule Pod %+v, because Node %+v is full, running %v out of %v Pods.", podName(pod), node, len(existingPods), info.Status.Capacity.Pods().Value())
return false, ErrExceededMaxPodNumber
FailedResourceType = "PodExceedsMaxPodNumber"
return false, nil
}

podRequest := getResourceRequest(pod)
Expand All @@ -318,11 +321,13 @@ func (r *ResourceFit) PodFitsResources(pod *api.Pod, existingPods []*api.Pod, no
_, exceedingCPU, exceedingMemory := CheckPodsExceedingFreeResources(pods, info.Status.Capacity)
if len(exceedingCPU) > 0 {
glog.V(10).Infof("Cannot schedule Pod %+v, because Node %v does not have sufficient CPU", podName(pod), node)
return false, ErrInsufficientFreeCPU
FailedResourceType = "PodExceedsFreeCPU"
return false, nil
}
if len(exceedingMemory) > 0 {
glog.V(10).Infof("Cannot schedule Pod %+v, because Node %v does not have sufficient Memory", podName(pod), node)
return false, ErrInsufficientFreeMemory
FailedResourceType = "PodExceedsFreeMemory"
return false, nil
}
glog.V(10).Infof("Schedule Pod %+v on Node %+v is allowed, Node is running only %v out of %v Pods.", podName(pod), node, len(pods)-1, info.Status.Capacity.Pods().Value())
return true, nil
Expand Down
18 changes: 4 additions & 14 deletions plugin/pkg/scheduler/algorithm/predicates/predicates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ func TestPodFitsResources(t *testing.T) {
existingPods []*api.Pod
fits bool
test string
wErr error
}{
{
pod: &api.Pod{},
Expand All @@ -89,7 +88,6 @@ func TestPodFitsResources(t *testing.T) {
},
fits: true,
test: "no resources requested always fits",
wErr: nil,
},
{
pod: newResourcePod(resourceRequest{milliCPU: 1, memory: 1}),
Expand All @@ -98,7 +96,6 @@ func TestPodFitsResources(t *testing.T) {
},
fits: false,
test: "too many resources fails",
wErr: ErrInsufficientFreeCPU,
},
{
pod: newResourcePod(resourceRequest{milliCPU: 1, memory: 1}),
Expand All @@ -107,7 +104,6 @@ func TestPodFitsResources(t *testing.T) {
},
fits: true,
test: "both resources fit",
wErr: nil,
},
{
pod: newResourcePod(resourceRequest{milliCPU: 1, memory: 2}),
Expand All @@ -116,7 +112,6 @@ func TestPodFitsResources(t *testing.T) {
},
fits: false,
test: "one resources fits",
wErr: ErrInsufficientFreeMemory,
},
{
pod: newResourcePod(resourceRequest{milliCPU: 5, memory: 1}),
Expand All @@ -125,7 +120,6 @@ func TestPodFitsResources(t *testing.T) {
},
fits: true,
test: "equal edge case",
wErr: nil,
},
}

Expand All @@ -134,8 +128,8 @@ func TestPodFitsResources(t *testing.T) {

fit := ResourceFit{FakeNodeInfo(node)}
fits, err := fit.PodFitsResources(test.pod, test.existingPods, "machine")
if !reflect.DeepEqual(err, test.wErr) {
t.Errorf("%s: unexpected error: %v, want: %v", test.test, err, test.wErr)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if fits != test.fits {
t.Errorf("%s: expected: %v got %v", test.test, test.fits, fits)
Expand All @@ -147,7 +141,6 @@ func TestPodFitsResources(t *testing.T) {
existingPods []*api.Pod
fits bool
test string
wErr error
}{
{
pod: &api.Pod{},
Expand All @@ -156,7 +149,6 @@ func TestPodFitsResources(t *testing.T) {
},
fits: false,
test: "even without specified resources predicate fails when there's no available ips",
wErr: ErrExceededMaxPodNumber,
},
{
pod: newResourcePod(resourceRequest{milliCPU: 1, memory: 1}),
Expand All @@ -165,7 +157,6 @@ func TestPodFitsResources(t *testing.T) {
},
fits: false,
test: "even if both resources fit predicate fails when there's no available ips",
wErr: ErrExceededMaxPodNumber,
},
{
pod: newResourcePod(resourceRequest{milliCPU: 5, memory: 1}),
Expand All @@ -174,16 +165,15 @@ func TestPodFitsResources(t *testing.T) {
},
fits: false,
test: "even for equal edge case predicate fails when there's no available ips",
wErr: ErrExceededMaxPodNumber,
},
}
for _, test := range notEnoughPodsTests {
node := api.Node{Status: api.NodeStatus{Capacity: makeResources(10, 20, 1).Capacity}}

fit := ResourceFit{FakeNodeInfo(node)}
fits, err := fit.PodFitsResources(test.pod, test.existingPods, "machine")
if !reflect.DeepEqual(err, test.wErr) {
t.Errorf("%s: unexpected error: %v, want: %v", test.test, err, test.wErr)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if fits != test.fits {
t.Errorf("%s: expected: %v got %v", test.test, test.fits, fits)
Expand Down
5 changes: 3 additions & 2 deletions plugin/pkg/scheduler/generic_scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func findNodesThatFit(pod *api.Pod, machineToPods map[string][]*api.Pod, predica
for _, node := range nodes.Items {
fits := true
for name, predicate := range predicateFuncs {
predicates.FailedResourceType = ""
fit, err := predicate(pod, machineToPods[node.Name], node.Name)
if err != nil {
return api.NodeList{}, FailedPredicateMap{}, err
Expand All @@ -136,8 +137,8 @@ func findNodesThatFit(pod *api.Pod, machineToPods map[string][]*api.Pod, predica
if _, found := failedPredicateMap[node.Name]; !found {
failedPredicateMap[node.Name] = sets.String{}
}
if re, ok := err.(*predicates.InsufficientResourceError); ok {
failedPredicateMap[node.Name].Insert(re.ResourceName)
if predicates.FailedResourceType != "" {
failedPredicateMap[node.Name].Insert(predicates.FailedResourceType)
break
}
failedPredicateMap[node.Name].Insert(name)
Expand Down