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/13 15:10:06 UTC

[GitHub] [incubator-yunikorn-k8shim] craigcondit opened a new pull request #310: [WIP] [YUNIKORN-874] Implement PredicateManager.

craigcondit opened a new pull request #310:
URL: https://github.com/apache/incubator-yunikorn-k8shim/pull/310


   ### What is this PR for?
   Initial implementation of predicate manager (rework of predicates for K8S 1.20). Functionality is present, but tests are not yet written. Posting this WIP to gather feedback on approach.
   
   
   ### What type of PR is it?
   * [ ] - Bug Fix
   * [ ] - Improvement
   * [ ] - Feature
   * [ ] - Documentation
   * [ ] - Hot Fix
   * [ ] - Refactoring
   
   ### Todos
   * [x] - Task
   
   ### What is the Jira issue?
   https://issues.apache.org/jira/browse/YUNIKORN-874
   
   ### How should this be tested?
   Basic functionality in a test clister appears to be working.
   
   ### Screenshots (if appropriate)
   
   ### Questions:
   * [ ] - The licenses files need update.
   * [ ] - There is breaking changes for older versions.
   * [ ] - It needs documentation.
   


-- 
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



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

Posted by GitBox <gi...@apache.org>.
craigcondit commented on a change in pull request #310:
URL: https://github.com/apache/incubator-yunikorn-k8shim/pull/310#discussion_r731041083



