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

tests/e2e: improvements to testing workflow #385

Merged
merged 3 commits into from
Sep 6, 2022
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
10 changes: 1 addition & 9 deletions .github/workflows/run-e2e-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,7 @@ jobs:
run: |
cd go/src/github.com/cilium/tetragon

go test -p 1 -parallel 1 -timeout 20m -failfast -cover ./tests/e2e/tests/... \
-tetragon.helm.set=tetragon.image.override=${{ steps.vars.outputs.agentImage }} \
-tetragon.helm.set=tetragonOperator.image.override=${{ steps.vars.outputs.operatorImage }} \
-tetragon.helm.url="" \
-tetragon.helm.chart="$(realpath ./install/kubernetes)" \
-tetragon.install-cilium=false \
-cluster-name=${{ env.clusterName }} \
-kubeconfig ~/.kube/config \
-args -v=4
make e2e-test E2E_BUILD_IMAGES=0 E2E_AGENT=${{ steps.vars.outputs.agentImage }} E2E_OPERATOR=${{ steps.vars.outputs.operatorImage }} EXTRA_TESTFLAGS="-tetragon.install-cilium=false -cluster-name=${{ env.clusterName }} -kubeconfig ~/.kube/config -args -v=4"

- name: Upload Tetragon Logs
if: failure()
Expand Down
21 changes: 20 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,29 @@ clean:
test:
$(GO) test -p 1 -parallel 1 $(GOFLAGS) -gcflags=$(GO_GCFLAGS) -timeout 20m -failfast -cover ./pkg/... ${EXTRA_TESTFLAGS}

# Agent image to use for end-to-end tests
E2E_AGENT ?= "cilium/tetragon:$(DOCKER_IMAGE_TAG)"
# Operator image to use for end-to-end tests
E2E_OPERATOR ?= "cilium/tetragon-operator:$(DOCKER_IMAGE_TAG)"
# BTF file to use in the E2E test. Set to nothing to use system BTF.
E2E_BTF ?= ""
# Actual flags to use for BTF file in e2e test. Use E2E_BTF instead.
ifneq ($(E2E_BTF), "")
E2E_BTF_FLAGS ?= "-tetragon.btf=$(shell readlink -f $(E2E_BTF))"
else
E2E_BTF_FLAGS = ""
endif
# Build image and operator images locally before running test. Set to 0 to disable.
E2E_BUILD_IMAGES ?= 1

# Run an e2e-test
.PHONY: e2e-test
ifneq ($(E2E_BUILD_IMAGES), 0)
e2e-test: image image-operator
$(GO) test -p 1 -parallel 1 $(GOFLAGS) -gcflags=$(GO_GCFLAGS) -timeout 20m -failfast -cover ./tests/e2e/tests/... ${EXTRA_TESTFLAGS} -fail-fast -tetragon.helm.set tetragon.image.override="cilium/tetragon:${DOCKER_IMAGE_TAG}" -tetragon.helm.set tetragonOperator.image.override="cilium/tetragon-operator:${DOCKER_IMAGE_TAG}" -tetragon.helm.url="" -tetragon.helm.chart="$(realpath ./install/kubernetes)"
else
e2e-test:
endif
$(GO) test -p 1 -parallel 1 $(GOFLAGS) -gcflags=$(GO_GCFLAGS) -timeout 20m -failfast -cover ./tests/e2e/tests/... ${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)" $(E2E_BTF_FLAGS)

TEST_COMPILE ?= ./...
.PHONY: test-compile
Expand Down
28 changes: 18 additions & 10 deletions tests/e2e/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var Opts = Flags{
HelmChartVersion: "9999.9999.9999-dev",
Namespace: "kube-system",
ValuesFile: "",
BTF: "",
HelmValues: HelmValues{
// Don't stop any events from being exported by default
"tetragon.exportAllowList": "",
Expand All @@ -31,51 +32,56 @@ func init() {
flag.BoolVar(&Opts.Helm.Wait,
"tetragon.helm.wait",
Opts.Helm.Wait,
"set to true if we should wait for Tetragon to be installed before starting the test")
"Set to true if we should wait for Tetragon to be installed before starting the test")

flag.StringVar(&Opts.Helm.DaemonSetName,
"tetragon.helm.daemonset",
Opts.Helm.DaemonSetName,
"name for the Tetragon daemonset + install target")
"Name for the Tetragon daemonset + install target")

flag.StringVar(&Opts.Helm.HelmChart,
"tetragon.helm.chart",
Opts.Helm.HelmChart,
"name of the helm chart from which to install Tetragon")
"Name of the helm chart from which to install Tetragon")

