Skip to content

Commit

Permalink
Merge branch 'main' into label
Browse files Browse the repository at this point in the history
  • Loading branch information
xdevxy committed Sep 17, 2024
2 parents 2e1ebb4 + 33a8afa commit 706e22d
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 11 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ config/crd/bases/_.yaml
.idea

config/crd/external/

tests/e2e/output
44 changes: 34 additions & 10 deletions tests/e2e/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package e2e
import (
"context"
"fmt"
"io"
"os"
"time"

. "github.com/onsi/ginkgo/v2"
Expand All @@ -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 (
Expand All @@ -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
Expand Down Expand Up @@ -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
}
}

}
17 changes: 16 additions & 1 deletion tests/e2e/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,17 @@ 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)))

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())
Expand Down Expand Up @@ -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")
}

})

0 comments on commit 706e22d

Please sign in to comment.