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

[WIP] testing #3501

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion .github/workflows/checkpatch.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Check pull request commits
on:
push:
pull_request:
# pull_request:

jobs:
checkpatch:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/gotests.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Tetragon Go Test
on:
pull_request:
paths-ignore:
- 'docs/**'
# pull_request:
# paths-ignore:
# - 'docs/**'
push:
branches:
- main
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/lint-codeql.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name: codeql

on:
pull_request:
branches:
- main
paths-ignore:
- 'docs/**'
# pull_request:
# branches:
# - main
# paths-ignore:
# - 'docs/**'
push:
branches:
- main
Expand Down
11 changes: 7 additions & 4 deletions .github/workflows/packages-e2e-tests.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
name: Packages e2e Tests

on:
pull_request:
paths-ignore:
- "**.md"
- 'docs/**'
push:
branches:
- main
# pull_request:
# paths-ignore:
# - "**.md"
# - 'docs/**'

jobs:
standalone-tarball-builds:
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/podinfo-test.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: PodInfo Integration Test
on:
pull_request:
types:
- opened
- synchronize
- reopened
paths-ignore:
- 'docs/**'
# pull_request:
# types:
# - opened
# - synchronize
# - reopened
# paths-ignore:
# - 'docs/**'
push:
branches:
- main
Expand Down
17 changes: 12 additions & 5 deletions .github/workflows/run-e2e-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ concurrency:
group: ${{ github.ref }}
cancel-in-progress: true

env:
clusterName: tetragon-ci

jobs:
prepare:
runs-on: ubuntu-22.04
Expand Down Expand Up @@ -74,7 +71,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-22.04, ubuntu-22.04-arm64 ]
os: [ ubuntu-22.04 ]
package: ${{fromJson(needs.prepare.outputs.packages)}}
steps:
- name: Checkout Code
Expand Down Expand Up @@ -117,8 +114,18 @@ jobs:
env:
GHA_OS: ${{matrix.os}}
run: |
set -x
cd go/src/github.com/cilium/tetragon
make e2e-test E2E_TESTS=${{matrix.package.f}} E2E_BUILD_IMAGES=0 E2E_AGENT=${{ needs.prepare.outputs.agentImage }} E2E_OPERATOR=${{ needs.prepare.outputs.operatorImage }} EXTRA_TESTFLAGS="-cluster-name=${{ env.clusterName }} -args -v=4"
make e2e-test \
E2E_TESTS=${{matrix.package.f}} \
E2E_BUILD_IMAGES=0 \
E2E_AGENT=${{ needs.prepare.outputs.agentImage }} \
E2E_OPERATOR=${{ needs.prepare.outputs.operatorImage }}

- name: ls logs
if: failure() || cancelled()
run: |
ls /tmp/tetragon.e2e.*

- name: Upload Tetragon Logs
if: failure() || cancelled()
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/static-checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ on:
paths-ignore:
- 'docs/**'
- '**.md'
pull_request:
paths-ignore:
- 'docs/**'
- '**.md'
# pull_request:
# paths-ignore:
# - 'docs/**'
# - '**.md'

permissions:
# For golangci/golangci-lint to have read access to pull request for `only-new-issues` option.
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/vmtests.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: vmtests
on:
pull_request:
paths-ignore:
- 'docs/**'
# pull_request:
# paths-ignore:
# - 'docs/**'
push:
branches:
- main
Expand Down
18 changes: 15 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,10 @@ copy-golangci-lint:

.PHONY: test
test: tester-progs tetragon-bpf ## Run Go tests.
$(GO) test -exec "$(SUDO)" -p 1 -parallel 1 $(GOFLAGS) -gcflags=$(GO_BUILD_GCFLAGS) -timeout $(GO_TEST_TIMEOUT) -failfast -cover ./pkg/... ./cmd/... ./operator/... ${EXTRA_TESTFLAGS}
$(GO) test -exec "$(SUDO)" -p 1 -parallel 1 \
$(GOFLAGS) -gcflags=$(GO_BUILD_GCFLAGS) -timeout $(GO_TEST_TIMEOUT) -failfast -cover \
./pkg/... ./cmd/... ./operator/... \
${EXTRA_TESTFLAGS}

.PHONY: tester-progs
tester-progs: ## Compile helper programs for unit testing.
Expand All @@ -285,7 +288,10 @@ alignchecker: ## Run alignchecker.

.PHONY: bench
bench: ## Run Go benchmarks.
$(GO) test -exec "$(SUDO)" -p 1 -parallel 1 -run ^$$ $(GOFLAGS) -gcflags=$(GO_BUILD_GCFLAGS) -timeout $(GO_TEST_TIMEOUT) -failfast -cover ./pkg/... ./cmd/... ./operator/... -bench=. ${EXTRA_TESTFLAGS}
$(GO) test -exec "$(SUDO)" -p 1 -parallel 1 -run ^$$ \
$(GOFLAGS) -gcflags=$(GO_BUILD_GCFLAGS) -timeout $(GO_TEST_TIMEOUT) -failfast -cover \
./pkg/... ./cmd/... ./operator/... \
-bench=. ${EXTRA_TESTFLAGS}

