forked from grafana/xk6-kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexec-command.js
42 lines (35 loc) · 981 Bytes
/
exec-command.js
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
import { sleep } from 'k6';
import { Kubernetes } from 'k6/x/kubernetes';
export default function () {
const kubernetes = new Kubernetes({
})
const namespace = "default"
const podName = "new-pod"
const image = "busybox"
const command = ["sh", "-c", "sleep 300"]
kubernetes.pods.create({
namespace: namespace,
name: podName,
image: image,
command: command
})
sleep(3)
const newPod = kubernetes.pods.list(namespace).find(function(pod) { return pod.name == podName})
if (!newPod) {
throw podName + " pod was not created"
}
const container = newPod.spec.containers[0].name
const result = kubernetes.pods.exec({
namespace: namespace,
pod: podName,
container: container.name,
command: ["echo", "'hello xk6'"],
stadin: []
})
const stdout = String.fromCharCode(...result.stdout)
if (stdout.includes("xk6")) {
console.log("command executed")
} else {
throw "command not executed correctly"
}
}