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
fc4d3a57
Commit
fc4d3a57
authored
Sep 21, 2017
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make rollout_status to be part of single API endpoint
parent
051daa03
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
45 additions
and
44 deletions
+45
-44
app/controllers/projects/environments_controller.rb
app/controllers/projects/environments_controller.rb
+1
-21
app/models/project_services/mock_deployment_service.rb
app/models/project_services/mock_deployment_service.rb
+12
-6
app/serializers/environment_entity.rb
app/serializers/environment_entity.rb
+4
-5
app/serializers/rollout_status_entity.rb
app/serializers/rollout_status_entity.rb
+4
-4
config/routes/project.rb
config/routes/project.rb
+0
-1
ee/app/models/concerns/ee/kubernetes_service.rb
ee/app/models/concerns/ee/kubernetes_service.rb
+2
-1
lib/gitlab/kubernetes/rollout_status.rb
lib/gitlab/kubernetes/rollout_status.rb
+22
-6
No files found.
app/controllers/projects/environments_controller.rb
View file @
fc4d3a57
class
Projects::EnvironmentsController
<
Projects
::
ApplicationController
layout
'project'
before_action
:authorize_read_environment!
before_action
:authorize_read_deploy_board!
,
only: :status
before_action
:authorize_create_environment!
,
only:
[
:new
,
:create
]
before_action
:authorize_create_deployment!
,
only:
[
:stop
]
before_action
:authorize_update_environment!
,
only:
[
:edit
,
:update
]
before_action
:authorize_admin_environment!
,
only:
[
:terminal
,
:terminal_websocket_authorize
]
before_action
:environment
,
only:
[
:show
,
:edit
,
:update
,
:stop
,
:terminal
,
:terminal_websocket_authorize
,
:metrics
,
:status
]
before_action
:environment
,
only:
[
:show
,
:edit
,
:update
,
:stop
,
:terminal
,
:terminal_websocket_authorize
,
:metrics
]
before_action
:verify_api_request!
,
only: :terminal_websocket_authorize
def
index
...
...
@@ -132,25 +131,6 @@ class Projects::EnvironmentsController < Projects::ApplicationController
end
end
# The rollout status of an enviroment
def
status
unless
@environment
.
deployment_service_ready?
render
text:
'Not found'
,
status:
404
return
end
rollout_status
=
@environment
.
rollout_status
Gitlab
::
PollingInterval
.
set_header
(
response
,
interval:
3000
)
unless
rollout_status
.
try
(
:complete?
)
if
rollout_status
.
nil?
render
body:
nil
,
status:
204
# no result yet
else
serializer
=
RolloutStatusSerializer
.
new
(
project:
@project
,
current_user:
@current_user
)
render
json:
serializer
.
represent
(
rollout_status
)
end
end
def
additional_metrics
respond_to
do
|
format
|
format
.
json
do
...
...
app/models/project_services/mock_deployment_service.rb
View file @
fc4d3a57
...
...
@@ -17,12 +17,14 @@ class MockDeploymentService < DeploymentService
end
def
rollout_status
(
environment
)
OpenStruct
.
new
(
instances:
rollout_status_instances
,
completion:
80
,
valid?:
true
,
complete?:
true
)
case
environment
.
name
when
'staging'
Gitlab
::
Kubernetes
::
RolloutStatus
.
new
([],
status: :not_found
)
when
'test'
Gitlab
::
Kubernetes
::
RolloutStatus
.
new
([],
status: :loading
)
else
Gitlab
::
Kubernetes
::
RolloutStatus
.
new
(
rollout_status_deployments
)
end
end
private
...
...
@@ -31,4 +33,8 @@ class MockDeploymentService < DeploymentService
data
=
File
.
read
(
Rails
.
root
.
join
(
'spec'
,
'fixtures'
,
'rollout_status_instances.json'
))
JSON
.
parse
(
data
)
end
def
rollout_status_deployments
[
OpenStruct
.
new
(
instances:
rollout_status_instances
)
]
end
end
app/serializers/environment_entity.rb
View file @
fc4d3a57
...
...
@@ -9,6 +9,10 @@ class EnvironmentEntity < Grape::Entity
expose
:last_deployment
,
using:
DeploymentEntity
expose
:stop_action?
expose
:rollout_status
,
if:
->
(
environment
,
_
)
{
can?
(
request
.
current_user
,
:read_deploy_board
,
environment
.
project
)
},
using:
RolloutStatusEntity
expose
:metrics_path
,
if:
->
(
environment
,
_
)
{
environment
.
has_metrics?
}
do
|
environment
|
metrics_project_environment_path
(
environment
.
project
,
environment
)
end
...
...
@@ -26,11 +30,6 @@ class EnvironmentEntity < Grape::Entity
terminal_project_environment_path
(
environment
.
project
,
environment
)
end
expose
:rollout_status_path
,
if:
->
(
environment
,
_
)
{
environment
.
deployment_service_ready?
}
do
|
environment
|
can?
(
request
.
current_user
,
:read_deploy_board
,
environment
.
project
)
&&
status_project_environment_path
(
environment
.
project
,
environment
,
format: :json
)
end
expose
:folder_path
do
|
environment
|
folder_project_environments_path
(
environment
.
project
,
environment
.
folder_name
)
end
...
...
app/serializers/rollout_status_entity.rb
View file @
fc4d3a57
class
RolloutStatusEntity
<
Grape
::
Entity
include
RequestAwareEntity
expose
:instances
expose
:completion
expose
:valid?
,
as: :valid
expose
:status
,
as: :status
expose
:is_completed
do
|
rollout_status
|
expose
:instances
,
if:
->
(
rollout_status
,
_
)
{
rollout_status
.
found?
}
expose
:completion
,
if:
->
(
rollout_status
,
_
)
{
rollout_status
.
found?
}
expose
:is_completed
,
if:
->
(
rollout_status
,
_
)
{
rollout_status
.
found?
}
do
|
rollout_status
|
rollout_status
.
complete?
end
end
config/routes/project.rb
View file @
fc4d3a57
...
...
@@ -224,7 +224,6 @@ constraints(ProjectUrlConstrainer.new) do
get
:terminal
get
:metrics
get
:additional_metrics
get
:status
,
constraints:
{
format: :json
}
get
'/terminal.ws/authorize'
,
to:
'environments#terminal_websocket_authorize'
,
constraints:
{
format:
nil
}
end
...
...
ee/app/models/concerns/ee/kubernetes_service.rb
View file @
fc4d3a57
module
EE
module
KubernetesService
def
rollout_status
(
environment
)
with_reactive_cache
do
|
data
|
result
=
with_reactive_cache
do
|
data
|
specs
=
filter_by_label
(
data
[
:deployments
],
app:
environment
.
slug
)
::
Gitlab
::
Kubernetes
::
RolloutStatus
.
from_specs
(
*
specs
)
end
result
||
::
Gitlab
::
Kubernetes
::
RolloutStatus
.
loading_status
end
def
calculate_reactive_cache
...
...
lib/gitlab/kubernetes/rollout_status.rb
View file @
fc4d3a57
...
...
@@ -6,26 +6,42 @@ module Gitlab
# other resources, unified by an `app=` label. The rollout status sums the
# Kubernetes deployments together.
class
RolloutStatus
attr_reader
:deployments
,
:instances
,
:completion
attr_reader
:deployments
,
:instances
,
:completion
,
:status
def
complete?
completion
==
100
end
def
valid?
@valid
def
status
@status
end
def
loading?
@status
==
:loading
end
def
not_found?
@status
==
:not_found
end
def
found?
@status
==
:found
end
def
self
.
from_specs
(
*
specs
)
return
new
([],
valid:
false
)
if
specs
.
empty?
return
new
([],
status: :not_found
)
if
specs
.
empty?
deployments
=
specs
.
map
{
|
spec
|
::
Gitlab
::
Kubernetes
::
Deployment
.
new
(
spec
)
}
deployments
.
sort_by!
(
&
:order
)
new
(
deployments
)
end
def
initialize
(
deployments
,
valid:
true
)
@valid
=
valid
def
self
.
loading_rollout
new
([],
status: :loading
)
end
def
initialize
(
deployments
,
status: :found
)
@status
=
status
@deployments
=
deployments
@instances
=
deployments
.
flat_map
(
&
:instances
)
...
...
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