mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-15 22:20:51 +00:00
Add a resource fit scheduler predicate. Set sensible defaults.
This commit is contained in:
@@ -17,6 +17,8 @@ limitations under the License.
|
||||
package scheduler
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/labels"
|
||||
"github.com/GoogleCloudPlatform/kubernetes/pkg/resources"
|
||||
@@ -24,7 +26,20 @@ import (
|
||||
)
|
||||
|
||||
type NodeInfo interface {
|
||||
GetNodeInfo(nodeName string) (api.Minion, error)
|
||||
GetNodeInfo(nodeID string) (*api.Minion, error)
|
||||
}
|
||||
|
||||
type StaticNodeInfo struct {
|
||||
*api.MinionList
|
||||
}
|
||||
|
||||
func (nodes StaticNodeInfo) GetNodeInfo(nodeID string) (*api.Minion, error) {
|
||||
for ix := range nodes.Items {
|
||||
if nodes.Items[ix].ID == nodeID {
|
||||
return &nodes.Items[ix], nil
|
||||
}
|
||||
}
|
||||
return nil, fmt.Errorf("failed to find node: %s", nodeID)
|
||||
}
|
||||
|
||||
type ResourceFit struct {
|
||||
@@ -75,6 +90,13 @@ func (r *ResourceFit) PodFitsResources(pod api.Pod, existingPods []api.Pod, node
|
||||
return fitsCPU && fitsMemory, nil
|
||||
}
|
||||
|
||||
func NewResourceFitPredicate(info NodeInfo) FitPredicate {
|
||||
fit := &ResourceFit{
|
||||
info: info,
|
||||
}
|
||||
return fit.PodFitsResources
|
||||
}
|
||||
|
||||
func PodFitsPorts(pod api.Pod, existingPods []api.Pod, node string) (bool, error) {
|
||||
for _, scheduledPod := range existingPods {
|
||||
for _, container := range pod.DesiredState.Manifest.Containers {
|
||||
|
@@ -26,8 +26,9 @@ import (
|
||||
|
||||
type FakeNodeInfo api.Minion
|
||||
|
||||
func (n FakeNodeInfo) GetNodeInfo(nodeName string) (api.Minion, error) {
|
||||
return api.Minion(n), nil
|
||||
func (n FakeNodeInfo) GetNodeInfo(nodeName string) (*api.Minion, error) {
|
||||
node := api.Minion(n)
|
||||
return &node, nil
|
||||
}
|
||||
|
||||
func makeResources(milliCPU int, memory int) api.NodeResources {
|
||||
|
Reference in New Issue
Block a user