/ kubernetes / test / e2e_runtime / gvisor / suite_test.go
suite_test.go
 1  // Copyright 2025 Alibaba Group Holding Ltd.
 2  //
 3  // Licensed under the Apache License, Version 2.0 (the "License");
 4  // you may not use this file except in compliance with the License.
 5  // You may obtain a copy of the License at
 6  //
 7  //     http://www.apache.org/licenses/LICENSE-2.0
 8  //
 9  // Unless required by applicable law or agreed to in writing, software
10  // distributed under the License is distributed on an "AS IS" BASIS,
11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  // See the License for the specific language governing permissions and
13  // limitations under the License.
14  
15  package gvisor
16  
17  import (
18  	"fmt"
19  	"os"
20  	"os/exec"
21  	"testing"
22  
23  	"github.com/alibaba/OpenSandbox/sandbox-k8s/test/utils"
24  	. "github.com/onsi/ginkgo/v2"
25  	. "github.com/onsi/gomega"
26  )
27  
28  const (
29  	// RuntimeClassName is the name of the RuntimeClass for gVisor
30  	RuntimeClassName = "gvisor"
31  )
32  
33  // KindCluster is the name of the Kind cluster for gVisor tests.
34  // It reads from KIND_CLUSTER environment variable, defaulting to "gvisor-test".
35  var KindCluster = getKindCluster()
36  
37  func getKindCluster() string {
38  	if v, ok := os.LookupEnv("KIND_CLUSTER"); ok {
39  		return v
40  	}
41  	return "gvisor-test"
42  }
43  
44  // TestGVisorRuntimeClass runs the gVisor RuntimeClass end-to-end tests.
45  // These tests validate gVisor functionality with the Kind cluster
46  // configured specifically for gVisor (runsc) runtime.
47  func TestGVisorRuntimeClass(t *testing.T) {
48  	RegisterFailHandler(Fail)
49  	_, _ = fmt.Fprintf(GinkgoWriter, "Starting gVisor RuntimeClass E2E test suite\n")
50  	RunSpecs(t, "gVisor runtimeclass suite")
51  }
52  
53  var _ = BeforeSuite(func() {
54  	dockerBuildArgs := os.Getenv("DOCKER_BUILD_ARGS")
55  
56  	By("building task-executor image")
57  	makeArgs := []string{"docker-build-task-executor", fmt.Sprintf("TASK_EXECUTOR_IMG=%s", utils.TaskExecutorImage)}
58  	if dockerBuildArgs != "" {
59  		makeArgs = append(makeArgs, fmt.Sprintf("DOCKER_BUILD_ARGS=%s", dockerBuildArgs))
60  	}
61  	cmd := exec.Command("make", makeArgs...)
62  	cmd.Dir = "../../.." // Navigate from test/e2e_runtime/gvisor to project root
63  	output, err := cmd.CombinedOutput()
64  	ExpectWithOffset(1, err).NotTo(HaveOccurred(), "Failed to build task-executor image: %s", string(output))
65  
66  	By("loading task-executor image on Kind")
67  	// Use kind command directly to load image, avoiding utils.GetProjectDir() path issues
68  	cmd = exec.Command("kind", "load", "docker-image", "--name", KindCluster, utils.TaskExecutorImage)
69  	cmd.Dir = "../../.." // Navigate from test/e2e_runtime/gvisor to project root
70  	output, err = cmd.CombinedOutput()
71  	ExpectWithOffset(1, err).NotTo(HaveOccurred(), "Failed to load task-executor image into Kind: %s", string(output))
72  })
73  
74  var _ = AfterSuite(func() {
75  })