Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not try to evict mirror pods #1058

Merged
merged 1 commit into from
Dec 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions pkg/controllers/termination/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
. "knative.dev/pkg/logging/testing"
Expand Down Expand Up @@ -196,6 +197,48 @@ var _ = Describe("Termination", func() {
ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(node))
ExpectNotFound(ctx, env.Client, node)
})
It("should not evict static pods", func() {
podEvict := test.Pod(test.PodOptions{NodeName: node.Name})
ExpectCreated(ctx, env.Client, node, podEvict)

podNoEvict := test.Pod(test.PodOptions{
NodeName: node.Name,
OwnerReferences: []metav1.OwnerReference{{
APIVersion: "v1",
Kind: "Node",
Name: node.Name,
UID: node.UID,
}},
})
ExpectCreated(ctx, env.Client, podNoEvict)

Expect(env.Client.Delete(ctx, node)).To(Succeed())
node = ExpectNodeExists(ctx, env.Client, node.Name)
ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(node))

// Expect mirror pod to not be queued for enviction
ExpectNotEnqueuedForEviction(evictionQueue, podNoEvict)

// Expect podEvict to be enqueued for eviction then be successful
ExpectEnqueuedForEviction(evictionQueue, podEvict)
ExpectEvicted(env.Client, podEvict)

// Expect node to exist and be draining
ExpectNodeDraining(env.Client, node.Name)

// Reconcile node to evict pod
node = ExpectNodeExists(ctx, env.Client, node.Name)
ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(node))

// Delete pod to simulate successful eviction
ExpectDeleted(ctx, env.Client, podEvict)

// Reconcile to delete node
node = ExpectNodeExists(ctx, env.Client, node.Name)
ExpectReconcileSucceeded(ctx, controller, client.ObjectKeyFromObject(node))
ExpectNotFound(ctx, env.Client, node)

})
It("should not delete nodes until all pods are deleted", func() {
pods := []*v1.Pod{test.Pod(test.PodOptions{NodeName: node.Name}), test.Pod(test.PodOptions{NodeName: node.Name})}
ExpectCreated(ctx, env.Client, node, pods[0], pods[1])
Expand Down
13 changes: 9 additions & 4 deletions pkg/controllers/termination/terminate.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/aws/karpenter/pkg/cloudprovider"
"github.com/aws/karpenter/pkg/utils/functional"
"github.com/aws/karpenter/pkg/utils/injectabletime"
"github.com/aws/karpenter/pkg/utils/pod"
"github.com/aws/karpenter/pkg/utils/ptr"
)

Expand Down Expand Up @@ -110,16 +111,20 @@ func (t *Terminator) getPods(ctx context.Context, node *v1.Node) ([]*v1.Pod, err

func (t *Terminator) getEvictablePods(pods []*v1.Pod) []*v1.Pod {
evictable := []*v1.Pod{}
for _, pod := range pods {
for _, p := range pods {
// Ignore if unschedulable is tolerated, since they will reschedule
if (v1alpha5.Taints{{Key: v1.TaintNodeUnschedulable, Effect: v1.TaintEffectNoSchedule}}).Tolerates(pod) == nil {
if (v1alpha5.Taints{{Key: v1.TaintNodeUnschedulable, Effect: v1.TaintEffectNoSchedule}}).Tolerates(p) == nil {
continue
}
// Ignore if kubelet is partitioned and pods are beyond graceful termination window
if IsStuckTerminating(pod) {
if IsStuckTerminating(p) {
continue
}
// Ignore static mirror pods
if pod.IsOwnedByNode(p) {
continue
}
evictable = append(evictable, pod)
evictable = append(evictable, p)
}
return evictable
}
Expand Down