TEST_COMPILE ?= ./...
.PHONY: test-compile
Expand Down Expand Up @@ -335,7 +341,13 @@ e2e-test: image image-operator
else
e2e-test:
endif
$(GO) list $(E2E_TESTS) | xargs -Ipkg $(GO) test $(GOFLAGS) -gcflags=$(GO_BUILD_GCFLAGS) -timeout $(E2E_TEST_TIMEOUT) -failfast -cover pkg ${EXTRA_TESTFLAGS} -fail-fast -tetragon.helm.set tetragon.image.override="$(E2E_AGENT)" -tetragon.helm.set tetragonOperator.image.override="$(E2E_OPERATOR)" -tetragon.helm.url="" -tetragon.helm.chart="$(realpath ./install/kubernetes/tetragon)" $(E2E_BTF_FLAGS)
$(GO) list $(E2E_TESTS) | xargs -Ipkg \
$(GO) test $(GOFLAGS) -gcflags=$(GO_BUILD_GCFLAGS) -timeout $(E2E_TEST_TIMEOUT) -failfast -cover pkg \
${EXTRA_TESTFLAGS} \
-tetragon.helm.set tetragon.image.override="$(E2E_AGENT)" \
-tetragon.helm.set tetragonOperator.image.override="$(E2E_OPERATOR)" \
-tetragon.helm.url="" -tetragon.helm.chart="$(realpath ./install/kubernetes/tetragon)" \
$(E2E_BTF_FLAGS)

