diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 638b614..32fbd15 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -160,4 +160,13 @@ jobs: env: GOPATH: /home/runner/go run: KUBECONFIG=~/.kube/config VERSION=${{ github.sha }} DOCKER_PUSH=true DATA_LOSS_PREVENTION=${{matrix.datalossprevention}} make test-e2e + + - name: Archive controller logs + uses: actions/upload-artifact@v4 + if: always() + with: + name: controller-logs-${{matrix.datalossprevention}} + path: | + tests/e2e/output/ + retention-days: 7 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 2374322..1269c48 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,5 @@ config/crd/bases/_.yaml .idea config/crd/external/ + +tests/e2e/output \ No newline at end of file diff --git a/tests/e2e/common.go b/tests/e2e/common.go index ca5cbda..ef8ff96 100644 --- a/tests/e2e/common.go +++ b/tests/e2e/common.go @@ -3,6 +3,8 @@ package e2e import ( "context" "fmt" + "io" + "os" "time" . "github.com/onsi/ginkgo/v2" @@ -19,6 +21,7 @@ import ( "github.com/numaproj/numaplane/internal/util/kubernetes" apiv1 "github.com/numaproj/numaplane/pkg/apis/numaplane/v1alpha1" planepkg "github.com/numaproj/numaplane/pkg/client/clientset/versioned/typed/numaplane/v1alpha1" + corev1 "k8s.io/api/core/v1" ) var ( @@ -41,6 +44,12 @@ var ( const ( Namespace = "numaplane-system" + + NumaplaneCtrlLogs = "output/numaplane-controller.log" + NumaflowCtrlLogs = "output/numaflow-controller.log" + + NumaplaneLabel = "app.kubernetes.io/part-of=numaplane" + NumaflowLabel = "app.kubernetes.io/part-of=numaflow, app.kubernetes.io/component=controller-manager" ) // document for Ginkgo framework and print to console @@ -94,16 +103,31 @@ func getNumaflowResourceStatus(u *unstructured.Unstructured) (kubernetes.Generic return status, err } -// commenting out to please Lint, but leaving here because it could be useful later -/* -func printPodLogs(client clientgo.Interface, namespace, podName, containerName string) { - podLogOptions := &apiv1.PodLogOptions{Container: containerName} - stream, err := client.CoreV1().Pods(namespace).GetLogs(podName, podLogOptions).Stream(ctx) +func getPodLogs(client clientgo.Interface, namespace, labelSelector, containerName, fileName string) { + + ctx := context.Background() + podLogOptions := &corev1.PodLogOptions{Container: containerName} + + podList, err := client.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{LabelSelector: labelSelector}) if err != nil { - fmt.Printf("Error getting Pod logs: namespace=%q, pod=%q, container=%q\n", namespace, podName, containerName) + fmt.Printf("Error listing pods: %v\n", err) return } - defer stream.Close() - logBytes, _ := io.ReadAll(stream) - fmt.Printf("Printing Log for namespace=%q, pod=%q, container=%q:\n%s\n", namespace, podName, containerName, string(logBytes)) -}*/ + + for _, pod := range podList.Items { + stream, err := client.CoreV1().Pods(namespace).GetLogs(pod.Name, podLogOptions).Stream(ctx) + if err != nil { + fmt.Printf("Error getting pods logs: %v\n", err) + return + } + defer stream.Close() + logBytes, _ := io.ReadAll(stream) + + err = os.WriteFile(fileName, logBytes, 0644) + if err != nil { + fmt.Printf("Error writing pod logs to file: %v\n", err) + return + } + } + +} diff --git a/tests/e2e/suite_test.go b/tests/e2e/suite_test.go index ab10067..1558eae 100644 --- a/tests/e2e/suite_test.go +++ b/tests/e2e/suite_test.go @@ -45,6 +45,10 @@ func TestE2E(t *testing.T) { var _ = BeforeSuite(func() { + var err error + err = os.Mkdir("output", os.ModePerm) + Expect(err).NotTo(HaveOccurred()) + dataLossPrevention = os.Getenv("DATA_LOSS_PREVENTION") logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true))) @@ -52,7 +56,6 @@ var _ = BeforeSuite(func() { By("bootstrapping test environment") ctx, cancel = context.WithTimeout(context.Background(), suiteTimeout) // Note: if we start seeing "client rate limiter: context deadline exceeded", we need to increase this value - var err error scheme := runtime.NewScheme() err = apiv1.AddToScheme(scheme) Expect(err).NotTo(HaveOccurred()) @@ -103,7 +106,19 @@ var _ = AfterSuite(func() { cancel() By("tearing down test environment") + getPodLogs(kubeClient, Namespace, NumaplaneLabel, "manager", NumaplaneCtrlLogs) err := testEnv.Stop() Expect(err).NotTo(HaveOccurred()) }) + +var _ = AfterEach(func() { + + report := CurrentSpecReport() + if report.Failed() { + getPodLogs(kubeClient, Namespace, NumaplaneLabel, "manager", NumaplaneCtrlLogs) + getPodLogs(kubeClient, Namespace, NumaflowLabel, "controller-manager", NumaflowCtrlLogs) + AbortSuite("Test spec has failed, aborting suite run") + } + +})