Path: blob/main/test/tests/workspace/ephemeral_storage_limit_test.go
2496 views
// Copyright (c) 2020 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package workspace56import (7"context"8"strings"9"testing"10"time"1112agent "github.com/gitpod-io/gitpod/test/pkg/agent/workspace/api"13"github.com/gitpod-io/gitpod/test/pkg/integration"14"sigs.k8s.io/e2e-framework/pkg/envconf"15"sigs.k8s.io/e2e-framework/pkg/features"16)1718func TestEphemeralStorageLimit(t *testing.T) {19f := features.New("ephemeral storage limit").20WithLabel("component", "workspace").21WithLabel("type", "ephemeral storage limit").22Assess("it should stop a workspace that reaches the ephemeral storage limit", func(testCtx context.Context, t *testing.T, cfg *envconf.Config) context.Context {23t.Parallel()2425ctx, cancel := context.WithTimeout(testCtx, time.Duration(5*time.Minute))26defer cancel()2728api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client())29t.Cleanup(func() {30api.Done(t)31})3233nfo, stopWs, err := integration.LaunchWorkspaceDirectly(t, ctx, api)34if err != nil {35t.Fatal(err)36}3738t.Cleanup(func() {39sctx, scancel := context.WithTimeout(context.Background(), 5*time.Minute)40defer scancel()4142sapi := integration.NewComponentAPI(sctx, cfg.Namespace(), kubeconfig, cfg.Client())43defer sapi.Done(t)4445if _, err = stopWs(true, sapi); err != nil {46t.Errorf("cannot stop workspace: %q", err)47}48})4950rsa, closer, err := integration.Instrument(integration.ComponentWorkspace, "workspace", cfg.Namespace(), kubeconfig, cfg.Client(), integration.WithInstanceID(nfo.Req.Id))51integration.DeferCloser(t, closer)52if err != nil {53t.Fatalf("unexpected error instrumenting workspace: %v", err)54}55defer rsa.Close()5657t.Logf("allocating disk space")58var res agent.ExecResponse59err = rsa.Call("WorkspaceAgent.Exec", &agent.ExecRequest{60Dir: "/workspace",61Command: "fallocate",62Args: []string{"-l", "11G", "/var/tmp/test1"},63}, &res)64if err != nil {65t.Fatal(err)66}67if res.ExitCode != 0 {68t.Fatalf("fallocate failed (%d): %s", res.ExitCode, res.Stderr)69}7071t.Logf("expecting workspace to stop")72ready := make(chan struct{}, 1)73status, err := integration.WaitForWorkspaceStop(t, ctx, ready, api, nfo.Req.Id, nfo.WorkspaceID, integration.WorkspaceCanFail)74if err != nil {75t.Fatal(err)76}7778t.Logf("workspace stopped, checking for failed condition")79if status == nil || status.Conditions == nil {80t.Fatalf("workspace status is empty: %v", status)81}82if status.Conditions.Failed == "" {83t.Fatalf("expected failed condition but got none: %v", status)84}8586expectedFailures := []string{87"Evicted: Pod ephemeral local storage usage exceeds the total limit of containers ",88// Until WKS-215 is fixed we can sometimes see the below error:89"container workspace completed; containers of a workspace pod are not supposed to do that",90}91foundExpectedFailure := false92for _, ef := range expectedFailures {93if strings.Contains(status.Conditions.Failed, ef) {94foundExpectedFailure = true95break96}97}98if !foundExpectedFailure {99t.Fatalf("expected failed condition to contain one of %v but got: %v", expectedFailures, status.Conditions.Failed)100}101t.Logf("workspace failed as expected: %v", status.Conditions.Failed)102103return testCtx104}).105Feature()106107testEnv.Test(t, f)108}109110111