diff --git a/pkg/rescheduler/pods/pods.go b/pkg/rescheduler/pods/pods.go new file mode 100644 index 000000000..b868beeb8 --- /dev/null +++ b/pkg/rescheduler/pods/pods.go @@ -0,0 +1,37 @@ +/* +Copyright 2017 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 pod + +import ( + "k8s.io/kubernetes/pkg/api/v1" + "k8s.io/kubernetes/pkg/client/clientset_generated/clientset" +) + +func ListPodsOnANode(client clientset.Interface, node *v1.Node) ([]*v1.Pod, error) { + podList, err := client.CoreV1().Pods(v1.NamespaceAll).List( + metav1.ListOptions{FieldSelector: fields.SelectorFromSet(fields.Set{"spec.nodeName": node.Name}).String()}) + if err != nil { + return []*v1.Pod{}, err + } + + pods := make([]*v1.Pod, 0) + for i := range podList.Items { + pods = append(pods, &podList.Items[i]) + } + + return pods, nil +}