Skip to content

Commit

Permalink
Add test to use the PodSafeToEvictKey in reverse
Browse files Browse the repository at this point in the history
When this is set to false instead of true, the pod should not be evicted by
the autoscaler.
  • Loading branch information
vainu-arto committed Jul 11, 2018
1 parent 350a2ab commit b031679
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions cluster-autoscaler/utils/drain/drain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,31 @@ func TestDrain(t *testing.T) {
},
}

unsafeRcPod := &apiv1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
Namespace: "default",
OwnerReferences: GenerateOwnerReferences(rc.Name, "ReplicationController", "extensions/v1beta1", ""),
Annotations: map[string]string{
PodSafeToEvictKey: "false",
},
},
Spec: apiv1.PodSpec{
NodeName: "node",
},
}

unsafeJobPod := &apiv1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
Namespace: "default",
OwnerReferences: GenerateOwnerReferences(job.Name, "Job", "extensions/v1beta1", ""),
Annotations: map[string]string{
PodSafeToEvictKey: "false",
},
},
}

kubeSystemSafePod := &apiv1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "bar",
Expand Down Expand Up @@ -376,6 +401,22 @@ func TestDrain(t *testing.T) {
expectFatal: false,
expectPods: []*apiv1.Pod{emptydirSafePod},
},
{
description: "RC-managed pod with PodSafeToEvict=false annotation",
pods: []*apiv1.Pod{unsafeRcPod},
rcs: []apiv1.ReplicationController{rc},
pdbs: []*policyv1.PodDisruptionBudget{},
expectFatal: true,
expectPods: []*apiv1.Pod{},
},
{
description: "Job-managed pod with PodSafeToEvict=false annotation",
pods: []*apiv1.Pod{unsafeJobPod},
pdbs: []*policyv1.PodDisruptionBudget{},
rcs: []apiv1.ReplicationController{rc},
expectFatal: true,
expectPods: []*apiv1.Pod{},
},
{
description: "empty PDB with RC-managed pod",
pods: []*apiv1.Pod{rcPod},
Expand Down

0 comments on commit b031679

Please sign in to comment.