Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
b78ce713
Commit
b78ce713
authored
Jun 19, 2017
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move some EE-only KubernetesService code to a prepended module
parent
8ef83018
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
58 additions
and
37 deletions
+58
-37
app/models/concerns/ee/kubernetes_service.rb
app/models/concerns/ee/kubernetes_service.rb
+27
-0
app/models/project_services/kubernetes_service.rb
app/models/project_services/kubernetes_service.rb
+3
-18
spec/models/project_services/kubernetes_service_ee_spec.rb
spec/models/project_services/kubernetes_service_ee_spec.rb
+28
-0
spec/models/project_services/kubernetes_service_spec.rb
spec/models/project_services/kubernetes_service_spec.rb
+0
-19
No files found.
app/models/concerns/ee/kubernetes_service.rb
0 → 100644
View file @
b78ce713
module
EE
module
KubernetesService
def
rollout_status
(
environment
)
with_reactive_cache
do
|
data
|
specs
=
filter_by_label
(
data
[
:deployments
],
app:
environment
.
slug
)
::
Gitlab
::
Kubernetes
::
RolloutStatus
.
from_specs
(
*
specs
)
end
end
def
calculate_reactive_cache
result
=
super
result
[
:deployments
]
=
read_deployments
if
result
result
end
def
read_deployments
kubeclient
=
build_kubeclient!
(
api_path:
'apis/extensions'
,
api_version:
'v1beta1'
)
kubeclient
.
get_deployments
(
namespace:
actual_namespace
).
as_json
rescue
KubeException
=>
err
raise
err
unless
err
.
error_code
==
404
[]
end
end
end
app/models/project_services/kubernetes_service.rb
View file @
b78ce713
...
...
@@ -3,6 +3,8 @@ class KubernetesService < DeploymentService
include
Gitlab
::
Kubernetes
include
ReactiveCaching
prepend
EE
::
KubernetesService
self
.
reactive_cache_key
=
->
(
service
)
{
[
service
.
class
.
model_name
.
singular
,
service
.
project_id
]
}
# Namespace defaults to the project path, but can be overridden in case that
...
...
@@ -122,21 +124,13 @@ class KubernetesService < DeploymentService
end
end
def
rollout_status
(
environment
)
with_reactive_cache
do
|
data
|
specs
=
filter_by_label
(
data
[
:deployments
],
app:
environment
.
slug
)
::
Gitlab
::
Kubernetes
::
RolloutStatus
.
from_specs
(
*
specs
)
end
end
# Caches resources in the namespace so other calls don't need to block on
# network access
def
calculate_reactive_cache
return
unless
active?
&&
project
&&
!
project
.
pending_delete?
# We may want to cache extra things in the future
{
pods:
read_pods
,
deployments:
read_deployments
}
{
pods:
read_pods
}
end
TEMPLATE_PLACEHOLDER
=
'Kubernetes namespace'
.
freeze
...
...
@@ -173,15 +167,6 @@ class KubernetesService < DeploymentService
[]
end
def
read_deployments
kubeclient
=
build_kubeclient!
(
api_path:
'apis/extensions'
,
api_version:
'v1beta1'
)
kubeclient
.
get_deployments
(
namespace:
actual_namespace
).
as_json
rescue
KubeException
=>
err
raise
err
unless
err
.
error_code
==
404
[]
end
def
kubeclient_ssl_options
opts
=
{
verify_ssl:
OpenSSL
::
SSL
::
VERIFY_PEER
}
...
...
spec/models/project_services/kubernetes_service_ee_spec.rb
0 → 100644
View file @
b78ce713
require
'spec_helper'
describe
KubernetesService
,
models:
true
,
caching:
true
do
include
KubernetesHelpers
include
ReactiveCachingHelpers
let
(
:project
)
{
build_stubbed
(
:kubernetes_project
)
}
let
(
:service
)
{
project
.
kubernetes_service
}
describe
'#rollout_status'
do
let
(
:environment
)
{
build
(
:environment
,
project:
project
,
name:
"env"
,
slug:
"env-000000"
)
}
subject
(
:rollout_status
)
{
service
.
rollout_status
(
environment
)
}
context
'with valid deployments'
do
before
do
stub_reactive_cache
(
service
,
deployments:
[
kube_deployment
(
app:
environment
.
slug
),
kube_deployment
]
)
end
it
'creates a matching RolloutStatus'
do
expect
(
rollout_status
).
to
be_kind_of
(
::
Gitlab
::
Kubernetes
::
RolloutStatus
)
expect
(
rollout_status
.
deployments
.
map
(
&
:labels
)).
to
eq
([{
'app'
=>
'env-000000'
}])
end
end
end
end
spec/models/project_services/kubernetes_service_spec.rb
View file @
b78ce713
...
...
@@ -280,25 +280,6 @@ describe KubernetesService, models: true, caching: true do
end
end
describe
'#rollout_status'
do
let
(
:environment
)
{
build
(
:environment
,
project:
project
,
name:
"env"
,
slug:
"env-000000"
)
}
subject
(
:rollout_status
)
{
service
.
rollout_status
(
environment
)
}
context
'with valid deployments'
do
before
do
stub_reactive_cache
(
service
,
deployments:
[
kube_deployment
(
app:
environment
.
slug
),
kube_deployment
]
)
end
it
'creates a matching RolloutStatus'
do
expect
(
rollout_status
).
to
be_kind_of
(
::
Gitlab
::
Kubernetes
::
RolloutStatus
)
expect
(
rollout_status
.
deployments
.
map
(
&
:labels
)).
to
eq
([{
'app'
=>
'env-000000'
}])
end
end
end
describe
'#calculate_reactive_cache'
do
subject
{
service
.
calculate_reactive_cache
}
...
...
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