diff --git a/pkg/controllers/allocation/filter.go b/pkg/controllers/allocation/filter.go index b554cbaee51c..5f8eb1212aa4 100644 --- a/pkg/controllers/allocation/filter.go +++ b/pkg/controllers/allocation/filter.go @@ -65,6 +65,9 @@ func (f *Filter) isUnschedulable(p *v1.Pod) error { if pod.IsOwnedByDaemonSet(p) { return fmt.Errorf("owned by daemonset") } + if pod.IsOwnedByNode(p) { + return fmt.Errorf("owned by node") + } return nil } diff --git a/pkg/controllers/node/emptiness.go b/pkg/controllers/node/emptiness.go index a76aa4c90d2c..5207a36d3878 100644 --- a/pkg/controllers/node/emptiness.go +++ b/pkg/controllers/node/emptiness.go @@ -90,7 +90,7 @@ func (r *Emptiness) isEmpty(ctx context.Context, n *v1.Node) (bool, error) { if pod.HasFailed(&p) { continue } - if !pod.IsOwnedByDaemonSet(&p) { + if !pod.IsOwnedByDaemonSet(&p) && !pod.IsOwnedByNode(&p) { return false, nil } } diff --git a/pkg/utils/pod/scheduling.go b/pkg/utils/pod/scheduling.go index f2e029ade4f5..9f760ef76d44 100644 --- a/pkg/utils/pod/scheduling.go +++ b/pkg/utils/pod/scheduling.go @@ -33,9 +33,20 @@ func HasFailed(pod *v1.Pod) bool { } func IsOwnedByDaemonSet(pod *v1.Pod) bool { - for _, ignoredOwner := range []schema.GroupVersionKind{ + return IsOwnedBy(pod, []schema.GroupVersionKind{ {Group: "apps", Version: "v1", Kind: "DaemonSet"}, - } { + }) +} + +// IsOwnedByNode returns true if the pod is a static pod owned by a specific node +func IsOwnedByNode(pod *v1.Pod) bool { + return IsOwnedBy(pod, []schema.GroupVersionKind{ + {Version: "v1", Kind: "Node"}, + }) +} + +func IsOwnedBy(pod *v1.Pod, gvks []schema.GroupVersionKind) bool { + for _, ignoredOwner := range gvks { for _, owner := range pod.ObjectMeta.OwnerReferences { if owner.APIVersion == ignoredOwner.GroupVersion().String() && owner.Kind == ignoredOwner.Kind { return true