forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compat.go
139 lines (123 loc) · 3.03 KB
/
compat.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package cli
import (
"time"
"github.com/MakeNowJust/heredoc"
g "github.com/onsi/ginkgo"
o "github.com/onsi/gomega"
kapiv1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
exutil "github.com/openshift/origin/test/extended/util"
)
func cliPod(cli *exutil.CLI, shell string) *kapiv1.Pod {
cliImage, _ := exutil.FindCLIImage(cli)
return &kapiv1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "cli-test",
},
Spec: kapiv1.PodSpec{
RestartPolicy: kapiv1.RestartPolicyNever,
Containers: []kapiv1.Container{
{
Name: "test",
Image: cliImage,
Command: []string{"/bin/bash", "-c", "set -euo pipefail; " + shell},
Env: []kapiv1.EnvVar{
{
Name: "HOME",
Value: "/tmp",
},
},
},
},
},
}
}
func cliPodWithImage(cli *exutil.CLI, image string, shell string) *kapiv1.Pod {
cliImage, _ := exutil.FindCLIImage(cli)
return &kapiv1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "cli-test",
},
Spec: kapiv1.PodSpec{
ServiceAccountName: "builder",
RestartPolicy: kapiv1.RestartPolicyNever,
Volumes: []kapiv1.Volume{
{
Name: "bin",
VolumeSource: kapiv1.VolumeSource{
EmptyDir: &kapiv1.EmptyDirVolumeSource{},
},
},
},
InitContainers: []kapiv1.Container{
{
Name: "cli",
Image: cliImage,
Command: []string{"/bin/bash", "-c", "set -e; cp /usr/bin/oc /tmp/bin/"},
Env: []kapiv1.EnvVar{
{
Name: "HOME",
Value: "/tmp",
},
},
VolumeMounts: []kapiv1.VolumeMount{
{
Name: "bin",
MountPath: "/tmp/bin",
},
},
},
},
Containers: []kapiv1.Container{
{
Name: "test",
Image: cliImage,
Command: []string{"/bin/bash", "-c", "set -euo pipefail; export PATH=/tmp/bin:$PATH; " + shell},
Env: []kapiv1.EnvVar{
{
Name: "HOME",
Value: "/tmp",
},
},
VolumeMounts: []kapiv1.VolumeMount{
{
Name: "bin",
MountPath: "/tmp/bin",
},
},
},
},
},
}
}
var _ = g.Describe("[Feature:CLI] CLI", func() {
defer g.GinkgoRecover()
var oc *exutil.CLI
var ns string
g.AfterEach(func() {
if g.CurrentGinkgoTestDescription().Failed && len(ns) > 0 {
exutil.DumpPodLogsStartingWithInNamespace("", ns, oc)
}
})
oc = exutil.NewCLI("cli", exutil.KubeConfigPath())
g.It("can run inside of a busybox container", func() {
ns = oc.Namespace()
cli := oc.KubeFramework().PodClient()
_, err := oc.KubeClient().RbacV1().RoleBindings(ns).Create(&rbacv1.RoleBinding{
ObjectMeta: metav1.ObjectMeta{Name: "edit-for-builder"},
RoleRef: rbacv1.RoleRef{Kind: "ClusterRole", Name: "edit"},
Subjects: []rbacv1.Subject{
{Kind: "ServiceAccount", Name: "builder"},
},
})
o.Expect(err).NotTo(o.HaveOccurred())
pod := cli.Create(cliPodWithImage(oc, "busybox:latest", heredoc.Docf(`
set -x
# verify we can make API calls
oc get secrets
oc whoami
`)))
cli.WaitForSuccess(pod.Name, 5*time.Minute)
})
})