Skip to content

Commit

Permalink
ignore static pods owned by a node in node emptiness check (#721)
Browse files Browse the repository at this point in the history
  • Loading branch information
bwagner5 committed Oct 1, 2021
1 parent 52f183a commit 972c40b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
3 changes: 3 additions & 0 deletions pkg/controllers/allocation/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/controllers/node/emptiness.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
15 changes: 13 additions & 2 deletions pkg/utils/pod/scheduling.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 972c40b

Please sign in to comment.