Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/test/tests/workspace/ephemeral_storage_limit_test.go
2496 views
1
// Copyright (c) 2020 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package workspace
6
7
import (
8
"context"
9
"strings"
10
"testing"
11
"time"
12
13
agent "github.com/gitpod-io/gitpod/test/pkg/agent/workspace/api"
14
"github.com/gitpod-io/gitpod/test/pkg/integration"
15
"sigs.k8s.io/e2e-framework/pkg/envconf"
16
"sigs.k8s.io/e2e-framework/pkg/features"
17
)
18
19
func TestEphemeralStorageLimit(t *testing.T) {
20
f := features.New("ephemeral storage limit").
21
WithLabel("component", "workspace").
22
WithLabel("type", "ephemeral storage limit").
23
Assess("it should stop a workspace that reaches the ephemeral storage limit", func(testCtx context.Context, t *testing.T, cfg *envconf.Config) context.Context {
24
t.Parallel()
25
26
ctx, cancel := context.WithTimeout(testCtx, time.Duration(5*time.Minute))
27
defer cancel()
28
29
api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client())
30
t.Cleanup(func() {
31
api.Done(t)
32
})
33
34
nfo, stopWs, err := integration.LaunchWorkspaceDirectly(t, ctx, api)
35
if err != nil {
36
t.Fatal(err)
37
}
38
39
t.Cleanup(func() {
40
sctx, scancel := context.WithTimeout(context.Background(), 5*time.Minute)
41
defer scancel()
42
43
sapi := integration.NewComponentAPI(sctx, cfg.Namespace(), kubeconfig, cfg.Client())
44
defer sapi.Done(t)
45
46
if _, err = stopWs(true, sapi); err != nil {
47
t.Errorf("cannot stop workspace: %q", err)
48
}
49
})
50
51
rsa, closer, err := integration.Instrument(integration.ComponentWorkspace, "workspace", cfg.Namespace(), kubeconfig, cfg.Client(), integration.WithInstanceID(nfo.Req.Id))
52
integration.DeferCloser(t, closer)
53
if err != nil {
54
t.Fatalf("unexpected error instrumenting workspace: %v", err)
55
}
56
defer rsa.Close()
57
58
t.Logf("allocating disk space")
59
var res agent.ExecResponse
60
err = rsa.Call("WorkspaceAgent.Exec", &agent.ExecRequest{
61
Dir: "/workspace",
62
Command: "fallocate",
63
Args: []string{"-l", "11G", "/var/tmp/test1"},
64
}, &res)
65
if err != nil {
66
t.Fatal(err)
67
}
68
if res.ExitCode != 0 {
69
t.Fatalf("fallocate failed (%d): %s", res.ExitCode, res.Stderr)
70
}
71
72
t.Logf("expecting workspace to stop")
73
ready := make(chan struct{}, 1)
74
status, err := integration.WaitForWorkspaceStop(t, ctx, ready, api, nfo.Req.Id, nfo.WorkspaceID, integration.WorkspaceCanFail)
75
if err != nil {
76
t.Fatal(err)
77
}
78
79
t.Logf("workspace stopped, checking for failed condition")
80
if status == nil || status.Conditions == nil {
81
t.Fatalf("workspace status is empty: %v", status)
82
}
83
if status.Conditions.Failed == "" {
84
t.Fatalf("expected failed condition but got none: %v", status)
85
}
86
87
expectedFailures := []string{
88
"Evicted: Pod ephemeral local storage usage exceeds the total limit of containers ",
89
// Until WKS-215 is fixed we can sometimes see the below error:
90
"container workspace completed; containers of a workspace pod are not supposed to do that",
91
}
92
foundExpectedFailure := false
93
for _, ef := range expectedFailures {
94
if strings.Contains(status.Conditions.Failed, ef) {
95
foundExpectedFailure = true
96
break
97
}
98
}
99
if !foundExpectedFailure {
100
t.Fatalf("expected failed condition to contain one of %v but got: %v", expectedFailures, status.Conditions.Failed)
101
}
102
t.Logf("workspace failed as expected: %v", status.Conditions.Failed)
103
104
return testCtx
105
}).
106
Feature()
107
108
testEnv.Test(t, f)
109
}
110
111