##@ Development

Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/checker/rpcchecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ func (rc *RPCChecker) updateContextEventCheckers(ctx context.Context) context.Co
func getExportDir(ctx context.Context) (string, error) {
exportDir, ok := ctx.Value(state.ExportDir).(string)
if !ok {
return "", fmt.Errorf("export dir has not been created. Call helpers.CreateExportDir() first")
return "", fmt.Errorf("export dir has not been created. Call runner.SetupExport() first")
}
return exportDir, nil
}
Expand Down
9 changes: 0 additions & 9 deletions tests/e2e/helpers/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,14 @@ nodes:
`

var (
clusterName string
clusterImage string
)

func init() {
flag.StringVar(&clusterName, "cluster-name", "tetragon-ci", "Set the name of the k8s cluster being used")
// renovate: datasource=docker
flag.StringVar(&clusterImage, "cluster-image", "kindest/node:v1.32.3", "Set the node image for the kind cluster")
}

// GetClusterName fetches the cluster name configured with -cluster-name or the temporary
// kind cluster name.
func GetClusterName() string {
return clusterName
}

func SetMinKernelVersion() env.Func {
return func(ctx context.Context, cfg *envconf.Config) (context.Context, error) {
client, err := cfg.NewClient()
Expand Down Expand Up @@ -141,7 +133,6 @@ func MaybeCreateTempKindCluster(testenv env.Environment, namePrefix string) env.
return func(ctx context.Context, cfg *envconf.Config) (context.Context, error) {
if cfg.KubeconfigFile() == "" {
name := envconf.RandomName(namePrefix, 16)
clusterName = name
klog.Infof("No kubeconfig specified, creating temporary kind cluster %s", name)
var err error
err = writeKindConfig()
Expand Down
109 changes: 66 additions & 43 deletions tests/e2e/helpers/dumpinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

var (
TetragonContainerName = "tetragon"
OperatorContainerName = "tetragon-operator"
TetragonJsonPathname = "/var/run/cilium/tetragon/tetragon.log"
)

Expand All @@ -52,63 +53,86 @@ func DumpInfo(ctx context.Context, cfg *envconf.Config) (context.Context, error)
if err != nil {
return ctx, err
}
r := client.Resources(opts.Namespace)

podList := &corev1.PodList{}
if err = r.List(
ctx,
podList,
resources.WithLabelSelector(fmt.Sprintf("app.kubernetes.io/instance=%s", opts.DaemonSetName)),
); err != nil {
if err := dumpPodSummary("pods.txt", exportDir); err != nil {
klog.ErrorS(err, "Failed to dump pod summary")
}
err = dumpAgentInfo(ctx, exportDir, opts, client)
if err != nil {
return ctx, err
}
err = dumpOperatorInfo(ctx, exportDir, opts, client)
if err != nil {
return ctx, err
}

return ctx, nil
}

func GetExportDir(ctx context.Context) (string, error) {
exportDir, ok := ctx.Value(state.ExportDir).(string)
if !ok {
return "", fmt.Errorf("export dir has not been created. Call runner.SetupExport() first")
}

return exportDir, nil
}

func dumpAgentInfo(ctx context.Context, exportDir string, opts *flags.HelmOptions, client klient.Client) error {
podList, err := getPods(ctx, opts.DaemonSetName, opts, client)
if err != nil {
return err
}

for _, pod := range podList.Items {
if err := extractJson(&pod, exportDir); err != nil {
klog.ErrorS(err, "Failed to extract json events")
}
if err := extractLogs(&pod, exportDir, true); err != nil {
if err := extractLogs(&pod, exportDir, TetragonContainerName, true); err != nil {
klog.ErrorS(err, "Failed to extract previous tetragon logs")
}
if err := extractLogs(&pod, exportDir, false); err != nil {
if err := extractLogs(&pod, exportDir, TetragonContainerName, false); err != nil {
klog.ErrorS(err, "Failed to extract tetragon logs")
}
if err := describeTetragonPod(&pod, exportDir); err != nil {
if err := describePod(&pod, opts.DaemonSetName, exportDir); err != nil {
klog.ErrorS(err, "Failed to describe tetragon pods")
}
if err := dumpPodSummary("pods.txt", exportDir); err != nil {
klog.ErrorS(err, "Failed to dump pod summary")
}
dumpBpftool(ctx, client, exportDir, pod.Namespace, pod.Name, TetragonContainerName)
}

return ctx, nil
return nil
}

func CreateExportDir(ctx context.Context, t *testing.T) (context.Context, error) {
dir, err := GetExportDir(ctx)
if err == nil {
klog.V(2).InfoS("export dir already exists, skipping creation", "test", t.Name(), "dir", dir)
return ctx, nil
}

dir, err = os.MkdirTemp("", fmt.Sprintf("tetragon.e2e.%s.*", t.Name()))
func dumpOperatorInfo(ctx context.Context, exportDir string, opts *flags.HelmOptions, client klient.Client) error {
name := opts.DaemonSetName + "-operator"
podList, err := getPods(ctx, name, opts, client)
if err != nil {
return ctx, err
return err
}

klog.InfoS("created export dir for test", "test", t.Name(), "dir", dir)

return context.WithValue(ctx, state.ExportDir, dir), nil
for _, pod := range podList.Items {
if err := extractLogs(&pod, exportDir, OperatorContainerName, true); err != nil {
klog.ErrorS(err, "Failed to extract previous operator logs")
}
if err := extractLogs(&pod, exportDir, OperatorContainerName, false); err != nil {
klog.ErrorS(err, "Failed to extract operator logs")
}
if err := describePod(&pod, name, exportDir); err != nil {
klog.ErrorS(err, "Failed to describe operator pods")
}
}
return nil
}

func GetExportDir(ctx context.Context) (string, error) {
exportDir, ok := ctx.Value(state.ExportDir).(string)
if !ok {
return "", fmt.Errorf("export dir has not been created. Call runner.CreateExportDir() first")
func getPods(ctx context.Context, nameLabel string, opts *flags.HelmOptions, client klient.Client) (*corev1.PodList, error) {
r := client.Resources(opts.Namespace)
podList := &corev1.PodList{}
if err := r.List(
ctx, podList,
resources.WithLabelSelector(fmt.Sprintf("app.kubernetes.io/name=%s", nameLabel)),
); err != nil {
return nil, err
}

return exportDir, nil
return podList, nil
}

func extractJson(pod *corev1.Pod, exportDir string) error {
Expand All @@ -119,22 +143,21 @@ func extractJson(pod *corev1.Pod, exportDir string) error {
filepath.Join(exportDir, fmt.Sprintf("tetragon.%s.json", pod.Name)))
}

func extractLogs(pod *corev1.Pod, exportDir string, prev bool) error {
func extractLogs(pod *corev1.Pod, exportDir string, container string, prev bool) error {
var fname string
if prev {
fname = fmt.Sprintf("tetragon.%s.prev.log", pod.Name)
fname = fmt.Sprintf("%s.%s.prev.log", container, pod.Name)
} else {
fname = fmt.Sprintf("tetragon.%s.log", pod.Name)
fname = fmt.Sprintf("%s.%s.log", container, pod.Name)
}
return kubectlLogs(filepath.Join(exportDir, fname),
pod.Namespace,
pod.Name,
TetragonContainerName,
prev)
return kubectlLogs(
filepath.Join(exportDir, fname),
pod.Namespace, pod.Name, container, prev,
)
}

func describeTetragonPod(pod *corev1.Pod, exportDir string) error {
fname := fmt.Sprintf("tetragon.%s.describe", pod.Name)
func describePod(pod *corev1.Pod, workload string, exportDir string) error {
fname := fmt.Sprintf("%s.%s.describe", workload, pod.Name)
return kubectlDescribe(filepath.Join(exportDir, fname),
pod.Namespace,
pod.Name)
Expand Down
Loading
Loading