summaryrefslogtreecommitdiff
path: root/spec/support
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2016-11-22 19:55:56 +0000
committerNick Thomas <nick@gitlab.com>2016-12-19 19:53:04 +0000
commitc3d972f4e861059312c2708dacb57999416fcc70 (patch)
tree977d60c01a81da4157aa1961b244e9967c9168ee /spec/support
parent5378302763e1a461bab5213aa379d5b9e6dc322c (diff)
downloadgitlab-ce-c3d972f4e861059312c2708dacb57999416fcc70.tar.gz
Add terminals to the Kubernetes deployment service
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/kubernetes_helpers.rb52
1 files changed, 52 insertions, 0 deletions
diff --git a/spec/support/kubernetes_helpers.rb b/spec/support/kubernetes_helpers.rb
new file mode 100644
index 00000000000..6c4c246a68b
--- /dev/null
+++ b/spec/support/kubernetes_helpers.rb
@@ -0,0 +1,52 @@
+module KubernetesHelpers
+ include Gitlab::Kubernetes
+
+ def kube_discovery_body
+ { "kind" => "APIResourceList",
+ "resources" => [
+ { "name" => "pods", "namespaced" => true, "kind" => "Pod" },
+ ],
+ }
+ end
+
+ def kube_pods_body(*pods)
+ { "kind" => "PodList",
+ "items" => [ kube_pod ],
+ }
+ end
+
+ # This is a partial response, it will have many more elements in reality but
+ # these are the ones we care about at the moment
+ def kube_pod(app: "valid-pod-label")
+ { "metadata" => {
+ "name" => "kube-pod",
+ "creationTimestamp" => "2016-11-25T19:55:19Z",
+ "labels" => { "app" => app },
+ },
+ "spec" => {
+ "containers" => [
+ { "name" => "container-0" },
+ { "name" => "container-1" },
+ ],
+ },
+ "status" => { "phase" => "Running" },
+ }
+ end
+
+ def kube_terminals(service, pod)
+ pod_name = pod['metadata']['name']
+ containers = pod['spec']['containers']
+
+ containers.map do |container|
+ terminal = {
+ selectors: { pod: pod_name, container: container['name'] },
+ url: container_exec_url(service.api_url, service.namespace, pod_name, container['name']),
+ subprotocols: ['channel.k8s.io'],
+ headers: { 'Authorization' => ["Bearer #{service.token}"] },
+ created_at: DateTime.parse(pod['metadata']['creationTimestamp'])
+ }
+ terminal[:ca_pem] = service.ca_pem if service.ca_pem.present?
+ terminal
+ end
+ end
+end