From 6aaf0bb41b36efda6088e8389e71ae4ef8abd522 Mon Sep 17 00:00:00 2001 From: Wei Huang Date: Thu, 9 Jan 2020 11:53:15 -0800 Subject: [PATCH] Cleanup scheduler/algorithm/predicates package --- pkg/scheduler/algorithm/predicates/BUILD | 7 +--- .../algorithm/predicates/metadata.go | 21 ------------ .../algorithm/predicates/predicates.go | 10 ++++-- pkg/scheduler/algorithm/predicates/utils.go | 34 ------------------- .../algorithm/predicates/utils_test.go | 17 ---------- 5 files changed, 9 insertions(+), 80 deletions(-) delete mode 100644 pkg/scheduler/algorithm/predicates/metadata.go delete mode 100644 pkg/scheduler/algorithm/predicates/utils.go delete mode 100644 pkg/scheduler/algorithm/predicates/utils_test.go diff --git a/pkg/scheduler/algorithm/predicates/BUILD b/pkg/scheduler/algorithm/predicates/BUILD index 655aad19cca..41f08117442 100644 --- a/pkg/scheduler/algorithm/predicates/BUILD +++ b/pkg/scheduler/algorithm/predicates/BUILD @@ -4,9 +4,7 @@ go_library( name = "go_default_library", srcs = [ "error.go", - "metadata.go", "predicates.go", - "utils.go", ], importpath = "k8s.io/kubernetes/pkg/scheduler/algorithm/predicates", visibility = ["//visibility:public"], @@ -25,10 +23,7 @@ go_library( go_test( name = "go_default_test", - srcs = [ - "predicates_test.go", - "utils_test.go", - ], + srcs = ["predicates_test.go"], embed = [":go_default_library"], deps = [ "//pkg/apis/core:go_default_library", diff --git a/pkg/scheduler/algorithm/predicates/metadata.go b/pkg/scheduler/algorithm/predicates/metadata.go deleted file mode 100644 index 513eb9e5364..00000000000 --- a/pkg/scheduler/algorithm/predicates/metadata.go +++ /dev/null @@ -1,21 +0,0 @@ -/* -Copyright 2016 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package predicates - -// Metadata interface represents anything that can access a predicate metadata. -// DEPRECATED. -type Metadata interface{} diff --git a/pkg/scheduler/algorithm/predicates/predicates.go b/pkg/scheduler/algorithm/predicates/predicates.go index 3a22337f2bc..59a7dfdb686 100644 --- a/pkg/scheduler/algorithm/predicates/predicates.go +++ b/pkg/scheduler/algorithm/predicates/predicates.go @@ -108,6 +108,10 @@ func Ordering() []string { return predicatesOrdering } +// Metadata interface represents anything that can access a predicate metadata. +// DEPRECATED. +type Metadata interface{} + // FitPredicate is a function that indicates if a pod fits into an existing node. // The failure information is given by the error. type FitPredicate func(pod *v1.Pod, meta Metadata, nodeInfo *schedulernodeinfo.NodeInfo) (bool, []PredicateFailureReason, error) @@ -278,8 +282,10 @@ func PodFitsHostPortsPredicate(pod *v1.Pod, meta []*v1.ContainerPort, nodeInfo * existingPorts := nodeInfo.UsedPorts() // try to see whether existingPorts and wantPorts will conflict or not - if portsConflict(existingPorts, wantPorts) { - return false, []PredicateFailureReason{ErrPodNotFitsHostPorts}, nil + for _, cp := range wantPorts { + if existingPorts.CheckConflict(cp.HostIP, string(cp.Protocol), cp.HostPort) { + return false, []PredicateFailureReason{ErrPodNotFitsHostPorts}, nil + } } return true, nil, nil diff --git a/pkg/scheduler/algorithm/predicates/utils.go b/pkg/scheduler/algorithm/predicates/utils.go deleted file mode 100644 index 167ada37340..00000000000 --- a/pkg/scheduler/algorithm/predicates/utils.go +++ /dev/null @@ -1,34 +0,0 @@ -/* -Copyright 2016 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package predicates - -import ( - v1 "k8s.io/api/core/v1" - schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo" -) - -// portsConflict check whether existingPorts and wantPorts conflict with each other -// return true if we have a conflict -func portsConflict(existingPorts schedulernodeinfo.HostPortInfo, wantPorts []*v1.ContainerPort) bool { - for _, cp := range wantPorts { - if existingPorts.CheckConflict(cp.HostIP, string(cp.Protocol), cp.HostPort) { - return true - } - } - - return false -} diff --git a/pkg/scheduler/algorithm/predicates/utils_test.go b/pkg/scheduler/algorithm/predicates/utils_test.go deleted file mode 100644 index b50b697c918..00000000000 --- a/pkg/scheduler/algorithm/predicates/utils_test.go +++ /dev/null @@ -1,17 +0,0 @@ -/* -Copyright 2016 The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package predicates