1/*
2Copyright 2020 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8    http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package node
18
19import (
20	"fmt"
21
22	v1 "k8s.io/api/core/v1"
23	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24	imageutils "k8s.io/kubernetes/test/utils/image"
25	utilpointer "k8s.io/utils/pointer"
26)
27
28// PreconfiguredRuntimeClassHandler returns configured runtime handler.
29func PreconfiguredRuntimeClassHandler(handler string) string {
30	if handler == "docker" {
31		return handler
32	}
33
34	// test-handler is the name of the runtime handler that is expected to be
35	// preconfigured in the test environment.
36	return "test-handler"
37}
38
39// NewRuntimeClassPod returns a test pod with the given runtimeClassName
40func NewRuntimeClassPod(runtimeClassName string) *v1.Pod {
41	return &v1.Pod{
42		ObjectMeta: metav1.ObjectMeta{
43			GenerateName: fmt.Sprintf("test-runtimeclass-%s-", runtimeClassName),
44		},
45		Spec: v1.PodSpec{
46			RuntimeClassName: &runtimeClassName,
47			Containers: []v1.Container{{
48				Name:    "test",
49				Image:   imageutils.GetE2EImage(imageutils.BusyBox),
50				Command: []string{"true"},
51			}},
52			RestartPolicy:                v1.RestartPolicyNever,
53			AutomountServiceAccountToken: utilpointer.BoolPtr(false),
54		},
55	}
56}
57