|
7 | 7 |
|
8 | 8 | v1 "k8s.io/api/core/v1" |
9 | 9 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 10 | + controllerruntimeclient "sigs.k8s.io/controller-runtime/pkg/client" |
10 | 11 | "sigs.k8s.io/e2e-framework/klient" |
11 | 12 | "sigs.k8s.io/e2e-framework/klient/wait" |
12 | 13 | "sigs.k8s.io/e2e-framework/klient/wait/conditions" |
@@ -71,20 +72,87 @@ func TestSelectiveDeployment(t *testing.T) { |
71 | 72 | return ctx |
72 | 73 | }). |
73 | 74 | 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 | + } |
75 | 96 |
|
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 | + } |
77 | 105 |
|
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 | + } |
80 | 109 |
|
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 | + } |
82 | 121 |
|
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 | + } |
85 | 127 |
|
| 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 | + } |
86 | 135 | return ctx |
87 | 136 | }). |
| 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 | + }). |
88 | 140 | Feature() |
89 | 141 | testEnv.Test(t, defaultTest) |
90 | 142 | } |
| 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 | +} |
0 commit comments