flag.StringVar(&Opts.Helm.HelmRepoUrl,
"tetragon.helm.url",
Opts.Helm.HelmRepoUrl,
"name of the helm repo where we find Tetragon")
"Name of the helm repo where we find Tetragon")

flag.StringVar(&Opts.Helm.HelmChartVersion,
"tetragon.helm.version",
Opts.Helm.HelmChartVersion,
"helm chart version to use")
"Helm chart version to use")

flag.StringVar(&Opts.Helm.Namespace,
"tetragon.helm.namespace",
Opts.Helm.Namespace,
"namespace in which to install Tetragon")
"Namespace in which to install Tetragon")

flag.StringVar(&Opts.Helm.ValuesFile,
"tetragon.helm.values",
Opts.Helm.ValuesFile,
"path to a values.yaml file")
"Path to a values.yaml file")

flag.Var(&Opts.Helm.HelmValues,
"tetragon.helm.set",
"values to pass directly to helm, of the form k=v")
"Values to pass directly to helm, of the form k=v")

flag.BoolVar(&Opts.KeepExportData,
"tetragon.keep-export",
Opts.KeepExportData,
"should we keep export files regardless of pass/fail?")
"Should we keep export files regardless of pass/fail?")

flag.BoolVar(&Opts.InstallCilium,
"tetragon.install-cilium",
Opts.InstallCilium,
"should we install Cilium in the test?")
"Should we install Cilium in the test?")

flag.StringVar(&Opts.Helm.BTF,
"tetragon.btf",
Opts.Helm.BTF,
"A BTF file on the host that should be loaded into the KinD cluster. Will override helm BTF settings. Only makes sense when testing on a KinD cluster.")
}

type Flags struct {
Expand Down Expand Up @@ -103,6 +109,8 @@ type HelmOptions struct {
ValuesFile string
// Optional helm values (a map specifying values to set)
HelmValues
// BTF file to load into the kind cluster
BTF string
}

type HelmValues map[string]string
Expand Down
25 changes: 25 additions & 0 deletions tests/e2e/install/tetragon.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package install
import (
"context"
"fmt"
"os/exec"
"strings"

v1 "k8s.io/api/apps/v1"
Expand All @@ -25,6 +26,7 @@ import (
)

var (
AgentBTFKey = "tetragon.btf"
AgentImageKey = "tetragon.image.override"
OperatorImageKey = "tetragonOperator.image.override"
)
Expand Down Expand Up @@ -55,6 +57,10 @@ func WithValuesFile(file string) Option {
return func(o *flags.HelmOptions) { o.ValuesFile = file }
}

func WithBTF(BTF string) Option {
return func(o *flags.HelmOptions) { o.BTF = BTF }
}

func WithHelmOptions(options map[string]string) Option {
return func(o *flags.HelmOptions) {
if o.HelmValues == nil {
Expand Down Expand Up @@ -122,6 +128,25 @@ func Install(opts ...Option) env.Func {
if o.ValuesFile != "" {
helmArgs.WriteString(fmt.Sprintf(" --values=%s", o.ValuesFile))
}

// Handle BTF option for KinD cluster
if o.BTF != "" {
if clusterName := e2ehelpers.GetTempKindClusterName(ctx); clusterName != "" {
controlPlaneId := fmt.Sprintf("%s-control-plane", clusterName)
cmd := exec.CommandContext(ctx, "docker", "cp", o.BTF, fmt.Sprintf("%s:/btf", controlPlaneId))
err := cmd.Run()
if err != nil {
return ctx, fmt.Errorf("failed to load BTF file into KinD cluster: %w", err)
}
helmArgs.WriteString(fmt.Sprintf(" --set=%s=/btf", AgentBTFKey))
helmArgs.WriteString(" --set=extraHostPathMounts[0].name=btf")
helmArgs.WriteString(" --set=extraHostPathMounts[0].mountPath=/btf")
helmArgs.WriteString(" --set=extraHostPathMounts[0].readOnly=true")
} else {
return ctx, fmt.Errorf("option -tetragon.btf only makes sense for KinD clusters")
}
}

helmArgs.WriteString(" --install")

helmOpts := []helm.Option{
Expand Down