Skip to content

Commit e7a83a3

Browse files
Add e2e test for Spintainer selective deployment
Signed-off-by: Kate Goldenring <[email protected]>
1 parent 5fdcba0 commit e7a83a3

File tree

2 files changed

+77
-8
lines changed

2 files changed

+77
-8
lines changed

e2e/selective_deployment_test.go

Lines changed: 75 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77

88
v1 "k8s.io/api/core/v1"
99
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10+
controllerruntimeclient "sigs.k8s.io/controller-runtime/pkg/client"
1011
"sigs.k8s.io/e2e-framework/klient"
1112
"sigs.k8s.io/e2e-framework/klient/wait"
1213
"sigs.k8s.io/e2e-framework/klient/wait/conditions"
@@ -71,20 +72,87 @@ func TestSelectiveDeployment(t *testing.T) {
7172
return ctx
7273
}).
7374
Assess("spin app is only serving hello component", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
74-
helper.EnsureDebugContainer(t, ctx, cfg, testNamespace)
75+
return testSelectiveDeploymentOfSalutationsApp(ctx, t, cfg, testSpinAppName)
76+
}).
77+
Feature()
78+
testEnv.Test(t, defaultTest)
79+
}
80+
81+
// TestSelectiveDeploymentSpintainer is a test that checks that selective deployment works
82+
func TestSelectiveDeploymentSpintainer(t *testing.T) {
83+
var client klient.Client
84+
85+
salutationsApp := "ghcr.io/kate-goldenring/spin-operator/examples/spin-salutations:20241022-144454"
86+
testSpinAppName := "test-spintainer-selective-deployment"
87+
88+
defaultTest := features.New("default and most minimal setup").
89+
Setup(func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
90+
91+
client = cfg.Client()
92+
93+
if err := spinapps_v1alpha1.AddToScheme(client.Resources(testNamespace).GetScheme()); err != nil {
94+
t.Fatalf("failed to register the spinapps_v1alpha1 types with Kubernetes scheme: %s", err)
95+
}
7596

76-
_, status, err := helper.CurlSpinApp(t, ctx, cfg, testNamespace, testSpinAppName, "/hi", "")
97+
return ctx
98+
}).
99+
Assess("spin app custom resource is created", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
100+
testSpinApp := newSpinAppCR(testSpinAppName, salutationsApp, "spintainer", []string{"hello"})
101+
102+
if err := client.Resources().Create(ctx, newSpintainerExecutor(testNamespace)); controllerruntimeclient.IgnoreAlreadyExists(err) != nil {
103+
t.Fatalf("Failed to create spinappexecutor: %s", err)
104+
}
77105

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

81-
_, status, err = helper.CurlSpinApp(t, ctx, cfg, testNamespace, testSpinAppName, "/bye", "")
110+
return ctx
111+
}).
112+
Assess("spin app deployment and service are available", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
113+
// wait for deployment to be ready
114+
if err := wait.For(
115+
conditions.New(client.Resources()).DeploymentAvailable(testSpinAppName, testNamespace),
116+
wait.WithTimeout(3*time.Minute),
117+
wait.WithInterval(time.Second),
118+
); err != nil {
119+
t.Fatal(err)
120+
}
82121

83-
require.NoError(t, err)
84-
require.Equal(t, 404, status)
122+
svc := &v1.ServiceList{
123+
Items: []v1.Service{
124+
{ObjectMeta: metav1.ObjectMeta{Name: testSpinAppName, Namespace: testNamespace}},
125+
},
126+
}
85127

128+
if err := wait.For(
129+
conditions.New(client.Resources()).ResourcesFound(svc),
130+
wait.WithTimeout(3*time.Minute),
131+
wait.WithInterval(500*time.Millisecond),
132+
); err != nil {
133+
t.Fatal(err)
134+
}
86135
return ctx
87136
}).
137+
Assess("spin app is only serving hello component", func(ctx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
138+
return testSelectiveDeploymentOfSalutationsApp(ctx, t, cfg, testSpinAppName)
139+
}).
88140
Feature()
89141
testEnv.Test(t, defaultTest)
90142
}
143+
144+
func testSelectiveDeploymentOfSalutationsApp(ctx context.Context, t *testing.T, cfg *envconf.Config, testSpinAppName string) context.Context {
145+
helper.EnsureDebugContainer(t, ctx, cfg, testNamespace)
146+
147+
_, status, err := helper.CurlSpinApp(t, ctx, cfg, testNamespace, testSpinAppName, "/hi", "")
148+
149+
require.NoError(t, err)
150+
require.Equal(t, 200, status)
151+
152+
_, status, err = helper.CurlSpinApp(t, ctx, cfg, testNamespace, testSpinAppName, "/bye", "")
153+
154+
require.NoError(t, err)
155+
require.Equal(t, 404, status)
156+
157+
return ctx
158+
}

e2e/spintainer_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ func newSpintainerExecutor(namespace string) *spinapps_v1alpha1.SpinAppExecutor
8888
Spec: spinapps_v1alpha1.SpinAppExecutorSpec{
8989
CreateDeployment: true,
9090
DeploymentConfig: &spinapps_v1alpha1.ExecutorDeploymentConfig{
91-
SpinImage: generics.Ptr("ghcr.io/fermyon/spin:v2.7.0"),
91+
// TODO: pin this to Spin 3.0 once released
92+
SpinImage: generics.Ptr("ghcr.io/fermyon/spin:canary"),
9293
},
9394
},
9495
}

0 commit comments

Comments
 (0)