Skip to content

Commit

Permalink
fix: exit filter step early when scheduling gates are found
Browse files Browse the repository at this point in the history
  • Loading branch information
marwanad committed Aug 13, 2024
1 parent b704bb7 commit bdd0022
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 7 deletions.
8 changes: 1 addition & 7 deletions pkg/scheduler_plugins/proxy/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,7 @@ func (pl *Plugin) Filter(ctx context.Context, state *framework.CycleState, pod *
return false, nil
}
_, isReserved = c.Annotations[common.AnnotationKeyIsReserved]

for _, cond := range c.Status.Conditions {
if cond.Type == v1.PodScheduled && cond.Status == v1.ConditionFalse && cond.Reason == v1.PodReasonUnschedulable {
isUnschedulable = true
break
}
}
isUnschedulable = isCandidatePodUnschedulable(c)

klog.V(1).Infof("candidate %s is reserved? %v unschedulable? %v", c.Name, isReserved, isUnschedulable)

Expand Down
32 changes: 32 additions & 0 deletions pkg/scheduler_plugins/proxy/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright The Multicluster-Scheduler Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package proxy

import (
v1 "k8s.io/api/core/v1"

"admiralty.io/multicluster-scheduler/pkg/apis/multicluster/v1alpha1"
)

func isCandidatePodUnschedulable(c *v1alpha1.PodChaperon) bool {
for _, cond := range c.Status.Conditions {
if cond.Type == v1.PodScheduled && cond.Status == v1.ConditionFalse && (cond.Reason == v1.PodReasonUnschedulable || cond.Reason == v1.PodReasonSchedulingGated) {
return true
}
}
return false
}
57 changes: 57 additions & 0 deletions pkg/scheduler_plugins/proxy/utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright The Multicluster-Scheduler Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package proxy

import (
"testing"

"github.com/stretchr/testify/require"
v1 "k8s.io/api/core/v1"
)

func TestIsPodUnschedulable(t *testing.T) {
tests := []struct {
name string
conditionStatus []v1.PodCondition
want bool
}{
{
name: "reason pod unschedulable",
conditionStatus: []v1.PodCondition{{Status: v1.ConditionFalse, Type: v1.PodScheduled, Reason: v1.PodReasonUnschedulable}},
want: true,
},
{
name: "scheduling gated",
conditionStatus: []v1.PodCondition{{Status: v1.ConditionFalse, Type: v1.PodScheduled, Reason: v1.PodReasonSchedulingGated}},
want: true,
},
{
name: "pod scheduled",
conditionStatus: []v1.PodCondition{{Status: v1.ConditionTrue, Type: v1.PodScheduled}},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
pod := &v1.Pod{
Status: v1.PodStatus{Conditions: tt.conditionStatus},
}
res := isCandidatePodUnschedulable(pod)
require.Equal(t, tt.want, res)
})
}
}

0 comments on commit bdd0022

Please sign in to comment.