BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
911e1c2d
Commit
911e1c2d
authored
May 08, 2017
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix terminals support for Kubernetes service
It was broken, because we introduced a default namespace, which was not used by terminal methods.
parent
7c7fe22c
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
47 additions
and
15 deletions
+47
-15
kubernetes_service.rb
app/models/project_services/kubernetes_service.rb
+12
-12
fix-terminals-support-for-kubernetes-service.yml
...released/fix-terminals-support-for-kubernetes-service.yml
+4
-0
services.rb
spec/factories/services.rb
+0
-1
kubernetes_service_spec.rb
spec/models/project_services/kubernetes_service_spec.rb
+30
-1
kubernetes_helpers.rb
spec/support/kubernetes_helpers.rb
+1
-1
No files found.
app/models/project_services/kubernetes_service.rb
View file @
911e1c2d
...
...
@@ -77,6 +77,14 @@ class KubernetesService < DeploymentService
]
end
def
actual_namespace
if
namespace
.
present?
namespace
else
default_namespace
end
end
# Check we can connect to the Kubernetes API
def
test
(
*
args
)
kubeclient
=
build_kubeclient!
...
...
@@ -91,7 +99,7 @@ class KubernetesService < DeploymentService
variables
=
[
{
key:
'KUBE_URL'
,
value:
api_url
,
public:
true
},
{
key:
'KUBE_TOKEN'
,
value:
token
,
public:
false
},
{
key:
'KUBE_NAMESPACE'
,
value:
namespace_variabl
e
,
public:
true
}
{
key:
'KUBE_NAMESPACE'
,
value:
actual_namespac
e
,
public:
true
}
]
if
ca_pem
.
present?
...
...
@@ -110,7 +118,7 @@ class KubernetesService < DeploymentService
with_reactive_cache
do
|
data
|
pods
=
data
.
fetch
(
:pods
,
nil
)
filter_pods
(
pods
,
app:
environment
.
slug
).
flat_map
{
|
pod
|
terminals_for_pod
(
api_url
,
namespace
,
pod
)
}.
flat_map
{
|
pod
|
terminals_for_pod
(
api_url
,
actual_
namespace
,
pod
)
}.
each
{
|
terminal
|
add_terminal_auth
(
terminal
,
terminal_auth
)
}
end
end
...
...
@@ -124,7 +132,7 @@ class KubernetesService < DeploymentService
# Store as hashes, rather than as third-party types
pods
=
begin
kubeclient
.
get_pods
(
namespace:
namespace
).
as_json
kubeclient
.
get_pods
(
namespace:
actual_
namespace
).
as_json
rescue
KubeException
=>
err
raise
err
unless
err
.
error_code
==
404
[]
...
...
@@ -142,20 +150,12 @@ class KubernetesService < DeploymentService
default_namespace
||
TEMPLATE_PLACEHOLDER
end
def
namespace_variable
if
namespace
.
present?
namespace
else
default_namespace
end
end
def
default_namespace
"
#{
project
.
path
}
-
#{
project
.
id
}
"
if
project
.
present?
end
def
build_kubeclient!
(
api_path:
'api'
,
api_version:
'v1'
)
raise
"Incomplete settings"
unless
api_url
&&
namespace
&&
token
raise
"Incomplete settings"
unless
api_url
&&
actual_
namespace
&&
token
::
Kubeclient
::
Client
.
new
(
join_api_url
(
api_path
),
...
...
changelogs/unreleased/fix-terminals-support-for-kubernetes-service.yml
0 → 100644
View file @
911e1c2d
---
title
:
Fix terminals support for Kubernetes Service
merge_request
:
author
:
spec/factories/services.rb
View file @
911e1c2d
...
...
@@ -20,7 +20,6 @@ FactoryGirl.define do
project
factory: :empty_project
active
true
properties
({
namespace:
'somepath'
,
api_url:
'https://kubernetes.example.com'
,
token:
'a'
*
40
})
...
...
spec/models/project_services/kubernetes_service_spec.rb
View file @
911e1c2d
...
...
@@ -13,7 +13,7 @@ describe KubernetesService, models: true, caching: true do
let
(
:discovery_url
)
{
service
.
api_url
+
'/api/v1'
}
let
(
:discovery_response
)
{
{
body:
kube_discovery_body
.
to_json
}
}
let
(
:pods_url
)
{
service
.
api_url
+
"/api/v1/namespaces/
#{
service
.
namespace
}
/pods"
}
let
(
:pods_url
)
{
service
.
api_url
+
"/api/v1/namespaces/
#{
service
.
actual_
namespace
}
/pods"
}
let
(
:pods_response
)
{
{
body:
kube_pods_body
(
kube_pod
).
to_json
}
}
def
stub_kubeclient_discover
...
...
@@ -105,6 +105,34 @@ describe KubernetesService, models: true, caching: true do
end
end
describe
'#actual_namespace'
do
subject
{
service
.
actual_namespace
}
it
"returns the default namespace"
do
is_expected
.
to
eq
(
service
.
send
(
:default_namespace
))
end
context
'when namespace is specified'
do
before
do
service
.
namespace
=
'my-namespace'
end
it
"returns the user-namespace"
do
is_expected
.
to
eq
(
'my-namespace'
)
end
end
context
'when service is not assigned to project'
do
before
do
service
.
project
=
nil
end
it
"does not return namespace"
do
is_expected
.
to
be_nil
end
end
end
describe
'#test'
do
before
do
stub_kubeclient_discover
...
...
@@ -194,6 +222,7 @@ describe KubernetesService, models: true, caching: true do
describe
'#terminals'
do
let
(
:environment
)
{
build
(
:environment
,
project:
project
,
name:
"env"
,
slug:
"env-000000"
)
}
subject
{
service
.
terminals
(
environment
)
}
context
'with invalid pods'
do
...
...
spec/support/kubernetes_helpers.rb
View file @
911e1c2d
...
...
@@ -41,7 +41,7 @@ module KubernetesHelpers
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'
]),
url:
container_exec_url
(
service
.
api_url
,
service
.
actual_
namespace
,
pod_name
,
container
[
'name'
]),
subprotocols:
[
'channel.k8s.io'
],
headers:
{
'Authorization'
=>
[
"Bearer
#{
service
.
token
}
"
]
},
created_at:
DateTime
.
parse
(
pod
[
'metadata'
][
'creationTimestamp'
]),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment