2016-11-22 14:55:56 -05:00
|
|
|
module KubernetesHelpers
|
|
|
|
include Gitlab::Kubernetes
|
|
|
|
|
|
|
|
def kube_discovery_body
|
2017-02-22 12:44:44 -05:00
|
|
|
{
|
|
|
|
"kind" => "APIResourceList",
|
2016-11-22 14:55:56 -05:00
|
|
|
"resources" => [
|
|
|
|
{ "name" => "pods", "namespaced" => true, "kind" => "Pod" },
|
2017-02-22 12:44:44 -05:00
|
|
|
]
|
2016-11-22 14:55:56 -05:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def kube_pods_body(*pods)
|
|
|
|
{ "kind" => "PodList",
|
2017-02-22 12:44:44 -05:00
|
|
|
"items" => [kube_pod] }
|
2016-11-22 14:55:56 -05:00
|
|
|
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")
|
2017-02-22 12:44:44 -05:00
|
|
|
{
|
|
|
|
"metadata" => {
|
2016-11-22 14:55:56 -05:00
|
|
|
"name" => "kube-pod",
|
|
|
|
"creationTimestamp" => "2016-11-25T19:55:19Z",
|
|
|
|
"labels" => { "app" => app },
|
|
|
|
},
|
|
|
|
"spec" => {
|
|
|
|
"containers" => [
|
|
|
|
{ "name" => "container-0" },
|
|
|
|
{ "name" => "container-1" },
|
|
|
|
],
|
|
|
|
},
|
2017-02-22 12:44:44 -05:00
|
|
|
"status" => { "phase" => "Running" }
|
2016-11-22 14:55:56 -05:00
|
|
|
}
|
|
|
|
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}"] },
|
2017-01-26 13:16:50 -05:00
|
|
|
created_at: DateTime.parse(pod['metadata']['creationTimestamp']),
|
|
|
|
max_session_time: 0
|
2016-11-22 14:55:56 -05:00
|
|
|
}
|
|
|
|
terminal[:ca_pem] = service.ca_pem if service.ca_pem.present?
|
|
|
|
terminal
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|