You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@yunikorn.apache.org by GitBox <gi...@apache.org> on 2021/10/18 15:10:14 UTC

[GitHub] [incubator-yunikorn-k8shim] craigcondit commented on a change in pull request #310: [YUNIKORN-874] Implement PredicateManager.

craigcondit commented on a change in pull request #310:
URL: https://github.com/apache/incubator-yunikorn-k8shim/pull/310#discussion_r731030713



##########
File path: pkg/plugin/predicates/predicate_manager.go
##########
@@ -0,0 +1,394 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements.  See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership.  The ASF licenses this file
+ to you 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 predicates
+
+import (
+	"context"
+	"errors"
+	"fmt"
+
+	"go.uber.org/zap"
+	v1 "k8s.io/api/core/v1"
+	"k8s.io/apimachinery/pkg/runtime"
+	"k8s.io/kube-scheduler/config/v1beta1"
+	"k8s.io/kubernetes/pkg/scheduler/algorithmprovider"
+	apiConfig "k8s.io/kubernetes/pkg/scheduler/apis/config"
+	"k8s.io/kubernetes/pkg/scheduler/apis/config/scheme"
+	"k8s.io/kubernetes/pkg/scheduler/framework"
+	"k8s.io/kubernetes/pkg/scheduler/framework/plugins"
+	"k8s.io/kubernetes/pkg/scheduler/framework/plugins/interpodaffinity"
+	"k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodeaffinity"
+	"k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodename"
+	"k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodeports"
+	"k8s.io/kubernetes/pkg/scheduler/framework/plugins/noderesources"
+	"k8s.io/kubernetes/pkg/scheduler/framework/plugins/nodeunschedulable"
+	"k8s.io/kubernetes/pkg/scheduler/framework/plugins/podtopologyspread"
+	"k8s.io/kubernetes/pkg/scheduler/framework/plugins/tainttoleration"
+	fwruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime"
+
+	"github.com/apache/incubator-yunikorn-core/pkg/log"
+)
+
+type PredicateManager interface {
+	Predicates(pod *v1.Pod, node *framework.NodeInfo, allocate bool) (plugin string, error error)
+}
+
+var _ PredicateManager = &predicateManagerImpl{}
+
+var configDecoder = scheme.Codecs.UniversalDecoder()
+
+type predicateManagerImpl struct {
+	reservationPreFilters *[]framework.PreFilterPlugin
+	allocationPreFilters  *[]framework.PreFilterPlugin
+	reservationFilters    *[]framework.FilterPlugin
+	allocationFilters     *[]framework.FilterPlugin
+}
+
+func (p *predicateManagerImpl) Predicates(pod *v1.Pod, node *framework.NodeInfo, allocate bool) (plugin string, error error) {
+	if allocate {
+		return p.predicatesAllocate(pod, node)
+	}
+	return p.predicatesReserve(pod, node)
+}
+
+func (p *predicateManagerImpl) predicatesReserve(pod *v1.Pod, node *framework.NodeInfo) (plugin string, error error) {
+	ctx := context.TODO()
+	state := framework.NewCycleState()
+	return p.podFitsNode(ctx, state, *p.reservationPreFilters, *p.reservationFilters, pod, node)
+}
+
+func (p *predicateManagerImpl) predicatesAllocate(pod *v1.Pod, node *framework.NodeInfo) (plugin string, error error) {
+	ctx := context.TODO()
+	state := framework.NewCycleState()
+	return p.podFitsNode(ctx, state, *p.allocationPreFilters, *p.allocationFilters, pod, node)
+}
+
+func (p *predicateManagerImpl) podFitsNode(ctx context.Context, state *framework.CycleState, preFilters []framework.PreFilterPlugin, filters []framework.FilterPlugin, pod *v1.Pod, node *framework.NodeInfo) (plugin string, error error) {
+	// Run "prefilter" plugins.
+	s, plugin := p.runPreFilterPlugins(ctx, state, preFilters, pod)
+	if !s.IsSuccess() {
+		if !s.IsUnschedulable() {
+			return plugin, s.AsError()
+		}
+		return plugin, errors.New("pod is unschedulable")
+	}
+
+	// Run "filter" plugins on node
+	statuses, plugin := p.runFilterPlugins(ctx, filters, state, pod, node)
+	s = statuses.Merge()
+	if !s.IsSuccess() {
+		if !s.IsUnschedulable() {
+			return plugin, s.AsError()
+		}
+		return plugin, errors.New("node is unschedulable")
+	}
+	return "", nil
+}
+
+func (p *predicateManagerImpl) runPreFilterPlugins(ctx context.Context, state *framework.CycleState, plugins []framework.PreFilterPlugin, pod *v1.Pod) (status *framework.Status, plugin string) {
+	for _, pl := range plugins {
+		status = p.runPreFilterPlugin(ctx, pl, state, pod)
+		if !status.IsSuccess() {
+			if status.IsUnschedulable() {
+				return status, plugin
+			}
+			err := status.AsError()
+			log.Logger().Error("failed running PreFilter plugin",
+				zap.String("pluginName", pl.Name()),
+				zap.String("pod", fmt.Sprintf("%s/%s", pod.Namespace, pod.Name)),
+				zap.Error(err))
+			return framework.AsStatus(fmt.Errorf("running PreFilter plugin %q: %w", pl.Name(), err)), plugin

Review comment:
       > if status.IsSuccess() is not true, is it possible that the code is "Skip"? In that case, is it correct to return an error here?
   According to the documentation, Skip is not allowed in this case (only used for bind plugins).
   




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: reviews-unsubscribe@yunikorn.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org