Skip to content
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ codecov.yaml
cover.out
.DS_Store
*.iml
test/e2e/logs/
16 changes: 16 additions & 0 deletions test/e2e/sparkapplication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ var _ = Describe("Example SparkApplication", func() {
key := types.NamespacedName{Namespace: app.Namespace, Name: app.Name}
Expect(k8sClient.Get(ctx, key, app)).To(Succeed())

By("Writing driver logs")
driverPodName := util.GetDriverPodName(app)
writePodLogs(ctx, app.Namespace, driverPodName)

By("Deleting SparkApplication")
Expect(k8sClient.Delete(ctx, app)).To(Succeed())
})
Expand Down Expand Up @@ -116,6 +120,10 @@ var _ = Describe("Example SparkApplication", func() {
key := types.NamespacedName{Namespace: app.Namespace, Name: app.Name}
Expect(k8sClient.Get(ctx, key, app)).To(Succeed())

By("Writing driver logs")
driverPodName := util.GetDriverPodName(app)
writePodLogs(ctx, app.Namespace, driverPodName)

volumes := app.Spec.Volumes
By("Deleting SparkApplication")
Expect(k8sClient.Delete(ctx, app)).To(Succeed())
Expand Down Expand Up @@ -201,6 +209,10 @@ var _ = Describe("Example SparkApplication", func() {
key := types.NamespacedName{Namespace: app.Namespace, Name: app.Name}
Expect(k8sClient.Get(ctx, key, app)).To(Succeed())

By("Writing driver logs")
driverPodName := util.GetDriverPodName(app)
writePodLogs(ctx, app.Namespace, driverPodName)

By("Deleting SparkApplication")
Expect(k8sClient.Delete(ctx, app)).To(Succeed())
})
Expand Down Expand Up @@ -376,6 +388,10 @@ var _ = Describe("Example SparkApplication", func() {
key := types.NamespacedName{Namespace: app.Namespace, Name: app.Name}
Expect(k8sClient.Get(ctx, key, app)).To(Succeed())

By("Writing driver logs")
driverPodName := util.GetDriverPodName(app)
writePodLogs(ctx, app.Namespace, driverPodName)

By("Deleting SparkApplication")
Expect(k8sClient.Delete(ctx, app)).To(Succeed())
})
Expand Down
31 changes: 31 additions & 0 deletions test/e2e/suit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ const (
MutatingWebhookName = "spark-operator-webhook"
ValidatingWebhookName = "spark-operator-webhook"

ControllerName = "spark-operator-controller"

PollInterval = 1 * time.Second
WaitTimeout = 5 * time.Minute
)
Expand Down Expand Up @@ -152,6 +154,9 @@ var _ = BeforeSuite(func() {
})

var _ = AfterSuite(func() {
By("Capturing the Spark operator logs")
writeControllerLogs(context.Background())

By("Uninstalling the Spark operator helm chart")
envSettings := cli.New()
envSettings.SetNamespace(ReleaseNamespace)
Expand Down Expand Up @@ -290,3 +295,29 @@ func collectSparkApplicationsUntilTermination(ctx context.Context, key types.Nam
})
return apps, err
}

func writePodLogs(ctx context.Context, podNamespace string, podName string) {
bytes, err := clientset.CoreV1().Pods(podNamespace).GetLogs(podName, &corev1.PodLogOptions{}).Do(ctx).Raw()
Expect(err).NotTo(HaveOccurred())
dir := filepath.Join("logs", podNamespace)
if _, err := os.Stat(dir); os.IsNotExist(err) {
err = os.MkdirAll(dir, 0755)
Expect(err).NotTo(HaveOccurred())
}
err = os.WriteFile(filepath.Join(dir, fmt.Sprintf("%s.log", podName)), bytes, 0644)
Expect(err).NotTo(HaveOccurred())
}

func writeControllerLogs(ctx context.Context) {
deployment, err := clientset.AppsV1().Deployments(ReleaseNamespace).Get(ctx, ControllerName, metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())
listOptions := metav1.ListOptions{
LabelSelector: metav1.FormatLabelSelector(&metav1.LabelSelector{MatchLabels: deployment.Spec.Selector.MatchLabels}),
}
pods, err := clientset.CoreV1().Pods(ReleaseNamespace).List(ctx, listOptions)
Expect(err).NotTo(HaveOccurred())
Expect(pods).NotTo(BeNil())
for _, pod := range pods.Items {
writePodLogs(ctx, ReleaseNamespace, pod.Name)
}
}