Skip to content

Commit

Permalink
e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
EronWright committed Feb 8, 2025
1 parent e9be1ff commit 72f80c8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
34 changes: 33 additions & 1 deletion operator/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ func TestE2E(t *testing.T) {
assert.NoError(t, err)
t.Log(string(out))
}

// cleanup
cmd = exec.Command("kubectl", "delete", "-f", "e2e/testdata/random-yaml-nonroot")
require.NoError(t, run(cmd))
},
},
{
Expand All @@ -135,6 +139,10 @@ func TestE2E(t *testing.T) {

assert.Equal(t, `"[secret]"`, string(stack.Status.Outputs["secretOutput"].Raw))
assert.Equal(t, `"foo"`, string(stack.Status.Outputs["simpleOutput"].Raw))

// cleanup
cmd = exec.Command("bash", "-c", "envsubst < e2e/testdata/git-auth-nonroot/* | kubectl delete -f -")
require.NoError(t, run(cmd))
},
},
{
Expand All @@ -149,15 +157,21 @@ func TestE2E(t *testing.T) {

assert.Contains(t, stack.Status.Outputs, "targeted")
assert.NotContains(t, stack.Status.Outputs, "notTargeted")

// cleanup
cmd = exec.Command("kubectl", "delete", "-f", "e2e/testdata/targets")
require.NoError(t, run(cmd))
},
},
{
name: "issue-801",
f: func(t *testing.T) {
dumpEvents(t, "issue-801")
dumpLogs(t, "issue-801", "pods/issue-801-workspace-0")

// deploy a workspace with a non-existent container image (pulumi:nosuchimage)
cmd := exec.Command("kubectl", "apply", "-f", "e2e/testdata/issue-801")
require.NoError(t, run(cmd))
dumpLogs(t, "issue-801", "pods/issue-801-workspace-0")

// wait for the pod to be created (knowing that it will never become ready)
_, err := waitFor[corev1.Pod]("pods/issue-801-workspace-0", "issue-801", 5*time.Minute, "create")
Expand All @@ -170,6 +184,10 @@ func TestE2E(t *testing.T) {
// wait for the workspace to be fully ready
_, err = waitFor[autov1alpha1.Workspace]("workspaces/issue-801", "issue-801", 5*time.Minute, "condition=Ready")
assert.NoError(t, err)

// cleanup
cmd = exec.Command("kubectl", "delete", "-f", "e2e/testdata/issue-801")
require.NoError(t, run(cmd))
},
},
}
Expand Down Expand Up @@ -206,6 +224,20 @@ func dumpLogs(t *testing.T, namespace, name string) {
})
}


func dumpEvents(t *testing.T, namespace string) {
t.Cleanup(func() {
if !t.Failed() {
return
}
t.Logf("=== EVENTS %s", namespace)
cmd := exec.Command("kubectl", "get", "events", "-n", namespace)
out, err := cmd.CombinedOutput()
assert.NoError(t, err)
t.Log(string(out))
})
}

func waitFor[T any](name, namespace string, d time.Duration, conditions ...string) (*T, error) {
if len(conditions) == 0 {
return nil, fmt.Errorf("no conditions provided")
Expand Down
1 change: 1 addition & 0 deletions operator/e2e/testdata/issue-801/manifests.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# note: image is purposefully set to a non-existent image to simulate a rollout problem
apiVersion: v1
kind: Namespace
metadata:
Expand Down
2 changes: 1 addition & 1 deletion operator/internal/controller/auto/workspace_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (r *WorkspaceReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
}
err = r.Patch(ctx, ss, client.Apply, client.FieldOwner(FieldManager))
if err != nil {
// issue-801 - migration logic for 2.0-beta.3 to 2.0.0
// issue-801 - migration logic for 2.0.0-beta.3 to 2.0.0
if apierrors.IsInvalid(err) {
l.V(0).Info("replacing the workspace statefulset to update an immutable field")
if err = r.Delete(ctx, ss); err != nil {
Expand Down

0 comments on commit 72f80c8

Please sign in to comment.