Skip to content

Commit

Permalink
Add e2e test for Spintainer selective deployment
Browse files Browse the repository at this point in the history
Signed-off-by: Kate Goldenring <[email protected]>
  • Loading branch information
kate-goldenring committed Nov 4, 2024
1 parent 5fdcba0 commit e7a83a3
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 8 deletions.
82 changes: 75 additions & 7 deletions e2e/selective_deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
controllerruntimeclient "sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/e2e-framework/klient"
"sigs.k8s.io/e2e-framework/klient/wait"
"sigs.k8s.io/e2e-framework/klient/wait/conditions"
Expand Down Expand Up @@ -71,20 +72,87 @@ func TestSelectiveDeployment(t *testing.T) {
return ctx
}).
Assess("spin app is only serving hello component", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
helper.EnsureDebugContainer(t, ctx, cfg, testNamespace)
return testSelectiveDeploymentOfSalutationsApp(ctx, t, cfg, testSpinAppName)
}).
Feature()
testEnv.Test(t, defaultTest)
}

// TestSelectiveDeploymentSpintainer is a test that checks that selective deployment works
func TestSelectiveDeploymentSpintainer(t *testing.T) {
var client klient.Client

salutationsApp := "ghcr.io/kate-goldenring/spin-operator/examples/spin-salutations:20241022-144454"
testSpinAppName := "test-spintainer-selective-deployment"

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 Kubernetes scheme: %s", err)
}

_, status, err := helper.CurlSpinApp(t, ctx, cfg, testNamespace, testSpinAppName, "/hi", "")
return ctx
}).
Assess("spin app custom resource is created", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
testSpinApp := newSpinAppCR(testSpinAppName, salutationsApp, "spintainer", []string{"hello"})

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

require.NoError(t, err)
require.Equal(t, 200, status)
if err := client.Resources().Create(ctx, testSpinApp); err != nil {
t.Fatalf("Failed to create spinapp: %s", err)
}

_, status, err = helper.CurlSpinApp(t, ctx, cfg, testNamespace, testSpinAppName, "/bye", "")
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(time.Second),
); err != nil {
t.Fatal(err)
}

require.NoError(t, err)
require.Equal(t, 404, status)
svc := &v1.ServiceList{
Items: []v1.Service{
{ObjectMeta: metav1.ObjectMeta{Name: testSpinAppName, Namespace: testNamespace}},
},
}

if err := wait.For(
conditions.New(client.Resources()).ResourcesFound(svc),
wait.WithTimeout(3*time.Minute),
wait.WithInterval(500*time.Millisecond),
); err != nil {
t.Fatal(err)
}
return ctx
}).
Assess("spin app is only serving hello component", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
return testSelectiveDeploymentOfSalutationsApp(ctx, t, cfg, testSpinAppName)
}).
Feature()
testEnv.Test(t, defaultTest)
}

func testSelectiveDeploymentOfSalutationsApp(ctx context.Context, t *testing.T, cfg *envconf.Config, testSpinAppName string) context.Context {
helper.EnsureDebugContainer(t, ctx, cfg, testNamespace)

_, status, err := helper.CurlSpinApp(t, ctx, cfg, testNamespace, testSpinAppName, "/hi", "")

require.NoError(t, err)
require.Equal(t, 200, status)

_, status, err = helper.CurlSpinApp(t, ctx, cfg, testNamespace, testSpinAppName, "/bye", "")

require.NoError(t, err)
require.Equal(t, 404, status)

return ctx
}
3 changes: 2 additions & 1 deletion e2e/spintainer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ func newSpintainerExecutor(namespace string) *spinapps_v1alpha1.SpinAppExecutor
Spec: spinapps_v1alpha1.SpinAppExecutorSpec{
CreateDeployment: true,
DeploymentConfig: &spinapps_v1alpha1.ExecutorDeploymentConfig{
SpinImage: generics.Ptr("ghcr.io/fermyon/spin:v2.7.0"),
// TODO: pin this to Spin 3.0 once released
SpinImage: generics.Ptr("ghcr.io/fermyon/spin:canary"),
},
},
}
Expand Down

0 comments on commit e7a83a3

Please sign in to comment.