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

e2e: speed up #310

Merged
merged 1 commit into from
Aug 27, 2024
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
67 changes: 14 additions & 53 deletions e2e/default_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/e2e-framework/klient"
"sigs.k8s.io/e2e-framework/klient/k8s"
"sigs.k8s.io/e2e-framework/klient/wait"
"sigs.k8s.io/e2e-framework/klient/wait/conditions"
"sigs.k8s.io/e2e-framework/pkg/envconf"
Expand All @@ -29,49 +28,28 @@ func TestDefaultSetup(t *testing.T) {

defaultTest := features.New("default and most minimal setup").
Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {

client = cfg.Client()

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)
}

return ctx
}).
Assess("spin app custom resource is created", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
testSpinApp := newSpinAppCR(testSpinAppName, helloWorldImage)

if err := client.Resources().Create(ctx, newContainerdShimExecutor(testNamespace)); err != nil {
t.Fatalf("Failed to create spinappexecutor: %s", err)
}

if err := client.Resources().Create(ctx, testSpinApp); err != nil {
t.Fatalf("Failed to create spinapp: %s", err)
}
// wait for spinapp to be created
if err := wait.For(
conditions.New(client.Resources()).ResourceMatch(testSpinApp, func(object k8s.Object) bool {
return true
}),
wait.WithTimeout(3*time.Minute),
wait.WithInterval(30*time.Second),
); err != nil {
t.Fatal(err)
}

return ctx
}).
Assess("spin app deployment and service are available", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {

// wait for deployment to be ready
if err := wait.For(
conditions.New(client.Resources()).DeploymentAvailable(testSpinAppName, testNamespace),
wait.WithTimeout(3*time.Minute),
wait.WithInterval(30*time.Second),
); err != nil {
t.Fatal(err)
}

Assess("spin app deployment is created and available",
func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
if err := wait.For(
conditions.New(client.Resources()).DeploymentAvailable(testSpinAppName, testNamespace),
wait.WithTimeout(3*time.Minute),
wait.WithInterval(time.Second),
); err != nil {
t.Fatal(err)
}

return ctx
}).
Assess("spin app service is created and available", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
svc := &corev1.ServiceList{
Items: []corev1.Service{
{ObjectMeta: metav1.ObjectMeta{Name: testSpinAppName, Namespace: testNamespace}},
Expand All @@ -81,7 +59,7 @@ func TestDefaultSetup(t *testing.T) {
if err := wait.For(
conditions.New(client.Resources()).ResourcesFound(svc),
wait.WithTimeout(3*time.Minute),
wait.WithInterval(30*time.Second),
wait.WithInterval(time.Second),
); err != nil {
t.Fatal(err)
}
Expand All @@ -104,20 +82,3 @@ func newSpinAppCR(name, image string) *spinapps_v1alpha1.SpinApp {
},
}
}

func newContainerdShimExecutor(namespace string) *spinapps_v1alpha1.SpinAppExecutor {
return &spinapps_v1alpha1.SpinAppExecutor{
ObjectMeta: metav1.ObjectMeta{
Name: "containerd-shim-spin",
Namespace: namespace,
},
Spec: spinapps_v1alpha1.SpinAppExecutorSpec{
CreateDeployment: true,
DeploymentConfig: &spinapps_v1alpha1.ExecutorDeploymentConfig{
RuntimeClassName: runtimeClassName,
InstallDefaultCACerts: true,
CACertSecret: testCACertSecret,
},
},
}
}
36 changes: 34 additions & 2 deletions e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"sigs.k8s.io/e2e-framework/pkg/envconf"
"sigs.k8s.io/e2e-framework/pkg/envfuncs"
"sigs.k8s.io/e2e-framework/support/utils"

spinapps_v1alpha1 "github.com/spinkube/spin-operator/api/v1alpha1"
)

const ErrFormat = "%v: %v\n"
Expand All @@ -35,7 +37,6 @@ func TestMain(m *testing.M) {
cluster.name = envconf.RandomName("crdtest-", 16)

testEnv.Setup(

func(ctx context.Context, e *envconf.Config) (context.Context, error) {
if _, err := cluster.Create(ctx, cluster.name); err != nil {
return ctx, err
Expand Down Expand Up @@ -85,6 +86,11 @@ func TestMain(m *testing.M) {

// wait for the controller deployment to be ready
client := cfg.Client()

if err := spinapps_v1alpha1.AddToScheme(client.Resources().GetScheme()); err != nil {
return ctx, fmt.Errorf("failed to register the spinapps_v1alpha1 types with Kubernetes scheme: %w", err)
}

if err := wait.For(
conditions.New(client.Resources()).
DeploymentAvailable(spinOperatorDeploymentName, spinOperatorNamespace),
Expand All @@ -96,7 +102,8 @@ func TestMain(m *testing.M) {

return ctx, nil
},
// deploy runtime class

// create runtime class
func(ctx context.Context, c *envconf.Config) (context.Context, error) {
client := cfg.Client()
runtimeClass := &nodev1.RuntimeClass{
Expand All @@ -109,6 +116,14 @@ func TestMain(m *testing.M) {
err := client.Resources().Create(ctx, runtimeClass)
return ctx, err
},

// create executor
func(ctx context.Context, c *envconf.Config) (context.Context, error) {
client := cfg.Client()

err := client.Resources().Create(ctx, newContainerdShimExecutor(testNamespace))
return ctx, err
},
)

testEnv.Finish(
Expand All @@ -119,3 +134,20 @@ func TestMain(m *testing.M) {

os.Exit(testEnv.Run(m))
}

func newContainerdShimExecutor(namespace string) *spinapps_v1alpha1.SpinAppExecutor {
return &spinapps_v1alpha1.SpinAppExecutor{
ObjectMeta: metav1.ObjectMeta{
Name: "containerd-shim-spin",
Namespace: namespace,
},
Spec: spinapps_v1alpha1.SpinAppExecutorSpec{
CreateDeployment: true,
DeploymentConfig: &spinapps_v1alpha1.ExecutorDeploymentConfig{
RuntimeClassName: runtimeClassName,
InstallDefaultCACerts: true,
CACertSecret: testCACertSecret,
},
},
}
}
Loading