123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- package predicates
- import (
- "k8s.io/api/core/v1"
- "k8s.io/apimachinery/pkg/labels"
- schedulernodeinfo "k8s.io/kubernetes/pkg/scheduler/nodeinfo"
- )
- func FindLabelsInSet(labelsToKeep []string, selector labels.Set) map[string]string {
- aL := make(map[string]string)
- for _, l := range labelsToKeep {
- if selector.Has(l) {
- aL[l] = selector.Get(l)
- }
- }
- return aL
- }
- func AddUnsetLabelsToMap(aL map[string]string, labelsToAdd []string, labelSet labels.Set) {
- for _, l := range labelsToAdd {
-
- if _, exists := aL[l]; exists {
- continue
- }
-
- if labelSet.Has(l) {
- aL[l] = labelSet.Get(l)
- }
- }
- }
- func FilterPodsByNamespace(pods []*v1.Pod, ns string) []*v1.Pod {
- filtered := []*v1.Pod{}
- for _, nsPod := range pods {
- if nsPod.Namespace == ns {
- filtered = append(filtered, nsPod)
- }
- }
- return filtered
- }
- func CreateSelectorFromLabels(aL map[string]string) labels.Selector {
- if aL == nil || len(aL) == 0 {
- return labels.Everything()
- }
- return labels.Set(aL).AsSelector()
- }
- 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
- }
- func SetPredicatesOrderingDuringTest(value []string) func() {
- origVal := predicatesOrdering
- predicatesOrdering = value
- return func() {
- predicatesOrdering = origVal
- }
- }
|