Skip to content

Commit

Permalink
add e2e to github workflow
Browse files Browse the repository at this point in the history
+ 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 <[email protected]>
  • Loading branch information
michelleN committed Mar 8, 2024
1 parent 9bfb7dc commit 639ec7f
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 19 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/...
20 changes: 10 additions & 10 deletions e2e/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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{
Expand Down Expand Up @@ -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",
Expand All @@ -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,
},
},
Expand Down
18 changes: 12 additions & 6 deletions e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package e2e

import (
"context"
"fmt"
"os"
"testing"
"time"
Expand All @@ -14,6 +15,8 @@ import (
"sigs.k8s.io/e2e-framework/support/utils"
)

const ErrFormat = "%v: %v\n"

var (
testEnv env.Environment
testNamespace string
Expand Down Expand Up @@ -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
},
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 639ec7f

Please sign in to comment.