From 639ec7f5279552c4a55e886eabb755a479d7da57 Mon Sep 17 00:00:00 2001 From: Michelle Dhanani Date: Wed, 6 Mar 2024 01:41:09 -0500 Subject: [PATCH] add e2e to github workflow + adds e2e make target for running e2es + updates return err to include output for better debugging experience + add workflow for checking e2e on PRs to main Signed-off-by: Michelle Dhanani --- .github/workflows/e2e.yaml | 18 ++++++++++++++++++ Makefile | 4 ++++ e2e/default_test.go | 20 ++++++++++---------- e2e/main_test.go | 18 ++++++++++++------ go.mod | 2 +- go.sum | 4 ++-- 6 files changed, 47 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/e2e.yaml diff --git a/.github/workflows/e2e.yaml b/.github/workflows/e2e.yaml new file mode 100644 index 00000000..8c719733 --- /dev/null +++ b/.github/workflows/e2e.yaml @@ -0,0 +1,18 @@ +name: e2e + +on: + pull_request: + branches: [main] + +jobs: + e2e: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Setup Go + uses: actions/setup-go@v5 + with: + go-version: "1.22.x" + cache: true + - name: run e2e + run: go test ./e2e -v diff --git a/Makefile b/Makefile index afa6e440..2319e824 100644 --- a/Makefile +++ b/Makefile @@ -291,3 +291,7 @@ $(ENVTEST): $(LOCALBIN) helmify: $(HELMIFY) ## Download helmify locally if necessary. $(HELMIFY): $(LOCALBIN) @test -s $(LOCALBIN)/helmify || GOBIN=$(LOCALBIN) go install github.com/arttor/helmify/cmd/helmify@$(HELMIFY_VESRION) + +.PHONY: e2e +e2e: ## Run e2e tests + go test -v ./e2e/... diff --git a/e2e/default_test.go b/e2e/default_test.go index b441091e..65579195 100644 --- a/e2e/default_test.go +++ b/e2e/default_test.go @@ -15,7 +15,7 @@ import ( "sigs.k8s.io/e2e-framework/pkg/envconf" "sigs.k8s.io/e2e-framework/pkg/features" - spinapps_v1 "github.com/spinkube/spin-operator/api/v1" + spinapps_v1alpha1 "github.com/spinkube/spin-operator/api/v1alpha1" ) var runtimeClassName = "wasmtime-spin-v2" @@ -33,8 +33,8 @@ func TestDefaultSetup(t *testing.T) { client = cfg.Client() - if err := spinapps_v1.AddToScheme(client.Resources(testNamespace).GetScheme()); err != nil { - t.Fatalf("failed to register the spinapps_v1 types with Kuberenets scheme: %s", err) + if err := spinapps_v1alpha1.AddToScheme(client.Resources(testNamespace).GetScheme()); err != nil { + t.Fatalf("failed to register the spinapps_v1alpha1 types with Kuberenets scheme: %s", err) } runtimeClass := &nodev1.RuntimeClass{ @@ -102,13 +102,13 @@ func TestDefaultSetup(t *testing.T) { testEnv.Test(t, defaultTest) } -func newSpinAppCR(name, image string) *spinapps_v1.SpinApp { - var testSpinApp = &spinapps_v1.SpinApp{ +func newSpinAppCR(name, image string) *spinapps_v1alpha1.SpinApp { + var testSpinApp = &spinapps_v1alpha1.SpinApp{ ObjectMeta: metav1.ObjectMeta{ Name: name, Namespace: testNamespace, }, - Spec: spinapps_v1.SpinAppSpec{ + Spec: spinapps_v1alpha1.SpinAppSpec{ Replicas: 1, Image: image, Executor: "containerd-shim-spin", @@ -119,15 +119,15 @@ func newSpinAppCR(name, image string) *spinapps_v1.SpinApp { } -func newContainerdShimExecutor(namespace string) *spinapps_v1.SpinAppExecutor { - var testSpinAppExecutor = &spinapps_v1.SpinAppExecutor{ +func newContainerdShimExecutor(namespace string) *spinapps_v1alpha1.SpinAppExecutor { + var testSpinAppExecutor = &spinapps_v1alpha1.SpinAppExecutor{ ObjectMeta: metav1.ObjectMeta{ Name: "containerd-shim-spin", Namespace: namespace, }, - Spec: spinapps_v1.SpinAppExecutorSpec{ + Spec: spinapps_v1alpha1.SpinAppExecutorSpec{ CreateDeployment: true, - DeploymentConfig: &spinapps_v1.ExecutorDeploymentConfig{ + DeploymentConfig: &spinapps_v1alpha1.ExecutorDeploymentConfig{ RuntimeClassName: runtimeClassName, }, }, diff --git a/e2e/main_test.go b/e2e/main_test.go index 418c1c65..16ee1dcf 100644 --- a/e2e/main_test.go +++ b/e2e/main_test.go @@ -2,6 +2,7 @@ package e2e import ( "context" + "fmt" "os" "testing" "time" @@ -14,6 +15,8 @@ import ( "sigs.k8s.io/e2e-framework/support/utils" ) +const ErrFormat = "%v: %v\n" + var ( testEnv env.Environment testNamespace string @@ -44,11 +47,12 @@ func TestMain(m *testing.M) { // build and load spin operator image into cluster func(ctx context.Context, _ *envconf.Config) (context.Context, error) { if p := utils.RunCommand(`bash -c "cd .. && IMG=ghcr.io/spinkube/spin-operator:dev make docker-build"`); p.Err() != nil { - return ctx, p.Err() + + return ctx, fmt.Errorf(ErrFormat, p.Err(), p.Out()) } if p := utils.RunCommand(("k3d image import -c " + cluster.name + " ghcr.io/spinkube/spin-operator:dev")); p.Err() != nil { - return ctx, p.Err() + return ctx, fmt.Errorf(ErrFormat, p.Err(), p.Out()) } return ctx, nil }, @@ -57,20 +61,22 @@ func TestMain(m *testing.M) { func(ctx context.Context, _ *envconf.Config) (context.Context, error) { // install crds if p := utils.RunCommand(`bash -c "cd .. && make install"`); p.Err() != nil { - return ctx, p.Err() + + return ctx, fmt.Errorf(ErrFormat, p.Err(), p.Out()) + } // install cert-manager if p := utils.RunCommand("kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.14.2/cert-manager.yaml"); p.Err() != nil { - return ctx, p.Err() + return ctx, fmt.Errorf(ErrFormat, p.Err(), p.Out()) } // wait for cert-manager to be ready if p := utils.RunCommand("kubectl wait --for=condition=Available --timeout=300s deployment/cert-manager-webhook -n cert-manager"); p.Err() != nil { - return ctx, p.Err() + return ctx, fmt.Errorf(ErrFormat, p.Err(), p.Out()) } if p := utils.RunCommand(`bash -c "cd .. && IMG=ghcr.io/spinkube/spin-operator:dev make deploy"`); p.Err() != nil { - return ctx, p.Err() + return ctx, fmt.Errorf(ErrFormat, p.Err(), p.Out()) } // wait for the controller deployment to be ready diff --git a/go.mod b/go.mod index 6abcf036..14fbd712 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/go-logr/logr v1.4.1 github.com/pelletier/go-toml/v2 v2.1.1 github.com/prometheus/common v0.49.0 - github.com/stretchr/testify v1.9.0 + github.com/stretchr/testify v1.8.4 golang.org/x/sync v0.5.0 k8s.io/api v0.29.2 k8s.io/apiextensions-apiserver v0.29.0 diff --git a/go.sum b/go.sum index cec9387a..5c9e9d6a 100644 --- a/go.sum +++ b/go.sum @@ -110,8 +110,8 @@ github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UV github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/vladimirvivien/gexe v0.2.0 h1:nbdAQ6vbZ+ZNsolCgSVb9Fno60kzSuvtzVh6Ytqi/xY= github.com/vladimirvivien/gexe v0.2.0/go.mod h1:LHQL00w/7gDUKIak24n801ABp8C+ni6eBht9vGVst8w= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=