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

Add E2E to verify Event Generation for Volcano Job #393

Merged
merged 1 commit into from
Jul 27, 2019
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
79 changes: 79 additions & 0 deletions test/e2e/job_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ import (

"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
kubeletapi "k8s.io/kubernetes/pkg/kubelet/apis"
"k8s.io/kubernetes/pkg/scheduler/api"

vkv1 "volcano.sh/volcano/pkg/apis/batch/v1alpha1"
)

Expand Down Expand Up @@ -289,4 +291,81 @@ var _ = Describe("Job Life Cycle", func() {

})

It("Checking Event Generation for job", func() {
context := initTestContext()
defer cleanupTestContext(context)

job := createJob(context, &jobSpec{
name: "terminate-job",
policies: []vkv1.LifecyclePolicy{
{
Action: vkv1.TerminateJobAction,
Event: vkv1.PodFailedEvent,
},
},
tasks: []taskSpec{
{
name: "complete",
img: defaultNginxImage,
min: 1,
rep: 1,
command: "sleep 10s && xyz",
restartPolicy: v1.RestartPolicyNever,
},
},
})

err := waitJobTerminateAction(context, job)
Expect(err).NotTo(HaveOccurred())
})

It("Checking Unschedulable Event Generation for job", func() {
context := initTestContext()
defer cleanupTestContext(context)

nodeName, rep := computeNode(context, oneCPU)

nodeAffinity := &v1.NodeAffinity{
RequiredDuringSchedulingIgnoredDuringExecution: &v1.NodeSelector{
NodeSelectorTerms: []v1.NodeSelectorTerm{
{
MatchExpressions: []v1.NodeSelectorRequirement{
{
Key: kubeletapi.LabelHostname,
Operator: v1.NodeSelectorOpIn,
Values: []string{nodeName},
},
},
},
},
},
}

job := createJob(context, &jobSpec{
name: "unschedulable-job",
policies: []vkv1.LifecyclePolicy{
{
Action: vkv1.TerminateJobAction,
Event: vkv1.PodFailedEvent,
},
},
tasks: []taskSpec{
{
name: "complete",
img: defaultNginxImage,
min: rep + 1,
rep: rep + 1,
command: "sleep 10s",
restartPolicy: v1.RestartPolicyNever,
req: cpuResource("1"),
limit: cpuResource("1"),
affinity: &v1.Affinity{NodeAffinity: nodeAffinity},
},
},
})

err := waitJobUnschedulable(context, job)
Expect(err).NotTo(HaveOccurred())
})

})
23 changes: 23 additions & 0 deletions test/e2e/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const (
defaultBusyBoxImage = "busybox:1.24"
defaultMPIImage = "volcanosh/example-mpi:0.0.1"
schedulerName = "volcano"
executeAction = "ExecuteAction"

defaultNamespace = "test"
defaultQueue1 = "q1"
Expand Down Expand Up @@ -1152,3 +1153,25 @@ func waitPodGone(ctx *context, podName, namespace string) error {
}
return err
}

func waitJobTerminateAction(ctx *context, pg *batchv1alpha1.Job) error {
return wait.Poll(10*time.Second, oneMinute, jobTerminateAction(ctx, pg, time.Now()))
}

func jobTerminateAction(ctx *context, pg *batchv1alpha1.Job, time time.Time) wait.ConditionFunc {
return func() (bool, error) {
events, err := ctx.kubeclient.CoreV1().Events(pg.Namespace).List(metav1.ListOptions{})
Expect(err).NotTo(HaveOccurred())

for _, event := range events.Items {
target := event.InvolvedObject
if strings.HasPrefix(target.Name, pg.Name) && target.Namespace == pg.Namespace {
if event.Reason == string(executeAction) && strings.Contains(event.Message, "TerminateJob") && event.LastTimestamp.After(time) {
return true, nil
}
}
}

return false, nil
}
}