improve memory footprint of daemonset simulate

pull/8/head
Michal Fojtik 2018-06-08 14:21:22 +02:00
parent 0647cff9ff
commit 60ef68c87d
No known key found for this signature in database
GPG Key ID: 172B61E538AAC0EE
2 changed files with 13 additions and 1 deletions

View File

@ -33,6 +33,7 @@ go_library(
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/labels:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/intstr:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/json:go_default_library",

View File

@ -30,6 +30,7 @@ import (
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/types"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/util/sets"
@ -1274,7 +1275,8 @@ func (dsc *DaemonSetsController) simulate(newPod *v1.Pod, node *v1.Node, ds *app
}
// ignore pods that belong to the daemonset when taking into account whether
// a daemonset should bind to a node.
if metav1.IsControlledBy(pod, ds) {
// TODO: replace this with metav1.IsControlledBy() in 1.12
if isControlledByDaemonSet(pod, ds.GetUID()) {
continue
}
pods = append(pods, pod)
@ -1496,3 +1498,12 @@ func (o podByCreationTimestampAndPhase) Less(i, j int) bool {
}
return o[i].CreationTimestamp.Before(&o[j].CreationTimestamp)
}
func isControlledByDaemonSet(p *v1.Pod, uuid types.UID) bool {
for _, ref := range p.OwnerReferences {
if ref.Controller != nil && *ref.Controller && ref.UID == uuid {
return true
}
}
return false
}