##########
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
+		}
+	}
+
+	return nil, ""
+}
+
+func (p *predicateManagerImpl) runPreFilterPlugin(ctx context.Context, pl framework.PreFilterPlugin, state *framework.CycleState, pod *v1.Pod) *framework.Status {
+	return pl.PreFilter(ctx, state, pod)
+}
+
+func (p *predicateManagerImpl) runFilterPlugins(ctx context.Context, plugins []framework.FilterPlugin, state *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) (status framework.PluginToStatus, plugin string) {
+	statuses := make(framework.PluginToStatus)
+	plugin = ""
+	for _, pl := range plugins {
+		pluginStatus := p.runFilterPlugin(ctx, pl, state, pod, nodeInfo)
+		if !pluginStatus.IsSuccess() {
+			if plugin == "" {
+				plugin = pl.Name()
+			}
+			if !pluginStatus.IsUnschedulable() {
+				// Filter plugins are not supposed to return any status other than
+				// Success or Unschedulable.
+				errStatus := framework.NewStatus(framework.Error, fmt.Sprintf("running %q filter plugin for pod %q: %v", pl.Name(), pod.Name, pluginStatus.Message()))
+				log.Logger().Error("failed running Filter plugin",
+					zap.String("pluginName", pl.Name()),
+					zap.String("pod", fmt.Sprintf("%s/%s", pod.Namespace, pod.Name)),
+					zap.String("message", pluginStatus.Message()))
+				return map[string]*framework.Status{pl.Name(): errStatus}, pl.Name()
+			}
+			statuses[pl.Name()] = pluginStatus
+		}
+	}
+	return statuses, plugin
+}
+
+func (p *predicateManagerImpl) runFilterPlugin(ctx context.Context, pl framework.FilterPlugin, state *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) *framework.Status {
+	return pl.Filter(ctx, state, pod, nodeInfo)
+}
+
+func NewPredicateManager(handle framework.Handle) PredicateManager {
+	/*
+		Default K8S plugins as of 1.20 that implement PreFilter:
+		   NodeResourcesFit
+		   NodePorts
+		   PodTopologySpread
+		   InterPodAffinity
+		   VolumeBinding
+	*/
+
+	// run only the simpler PreFilter plugins during reservation phase
+	reservationPreFilters := map[string]bool{
+		noderesources.FitName:  true,

Review comment:
       will update in new patch




-- 
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



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

Posted by GitBox <gi...@apache.org>.
craigcondit commented on a change in pull request #310:
URL: https://github.com/apache/incubator-yunikorn-k8shim/pull/310#discussion_r731031756



##########
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
+		}
+	}
+
+	return nil, ""
+}
+
+func (p *predicateManagerImpl) runPreFilterPlugin(ctx context.Context, pl framework.PreFilterPlugin, state *framework.CycleState, pod *v1.Pod) *framework.Status {
+	return pl.PreFilter(ctx, state, pod)
+}
+
+func (p *predicateManagerImpl) runFilterPlugins(ctx context.Context, plugins []framework.FilterPlugin, state *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) (status framework.PluginToStatus, plugin string) {
+	statuses := make(framework.PluginToStatus)
+	plugin = ""
+	for _, pl := range plugins {
+		pluginStatus := p.runFilterPlugin(ctx, pl, state, pod, nodeInfo)
+		if !pluginStatus.IsSuccess() {
+			if plugin == "" {
+				plugin = pl.Name()
+			}
+			if !pluginStatus.IsUnschedulable() {
+				// Filter plugins are not supposed to return any status other than
+				// Success or Unschedulable.
+				errStatus := framework.NewStatus(framework.Error, fmt.Sprintf("running %q filter plugin for pod %q: %v", pl.Name(), pod.Name, pluginStatus.Message()))
+				log.Logger().Error("failed running Filter plugin",
+					zap.String("pluginName", pl.Name()),
+					zap.String("pod", fmt.Sprintf("%s/%s", pod.Namespace, pod.Name)),
+					zap.String("message", pluginStatus.Message()))

Review comment:
       Failure in this context is failure of the plugin, not failure to schedule, so logging this at Error level is in fact correct. I have verified that nothing is logged when pods are not eligible for scheduling.




-- 
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



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

Posted by GitBox <gi...@apache.org>.
craigcondit commented on a change in pull request #310:
URL: https://github.com/apache/incubator-yunikorn-k8shim/pull/310#discussion_r728499976



##########
File path: pkg/plugin/predicates/predicate_manager.go
##########
@@ -0,0 +1,365 @@
+/*
+ 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"
+	fwruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime"
+
+	"github.com/apache/incubator-yunikorn-core/pkg/log"
+)
+
+/*
+Default K8S plugins as of 1.20 that implement PreFilter:
+	NodeResourcesFit
+	NodePorts
+	PodTopologySpread
+	InterPodAffinity
+	VolumeBinding
+*/
+
+// run only the simpler PreFilter plugins during reservation phase
+var reservationPreFilters = map[string]bool{
+	"NodeResourcesFit":  true,
+	"NodePorts":         true,
+	"PodTopologySpread": true,
+	"InterPodAffinity":  true,
+	// VolumeBinding
+}
+
+// run all PreFilter plugins during allocation phase
+var allocationPreFilters = map[string]bool{
+	"*": true,
+}
+
+/*
+Default K8S plugins as of 1.20 that implement Filter:
+	NodeUnschedulable
+	NodeName
+	TaintToleration
+	NodeAffinity
+	NodePorts
+	NodeResourcesFit
+	VolumeRestrictions
+	EBSLimits
+	GCEPDLimits
+	NodeVolumeLimits
+	AzureDiskLimits
+	VolumeBinding
+	VolumeZone
+	PodTopologySpread
+	InterPodAffinity
+*/
+
+// run only the simpler Filter plugins during reservation phase
+var reservationFilters = map[string]bool{
+	"NodeUnschedulable": true,
+	"NodeName":          true,
+	"TaintToleration":   true,
+	"NodeAffinity":      true,
+	"NodePorts":         true,
+	"NodeResourcesFit":  true,
+	// VolumeRestrictions
+	// EBSLimits
+	// GCEPDLimits
+	// NodeVolumeLimits
+	// AzureDiskLimits
+	// VolumeBinding
+	// VolumeZone
+	"PodTopologySpread": true,
+	"InterPodAffinity":  true,

Review comment:
       nodelabel functionality has been rolled into the nodeaffinity plugin.




-- 
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



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

Posted by GitBox <gi...@apache.org>.
craigcondit commented on a change in pull request #310:
URL: https://github.com/apache/incubator-yunikorn-k8shim/pull/310#discussion_r731042253



##########
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
+		}
+	}
+
+	return nil, ""
+}
+
+func (p *predicateManagerImpl) runPreFilterPlugin(ctx context.Context, pl framework.PreFilterPlugin, state *framework.CycleState, pod *v1.Pod) *framework.Status {
+	return pl.PreFilter(ctx, state, pod)
+}
+
+func (p *predicateManagerImpl) runFilterPlugins(ctx context.Context, plugins []framework.FilterPlugin, state *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) (status framework.PluginToStatus, plugin string) {
+	statuses := make(framework.PluginToStatus)
+	plugin = ""
+	for _, pl := range plugins {
+		pluginStatus := p.runFilterPlugin(ctx, pl, state, pod, nodeInfo)
+		if !pluginStatus.IsSuccess() {
+			if plugin == "" {
+				plugin = pl.Name()
+			}
+			if !pluginStatus.IsUnschedulable() {
+				// Filter plugins are not supposed to return any status other than
+				// Success or Unschedulable.
+				errStatus := framework.NewStatus(framework.Error, fmt.Sprintf("running %q filter plugin for pod %q: %v", pl.Name(), pod.Name, pluginStatus.Message()))
+				log.Logger().Error("failed running Filter plugin",
+					zap.String("pluginName", pl.Name()),
+					zap.String("pod", fmt.Sprintf("%s/%s", pod.Namespace, pod.Name)),
+					zap.String("message", pluginStatus.Message()))
+				return map[string]*framework.Status{pl.Name(): errStatus}, pl.Name()
+			}
+			statuses[pl.Name()] = pluginStatus
+		}
+	}
+	return statuses, plugin
+}
+
+func (p *predicateManagerImpl) runFilterPlugin(ctx context.Context, pl framework.FilterPlugin, state *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) *framework.Status {
+	return pl.Filter(ctx, state, pod, nodeInfo)
+}
+
+func NewPredicateManager(handle framework.Handle) PredicateManager {
+	/*
+		Default K8S plugins as of 1.20 that implement PreFilter:
+		   NodeResourcesFit
+		   NodePorts
+		   PodTopologySpread
+		   InterPodAffinity
+		   VolumeBinding
+	*/
+
+	// run only the simpler PreFilter plugins during reservation phase
+	reservationPreFilters := map[string]bool{
+		noderesources.FitName:  true,
+		nodeports.Name:         true,
+		podtopologyspread.Name: true,
+		interpodaffinity.Name:  true,
+		// VolumeBinding
+	}
+
+	// run all PreFilter plugins during allocation phase
+	allocationPreFilters := map[string]bool{
+		"*": true,
+	}
+
+	/*
+		Default K8S plugins as of 1.20 that implement Filter:
+		    NodeUnschedulable
+			NodeName
+			TaintToleration
+			NodeAffinity
+			NodePorts
+			NodeResourcesFit
+			VolumeRestrictions
+			EBSLimits
+			GCEPDLimits
+			NodeVolumeLimits
+			AzureDiskLimits
+			VolumeBinding
+			VolumeZone
+			PodTopologySpread
+			InterPodAffinity
+	*/
+
+	// run only the simpler Filter plugins during reservation phase
+	reservationFilters := map[string]bool{
+		nodeunschedulable.Name: true,
+		nodename.Name:          true,
+		tainttoleration.Name:   true,
+		nodeaffinity.Name:      true,
+		nodeports.Name:         true,
+		noderesources.FitName:  true,

Review comment:
       will update in new patch.
   
   > BTW, why both Filter and PreFilter has `noderesources` check?
   
   Some plugins implement both Filter and PreFilter stages and so must be run in the same way.




-- 
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



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

Posted by GitBox <gi...@apache.org>.
yangwwei commented on a change in pull request #310:
URL: https://github.com/apache/incubator-yunikorn-k8shim/pull/310#discussion_r728508910



##########
File path: pkg/cache/context.go
##########
@@ -75,9 +77,15 @@ func NewContext(apis client.APIProvider) *Context {
 	// init the controllers and plugins (need the cache)
 	ctx.nodes = newSchedulerNodes(apis.GetAPIs().SchedulerAPI, ctx.schedulerCache)
 
-	/* FUTURE YUNIKORN-872 replace this with predicateManager initilization in YUNIKORN-874
-	ctx.predictor = plugin.NewPredictor(schedulercache.GetPluginArgs(), apis.IsTestingMode())
-	*/
+	// create the predicate manager
+	if !apis.IsTestingMode() {
+		sharedLister := support.NewSharedLister(ctx.schedulerCache)
+		k8sClient := client.NewKubeClient(conf.GetSchedulerConf().KubeConfig)
+		clientSet := k8sClient.GetClientSet()
+		informerFactory := informers.NewSharedInformerFactory(clientSet, 0)

Review comment:
       can we reuse the `clientSet` and `informerFactory` from apiProvider? 
   ```
   apiProvider.GetAPIs().KubeClient.GetClientSet()
   apiProvider.GetAPIs().InformerFactory
   ```

##########
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

Review comment:
       shall we format the return message with more meaningful info than just `return status, plugin` here? Because we will need to expose those messages via K8s events.  BTW, one thing missing in this patch is to publish events to k8s:
   
   ```
   events.GetRecorder().Eventf(pod, v1.EventTypeWarning, 
     "FailedScheduling", "predicate is not satisfied, error: %s", err.Error())
   ```

##########
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
+		}
+	}
+
+	return nil, ""
+}
+
+func (p *predicateManagerImpl) runPreFilterPlugin(ctx context.Context, pl framework.PreFilterPlugin, state *framework.CycleState, pod *v1.Pod) *framework.Status {
+	return pl.PreFilter(ctx, state, pod)
+}
+
+func (p *predicateManagerImpl) runFilterPlugins(ctx context.Context, plugins []framework.FilterPlugin, state *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) (status framework.PluginToStatus, plugin string) {
+	statuses := make(framework.PluginToStatus)
+	plugin = ""
+	for _, pl := range plugins {
+		pluginStatus := p.runFilterPlugin(ctx, pl, state, pod, nodeInfo)
+		if !pluginStatus.IsSuccess() {
+			if plugin == "" {
+				plugin = pl.Name()
+			}
+			if !pluginStatus.IsUnschedulable() {
+				// Filter plugins are not supposed to return any status other than
+				// Success or Unschedulable.
+				errStatus := framework.NewStatus(framework.Error, fmt.Sprintf("running %q filter plugin for pod %q: %v", pl.Name(), pod.Name, pluginStatus.Message()))
+				log.Logger().Error("failed running Filter plugin",
+					zap.String("pluginName", pl.Name()),
+					zap.String("pod", fmt.Sprintf("%s/%s", pod.Namespace, pod.Name)),
+					zap.String("message", pluginStatus.Message()))

Review comment:
       we can't print the error log here, it will be overwhelming. 
   this can fail when a pod has node-affinity, this will get printed every time we try to place the pod on a node without a certain label, endlessly. 
   suggest to remove it

##########
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:
       Looking at the possible code:
   
   ```
   Success
   Error
   Unschedulable
   UnschedulableAndUnresolvable
   Wait
   Skip
   ```
   
   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?

##########
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
+		}
+	}
+
+	return nil, ""
+}
+
+func (p *predicateManagerImpl) runPreFilterPlugin(ctx context.Context, pl framework.PreFilterPlugin, state *framework.CycleState, pod *v1.Pod) *framework.Status {
+	return pl.PreFilter(ctx, state, pod)
+}
+
+func (p *predicateManagerImpl) runFilterPlugins(ctx context.Context, plugins []framework.FilterPlugin, state *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) (status framework.PluginToStatus, plugin string) {
+	statuses := make(framework.PluginToStatus)
+	plugin = ""
+	for _, pl := range plugins {
+		pluginStatus := p.runFilterPlugin(ctx, pl, state, pod, nodeInfo)
+		if !pluginStatus.IsSuccess() {
+			if plugin == "" {
+				plugin = pl.Name()
+			}
+			if !pluginStatus.IsUnschedulable() {
+				// Filter plugins are not supposed to return any status other than
+				// Success or Unschedulable.
+				errStatus := framework.NewStatus(framework.Error, fmt.Sprintf("running %q filter plugin for pod %q: %v", pl.Name(), pod.Name, pluginStatus.Message()))
+				log.Logger().Error("failed running Filter plugin",
+					zap.String("pluginName", pl.Name()),
+					zap.String("pod", fmt.Sprintf("%s/%s", pod.Namespace, pod.Name)),
+					zap.String("message", pluginStatus.Message()))
+				return map[string]*framework.Status{pl.Name(): errStatus}, pl.Name()
+			}
+			statuses[pl.Name()] = pluginStatus
+		}
+	}
+	return statuses, plugin
+}
+
+func (p *predicateManagerImpl) runFilterPlugin(ctx context.Context, pl framework.FilterPlugin, state *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) *framework.Status {
+	return pl.Filter(ctx, state, pod, nodeInfo)
+}
+
+func NewPredicateManager(handle framework.Handle) PredicateManager {
+	/*
+		Default K8S plugins as of 1.20 that implement PreFilter:
+		   NodeResourcesFit
+		   NodePorts
+		   PodTopologySpread
+		   InterPodAffinity
+		   VolumeBinding
+	*/
+
+	// run only the simpler PreFilter plugins during reservation phase
+	reservationPreFilters := map[string]bool{
+		noderesources.FitName:  true,

Review comment:
       we can't have this one, when we do reservation, the node resource is always not enough for the pod

##########
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
+		}
+	}
+
+	return nil, ""
+}
+
+func (p *predicateManagerImpl) runPreFilterPlugin(ctx context.Context, pl framework.PreFilterPlugin, state *framework.CycleState, pod *v1.Pod) *framework.Status {
+	return pl.PreFilter(ctx, state, pod)
+}
+
+func (p *predicateManagerImpl) runFilterPlugins(ctx context.Context, plugins []framework.FilterPlugin, state *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) (status framework.PluginToStatus, plugin string) {
+	statuses := make(framework.PluginToStatus)
+	plugin = ""
+	for _, pl := range plugins {
+		pluginStatus := p.runFilterPlugin(ctx, pl, state, pod, nodeInfo)
+		if !pluginStatus.IsSuccess() {
+			if plugin == "" {
+				plugin = pl.Name()
+			}
+			if !pluginStatus.IsUnschedulable() {
+				// Filter plugins are not supposed to return any status other than
+				// Success or Unschedulable.
+				errStatus := framework.NewStatus(framework.Error, fmt.Sprintf("running %q filter plugin for pod %q: %v", pl.Name(), pod.Name, pluginStatus.Message()))
+				log.Logger().Error("failed running Filter plugin",
+					zap.String("pluginName", pl.Name()),
+					zap.String("pod", fmt.Sprintf("%s/%s", pod.Namespace, pod.Name)),
+					zap.String("message", pluginStatus.Message()))
+				return map[string]*framework.Status{pl.Name(): errStatus}, pl.Name()
+			}
+			statuses[pl.Name()] = pluginStatus
+		}
+	}
+	return statuses, plugin
+}
+
+func (p *predicateManagerImpl) runFilterPlugin(ctx context.Context, pl framework.FilterPlugin, state *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) *framework.Status {
+	return pl.Filter(ctx, state, pod, nodeInfo)
+}
+
+func NewPredicateManager(handle framework.Handle) PredicateManager {
+	/*
+		Default K8S plugins as of 1.20 that implement PreFilter:
+		   NodeResourcesFit
+		   NodePorts
+		   PodTopologySpread
+		   InterPodAffinity
+		   VolumeBinding
+	*/
+
+	// run only the simpler PreFilter plugins during reservation phase
+	reservationPreFilters := map[string]bool{
+		noderesources.FitName:  true,
+		nodeports.Name:         true,
+		podtopologyspread.Name: true,
+		interpodaffinity.Name:  true,
+		// VolumeBinding
+	}
+
+	// run all PreFilter plugins during allocation phase
+	allocationPreFilters := map[string]bool{
+		"*": true,
+	}
+
+	/*
+		Default K8S plugins as of 1.20 that implement Filter:
+		    NodeUnschedulable
+			NodeName
+			TaintToleration
+			NodeAffinity
+			NodePorts
+			NodeResourcesFit
+			VolumeRestrictions
+			EBSLimits
+			GCEPDLimits
+			NodeVolumeLimits
+			AzureDiskLimits
+			VolumeBinding
+			VolumeZone
+			PodTopologySpread
+			InterPodAffinity
+	*/
+
+	// run only the simpler Filter plugins during reservation phase
+	reservationFilters := map[string]bool{
+		nodeunschedulable.Name: true,
+		nodename.Name:          true,
+		tainttoleration.Name:   true,
+		nodeaffinity.Name:      true,
+		nodeports.Name:         true,
+		noderesources.FitName:  true,

Review comment:
       Need to remove this one, same as above
   BTW, why both Filter and PreFilter has `noderesources` check? 




-- 
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



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

Posted by GitBox <gi...@apache.org>.
ycr-oss commented on a change in pull request #310:
URL: https://github.com/apache/incubator-yunikorn-k8shim/pull/310#discussion_r728469666



##########
File path: pkg/plugin/predicates/predicate_manager.go
##########
@@ -0,0 +1,365 @@
+/*
+ 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"
+	fwruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime"
+
+	"github.com/apache/incubator-yunikorn-core/pkg/log"
+)
+
+/*
+Default K8S plugins as of 1.20 that implement PreFilter:
+	NodeResourcesFit
+	NodePorts
+	PodTopologySpread
+	InterPodAffinity
+	VolumeBinding
+*/
+
+// run only the simpler PreFilter plugins during reservation phase
+var reservationPreFilters = map[string]bool{
+	"NodeResourcesFit":  true,
+	"NodePorts":         true,
+	"PodTopologySpread": true,
+	"InterPodAffinity":  true,
+	// VolumeBinding
+}
+
+// run all PreFilter plugins during allocation phase
+var allocationPreFilters = map[string]bool{
+	"*": true,
+}
+
+/*
+Default K8S plugins as of 1.20 that implement Filter:
+	NodeUnschedulable
+	NodeName
+	TaintToleration
+	NodeAffinity
+	NodePorts
+	NodeResourcesFit
+	VolumeRestrictions
+	EBSLimits
+	GCEPDLimits
+	NodeVolumeLimits
+	AzureDiskLimits
+	VolumeBinding
+	VolumeZone
+	PodTopologySpread
+	InterPodAffinity
+*/
+
+// run only the simpler Filter plugins during reservation phase
+var reservationFilters = map[string]bool{
+	"NodeUnschedulable": true,
+	"NodeName":          true,
+	"TaintToleration":   true,
+	"NodeAffinity":      true,
+	"NodePorts":         true,
+	"NodeResourcesFit":  true,
+	// VolumeRestrictions
+	// EBSLimits
+	// GCEPDLimits
+	// NodeVolumeLimits
+	// AzureDiskLimits
+	// VolumeBinding
+	// VolumeZone
+	"PodTopologySpread": true,
+	"InterPodAffinity":  true,

Review comment:
       Doesn't the [nodelabel](https://github.com/kubernetes/kubernetes/blob/v1.20.11/pkg/scheduler/framework/plugins/nodelabel/node_label.go) filter make sense to be considered during reservation?




-- 
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



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

Posted by GitBox <gi...@apache.org>.
craigcondit commented on pull request #310:
URL: https://github.com/apache/incubator-yunikorn-k8shim/pull/310#issuecomment-942774664


   Updated PR with comprehensive unit tests. The e2e tests also now compile, but I have not been able to verify them as of yet.


-- 
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



[GitHub] [incubator-yunikorn-k8shim] ycr-oss commented on pull request #310: [YUNIKORN-874] Implement PredicateManager.

Posted by GitBox <gi...@apache.org>.
ycr-oss commented on pull request #310:
URL: https://github.com/apache/incubator-yunikorn-k8shim/pull/310#issuecomment-942779064


   I'll review this evening and also try it out. Thanks a lot for getting it done so quickly


-- 
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



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

Posted by GitBox <gi...@apache.org>.
craigcondit commented on pull request #310:
URL: https://github.com/apache/incubator-yunikorn-k8shim/pull/310#issuecomment-942776337


   @ycr-oss, the PR is now pretty close to ready. Can you review?


-- 
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



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

Posted by GitBox <gi...@apache.org>.
ycr-oss commented on a change in pull request #310:
URL: https://github.com/apache/incubator-yunikorn-k8shim/pull/310#discussion_r728504513



##########
File path: pkg/plugin/predicates/predicate_manager.go
##########
@@ -0,0 +1,365 @@
+/*
+ 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"
+	fwruntime "k8s.io/kubernetes/pkg/scheduler/framework/runtime"
+
+	"github.com/apache/incubator-yunikorn-core/pkg/log"
+)
+
+/*
+Default K8S plugins as of 1.20 that implement PreFilter:
+	NodeResourcesFit
+	NodePorts
+	PodTopologySpread
+	InterPodAffinity
+	VolumeBinding
+*/
+
+// run only the simpler PreFilter plugins during reservation phase
+var reservationPreFilters = map[string]bool{
+	"NodeResourcesFit":  true,
+	"NodePorts":         true,
+	"PodTopologySpread": true,
+	"InterPodAffinity":  true,
+	// VolumeBinding
+}
+
+// run all PreFilter plugins during allocation phase
+var allocationPreFilters = map[string]bool{
+	"*": true,
+}
+
+/*
+Default K8S plugins as of 1.20 that implement Filter:
+	NodeUnschedulable
+	NodeName
+	TaintToleration
+	NodeAffinity
+	NodePorts
+	NodeResourcesFit
+	VolumeRestrictions
+	EBSLimits
+	GCEPDLimits
+	NodeVolumeLimits
+	AzureDiskLimits
+	VolumeBinding
+	VolumeZone
+	PodTopologySpread
+	InterPodAffinity
+*/
+
+// run only the simpler Filter plugins during reservation phase
+var reservationFilters = map[string]bool{
+	"NodeUnschedulable": true,
+	"NodeName":          true,
+	"TaintToleration":   true,
+	"NodeAffinity":      true,
+	"NodePorts":         true,
+	"NodeResourcesFit":  true,
+	// VolumeRestrictions
+	// EBSLimits
+	// GCEPDLimits
+	// NodeVolumeLimits
+	// AzureDiskLimits
+	// VolumeBinding
+	// VolumeZone
+	"PodTopologySpread": true,
+	"InterPodAffinity":  true,

Review comment:
       I didn't know that. You are correct!




-- 
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



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

Posted by GitBox <gi...@apache.org>.
craigcondit commented on pull request #310:
URL: https://github.com/apache/incubator-yunikorn-k8shim/pull/310#issuecomment-945936228


   > @yangwwei, I've made the requested changes. Can you re-review?
   
   Actually, hold on that.. There's something not quite right here that I'm trying to track down.


-- 
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



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

Posted by GitBox <gi...@apache.org>.
craigcondit commented on a change in pull request #310:
URL: https://github.com/apache/incubator-yunikorn-k8shim/pull/310#discussion_r731062076



##########
File path: pkg/cache/context.go
##########
@@ -75,9 +77,15 @@ func NewContext(apis client.APIProvider) *Context {
 	// init the controllers and plugins (need the cache)
 	ctx.nodes = newSchedulerNodes(apis.GetAPIs().SchedulerAPI, ctx.schedulerCache)
 
-	/* FUTURE YUNIKORN-872 replace this with predicateManager initilization in YUNIKORN-874
-	ctx.predictor = plugin.NewPredictor(schedulercache.GetPluginArgs(), apis.IsTestingMode())
-	*/
+	// create the predicate manager
+	if !apis.IsTestingMode() {
+		sharedLister := support.NewSharedLister(ctx.schedulerCache)
+		k8sClient := client.NewKubeClient(conf.GetSchedulerConf().KubeConfig)
+		clientSet := k8sClient.GetClientSet()
+		informerFactory := informers.NewSharedInformerFactory(clientSet, 0)

Review comment:
       Updated PR.

##########
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

Review comment:
       Updated PR.

##########
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
+		}
+	}
+
+	return nil, ""
+}
+
+func (p *predicateManagerImpl) runPreFilterPlugin(ctx context.Context, pl framework.PreFilterPlugin, state *framework.CycleState, pod *v1.Pod) *framework.Status {
+	return pl.PreFilter(ctx, state, pod)
+}
+
+func (p *predicateManagerImpl) runFilterPlugins(ctx context.Context, plugins []framework.FilterPlugin, state *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) (status framework.PluginToStatus, plugin string) {
+	statuses := make(framework.PluginToStatus)
+	plugin = ""
+	for _, pl := range plugins {
+		pluginStatus := p.runFilterPlugin(ctx, pl, state, pod, nodeInfo)
+		if !pluginStatus.IsSuccess() {
+			if plugin == "" {
+				plugin = pl.Name()
+			}
+			if !pluginStatus.IsUnschedulable() {
+				// Filter plugins are not supposed to return any status other than
+				// Success or Unschedulable.
+				errStatus := framework.NewStatus(framework.Error, fmt.Sprintf("running %q filter plugin for pod %q: %v", pl.Name(), pod.Name, pluginStatus.Message()))
+				log.Logger().Error("failed running Filter plugin",
+					zap.String("pluginName", pl.Name()),
+					zap.String("pod", fmt.Sprintf("%s/%s", pod.Namespace, pod.Name)),
+					zap.String("message", pluginStatus.Message()))
+				return map[string]*framework.Status{pl.Name(): errStatus}, pl.Name()
+			}
+			statuses[pl.Name()] = pluginStatus
+		}
+	}
+	return statuses, plugin
+}
+
+func (p *predicateManagerImpl) runFilterPlugin(ctx context.Context, pl framework.FilterPlugin, state *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) *framework.Status {
+	return pl.Filter(ctx, state, pod, nodeInfo)
+}
+
+func NewPredicateManager(handle framework.Handle) PredicateManager {
+	/*
+		Default K8S plugins as of 1.20 that implement PreFilter:
+		   NodeResourcesFit
+		   NodePorts
+		   PodTopologySpread
+		   InterPodAffinity
+		   VolumeBinding
+	*/
+
+	// run only the simpler PreFilter plugins during reservation phase
+	reservationPreFilters := map[string]bool{
+		noderesources.FitName:  true,

Review comment:
       Updated PR.

##########
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
+		}
+	}
+
+	return nil, ""
+}
+
+func (p *predicateManagerImpl) runPreFilterPlugin(ctx context.Context, pl framework.PreFilterPlugin, state *framework.CycleState, pod *v1.Pod) *framework.Status {
+	return pl.PreFilter(ctx, state, pod)
+}
+
+func (p *predicateManagerImpl) runFilterPlugins(ctx context.Context, plugins []framework.FilterPlugin, state *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) (status framework.PluginToStatus, plugin string) {
+	statuses := make(framework.PluginToStatus)
+	plugin = ""
+	for _, pl := range plugins {
+		pluginStatus := p.runFilterPlugin(ctx, pl, state, pod, nodeInfo)
+		if !pluginStatus.IsSuccess() {
+			if plugin == "" {
+				plugin = pl.Name()
+			}
+			if !pluginStatus.IsUnschedulable() {
+				// Filter plugins are not supposed to return any status other than
+				// Success or Unschedulable.
+				errStatus := framework.NewStatus(framework.Error, fmt.Sprintf("running %q filter plugin for pod %q: %v", pl.Name(), pod.Name, pluginStatus.Message()))
+				log.Logger().Error("failed running Filter plugin",
+					zap.String("pluginName", pl.Name()),
+					zap.String("pod", fmt.Sprintf("%s/%s", pod.Namespace, pod.Name)),
+					zap.String("message", pluginStatus.Message()))
+				return map[string]*framework.Status{pl.Name(): errStatus}, pl.Name()
+			}
+			statuses[pl.Name()] = pluginStatus
+		}
+	}
+	return statuses, plugin
+}
+
+func (p *predicateManagerImpl) runFilterPlugin(ctx context.Context, pl framework.FilterPlugin, state *framework.CycleState, pod *v1.Pod, nodeInfo *framework.NodeInfo) *framework.Status {
+	return pl.Filter(ctx, state, pod, nodeInfo)
+}
+
+func NewPredicateManager(handle framework.Handle) PredicateManager {
+	/*
+		Default K8S plugins as of 1.20 that implement PreFilter:
+		   NodeResourcesFit
+		   NodePorts
+		   PodTopologySpread
+		   InterPodAffinity
+		   VolumeBinding
+	*/
+
+	// run only the simpler PreFilter plugins during reservation phase
+	reservationPreFilters := map[string]bool{
+		noderesources.FitName:  true,
+		nodeports.Name:         true,
+		podtopologyspread.Name: true,
+		interpodaffinity.Name:  true,
+		// VolumeBinding
+	}
+
+	// run all PreFilter plugins during allocation phase
+	allocationPreFilters := map[string]bool{
+		"*": true,
+	}
+
+	/*
+		Default K8S plugins as of 1.20 that implement Filter:
+		    NodeUnschedulable
+			NodeName
+			TaintToleration
+			NodeAffinity
+			NodePorts
+			NodeResourcesFit
+			VolumeRestrictions
+			EBSLimits
+			GCEPDLimits
+			NodeVolumeLimits
+			AzureDiskLimits
+			VolumeBinding
+			VolumeZone
+			PodTopologySpread
+			InterPodAffinity
+	*/
+
+	// run only the simpler Filter plugins during reservation phase
+	reservationFilters := map[string]bool{
+		nodeunschedulable.Name: true,
+		nodename.Name:          true,
+		tainttoleration.Name:   true,
+		nodeaffinity.Name:      true,
+		nodeports.Name:         true,
+		noderesources.FitName:  true,

Review comment:
       Updated PR.




-- 
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



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

Posted by GitBox <gi...@apache.org>.
craigcondit commented on pull request #310:
URL: https://github.com/apache/incubator-yunikorn-k8shim/pull/310#issuecomment-945973355


   Added new patch with better messaging in case of predicate failure.


-- 
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



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

Posted by GitBox <gi...@apache.org>.
craigcondit commented on a change in pull request #310:
URL: https://github.com/apache/incubator-yunikorn-k8shim/pull/310#discussion_r731050205



##########
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

Review comment:
       I can add this in a later patch, but won't this just spam K8S with events? We are only checking a specific pod / node combination so in the case where we have many nodes and many pods, we'll get a warning event for every node that a pod doesn't fit, even if the pod is ultimately scheduled.




-- 
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



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

Posted by GitBox <gi...@apache.org>.
craigcondit commented on a change in pull request #310:
URL: https://github.com/apache/incubator-yunikorn-k8shim/pull/310#discussion_r731053971



##########
File path: pkg/cache/context.go
##########
@@ -75,9 +77,15 @@ func NewContext(apis client.APIProvider) *Context {
 	// init the controllers and plugins (need the cache)
 	ctx.nodes = newSchedulerNodes(apis.GetAPIs().SchedulerAPI, ctx.schedulerCache)
 
-	/* FUTURE YUNIKORN-872 replace this with predicateManager initilization in YUNIKORN-874
-	ctx.predictor = plugin.NewPredictor(schedulercache.GetPluginArgs(), apis.IsTestingMode())
-	*/
+	// create the predicate manager
+	if !apis.IsTestingMode() {
+		sharedLister := support.NewSharedLister(ctx.schedulerCache)
+		k8sClient := client.NewKubeClient(conf.GetSchedulerConf().KubeConfig)
+		clientSet := k8sClient.GetClientSet()
+		informerFactory := informers.NewSharedInformerFactory(clientSet, 0)

Review comment:
       will update in new patch




-- 
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



[GitHub] [incubator-yunikorn-k8shim] yangwwei merged pull request #310: [YUNIKORN-874] Implement PredicateManager.

Posted by GitBox <gi...@apache.org>.
yangwwei merged pull request #310:
URL: https://github.com/apache/incubator-yunikorn-k8shim/pull/310


   


-- 
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



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

Posted by GitBox <gi...@apache.org>.
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



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

Posted by GitBox <gi...@apache.org>.
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



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

Posted by GitBox <gi...@apache.org>.
craigcondit commented on pull request #310:
URL: https://github.com/apache/incubator-yunikorn-k8shim/pull/310#issuecomment-945901541


   @yangwwei, I've made the requested changes. Can you re-review?


-- 
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



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

Posted by GitBox <gi...@apache.org>.
craigcondit removed a comment on pull request #310:
URL: https://github.com/apache/incubator-yunikorn-k8shim/pull/310#issuecomment-945936228


   > @yangwwei, I've made the requested changes. Can you re-review?
   
   Actually, hold on that.. There's something not quite right here that I'm trying to track down.


-- 
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