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
1cec47ec
Commit
1cec47ec
authored
Aug 29, 2019
by
João Cunha
Committed by
Jan Provaznik
Aug 29, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DRY check progress services
Extract duplicated code from two similar classes into a parent one.
parent
2d31e3cb
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
68 additions
and
76 deletions
+68
-76
app/services/clusters/applications/check_installation_progress_service.rb
...sters/applications/check_installation_progress_service.rb
+1
-34
app/services/clusters/applications/check_progress_service.rb
app/services/clusters/applications/check_progress_service.rb
+50
-0
app/services/clusters/applications/check_uninstall_progress_service.rb
...clusters/applications/check_uninstall_progress_service.rb
+4
-29
spec/services/clusters/applications/check_installation_progress_service_spec.rb
.../applications/check_installation_progress_service_spec.rb
+8
-8
spec/services/clusters/applications/check_uninstall_progress_service_spec.rb
...ers/applications/check_uninstall_progress_service_spec.rb
+5
-5
No files found.
app/services/clusters/applications/check_installation_progress_service.rb
View file @
1cec47ec
...
...
@@ -2,24 +2,7 @@
module
Clusters
module
Applications
class
CheckInstallationProgressService
<
BaseHelmService
def
execute
return
unless
operation_in_progress?
case
installation_phase
when
Gitlab
::
Kubernetes
::
Pod
::
SUCCEEDED
on_success
when
Gitlab
::
Kubernetes
::
Pod
::
FAILED
on_failed
else
check_timeout
end
rescue
Kubeclient
::
HttpError
=>
e
log_error
(
e
)
app
.
make_errored!
(
"Kubernetes error:
#{
e
.
error_code
}
"
)
end
class
CheckInstallationProgressService
<
CheckProgressService
private
def
operation_in_progress?
...
...
@@ -32,10 +15,6 @@ module Clusters
remove_installation_pod
end
def
on_failed
app
.
make_errored!
(
"Operation failed. Check pod logs for
#{
pod_name
}
for more details."
)
end
def
check_timeout
if
timed_out?
begin
...
...
@@ -54,18 +33,6 @@ module Clusters
def
timed_out?
Time
.
now
.
utc
-
app
.
updated_at
.
utc
>
ClusterWaitForAppInstallationWorker
::
TIMEOUT
end
def
remove_installation_pod
helm_api
.
delete_pod!
(
pod_name
)
end
def
installation_phase
helm_api
.
status
(
pod_name
)
end
def
installation_errors
helm_api
.
log
(
pod_name
)
end
end
end
end
app/services/clusters/applications/check_progress_service.rb
0 → 100644
View file @
1cec47ec
# frozen_string_literal: true
module
Clusters
module
Applications
class
CheckProgressService
<
BaseHelmService
def
execute
return
unless
operation_in_progress?
case
pod_phase
when
Gitlab
::
Kubernetes
::
Pod
::
SUCCEEDED
on_success
when
Gitlab
::
Kubernetes
::
Pod
::
FAILED
on_failed
else
check_timeout
end
rescue
Kubeclient
::
HttpError
=>
e
log_error
(
e
)
app
.
make_errored!
(
_
(
'Kubernetes error: %{error_code}'
)
%
{
error_code:
e
.
error_code
})
end
private
def
operation_in_progress?
raise
NotImplementedError
end
def
on_success
raise
NotImplementedError
end
def
pod_name
raise
NotImplementedError
end
def
on_failed
app
.
make_errored!
(
_
(
'Operation failed. Check pod logs for %{pod_name} for more details.'
)
%
{
pod_name:
pod_name
})
end
def
timed_out?
raise
NotImplementedError
end
def
pod_phase
helm_api
.
status
(
pod_name
)
end
end
end
end
app/services/clusters/applications/check_uninstall_progress_service.rb
View file @
1cec47ec
...
...
@@ -2,26 +2,13 @@
module
Clusters
module
Applications
class
CheckUninstallProgressService
<
BaseHelmService
def
execute
return
unless
app
.
uninstalling?
case
installation_phase
when
Gitlab
::
Kubernetes
::
Pod
::
SUCCEEDED
on_success
when
Gitlab
::
Kubernetes
::
Pod
::
FAILED
on_failed
else
check_timeout
end
rescue
Kubeclient
::
HttpError
=>
e
log_error
(
e
)
class
CheckUninstallProgressService
<
CheckProgressService
private
app
.
make_errored!
(
_
(
'Kubernetes error: %{error_code}'
)
%
{
error_code:
e
.
error_code
})
def
operation_in_progress?
app
.
uninstalling?
end
private
def
on_success
app
.
post_uninstall
app
.
destroy!
...
...
@@ -31,10 +18,6 @@ module Clusters
remove_installation_pod
end
def
on_failed
app
.
make_errored!
(
_
(
'Operation failed. Check pod logs for %{pod_name} for more details.'
)
%
{
pod_name:
pod_name
})
end
def
check_timeout
if
timed_out?
app
.
make_errored!
(
_
(
'Operation timed out. Check pod logs for %{pod_name} for more details.'
)
%
{
pod_name:
pod_name
})
...
...
@@ -50,14 +33,6 @@ module Clusters
def
timed_out?
Time
.
now
.
utc
-
app
.
updated_at
.
utc
>
WaitForUninstallAppWorker
::
TIMEOUT
end
def
remove_installation_pod
helm_api
.
delete_pod!
(
pod_name
)
end
def
installation_phase
helm_api
.
status
(
pod_name
)
end
end
end
end
spec/services/clusters/applications/check_installation_progress_service_spec.rb
View file @
1cec47ec
...
...
@@ -14,7 +14,7 @@ describe Clusters::Applications::CheckInstallationProgressService, '#execute' do
let
(
:phase
)
{
a_phase
}
before
do
expect
(
service
).
to
receive
(
:
installation
_phase
).
once
.
and_return
(
phase
)
expect
(
service
).
to
receive
(
:
pod
_phase
).
once
.
and_return
(
phase
)
end
context
"when phase is
#{
a_phase
}
"
do
...
...
@@ -44,7 +44,7 @@ describe Clusters::Applications::CheckInstallationProgressService, '#execute' do
before
do
application
.
update!
(
cluster:
cluster
)
expect
(
service
).
to
receive
(
:
installation
_phase
).
and_raise
(
error
)
expect
(
service
).
to
receive
(
:
pod
_phase
).
and_raise
(
error
)
end
include_examples
'logs kubernetes errors'
do
...
...
@@ -77,7 +77,7 @@ describe Clusters::Applications::CheckInstallationProgressService, '#execute' do
context
'when installation POD succeeded'
do
let
(
:phase
)
{
Gitlab
::
Kubernetes
::
Pod
::
SUCCEEDED
}
before
do
expect
(
service
).
to
receive
(
:
installation
_phase
).
once
.
and_return
(
phase
)
expect
(
service
).
to
receive
(
:
pod
_phase
).
once
.
and_return
(
phase
)
end
it
'removes the installation POD'
do
...
...
@@ -101,7 +101,7 @@ describe Clusters::Applications::CheckInstallationProgressService, '#execute' do
let
(
:errors
)
{
'test installation failed'
}
before
do
expect
(
service
).
to
receive
(
:
installation
_phase
).
once
.
and_return
(
phase
)
expect
(
service
).
to
receive
(
:
pod
_phase
).
once
.
and_return
(
phase
)
end
it
'make the application errored'
do
...
...
@@ -116,7 +116,7 @@ describe Clusters::Applications::CheckInstallationProgressService, '#execute' do
let
(
:application
)
{
create
(
:clusters_applications_helm
,
:timed_out
,
:updating
)
}
before
do
expect
(
service
).
to
receive
(
:
installation
_phase
).
once
.
and_return
(
phase
)
expect
(
service
).
to
receive
(
:
pod
_phase
).
once
.
and_return
(
phase
)
end
it
'make the application errored'
do
...
...
@@ -138,7 +138,7 @@ describe Clusters::Applications::CheckInstallationProgressService, '#execute' do
context
'when installation POD succeeded'
do
let
(
:phase
)
{
Gitlab
::
Kubernetes
::
Pod
::
SUCCEEDED
}
before
do
expect
(
service
).
to
receive
(
:
installation
_phase
).
once
.
and_return
(
phase
)
expect
(
service
).
to
receive
(
:
pod
_phase
).
once
.
and_return
(
phase
)
end
it
'removes the installation POD'
do
...
...
@@ -162,7 +162,7 @@ describe Clusters::Applications::CheckInstallationProgressService, '#execute' do
let
(
:errors
)
{
'test installation failed'
}
before
do
expect
(
service
).
to
receive
(
:
installation
_phase
).
once
.
and_return
(
phase
)
expect
(
service
).
to
receive
(
:
pod
_phase
).
once
.
and_return
(
phase
)
end
it
'make the application errored'
do
...
...
@@ -177,7 +177,7 @@ describe Clusters::Applications::CheckInstallationProgressService, '#execute' do
let
(
:application
)
{
create
(
:clusters_applications_helm
,
:timed_out
)
}
before
do
expect
(
service
).
to
receive
(
:
installation
_phase
).
once
.
and_return
(
phase
)
expect
(
service
).
to
receive
(
:
pod
_phase
).
once
.
and_return
(
phase
)
end
it
'make the application errored'
do
...
...
spec/services/clusters/applications/check_uninstall_progress_service_spec.rb
View file @
1cec47ec
...
...
@@ -20,7 +20,7 @@ describe Clusters::Applications::CheckUninstallProgressService do
let
(
:phase
)
{
a_phase
}
before
do
expect
(
service
).
to
receive
(
:
installation
_phase
).
once
.
and_return
(
phase
)
expect
(
service
).
to
receive
(
:
pod
_phase
).
once
.
and_return
(
phase
)
end
context
"when phase is
#{
a_phase
}
"
do
...
...
@@ -47,7 +47,7 @@ describe Clusters::Applications::CheckUninstallProgressService do
context
'when installation POD succeeded'
do
let
(
:phase
)
{
Gitlab
::
Kubernetes
::
Pod
::
SUCCEEDED
}
before
do
expect
(
service
).
to
receive
(
:
installation
_phase
).
once
.
and_return
(
phase
)
expect
(
service
).
to
receive
(
:
pod
_phase
).
once
.
and_return
(
phase
)
end
it
'removes the installation POD'
do
...
...
@@ -95,7 +95,7 @@ describe Clusters::Applications::CheckUninstallProgressService do
let
(
:errors
)
{
'test installation failed'
}
before
do
expect
(
service
).
to
receive
(
:
installation
_phase
).
once
.
and_return
(
phase
)
expect
(
service
).
to
receive
(
:
pod
_phase
).
once
.
and_return
(
phase
)
end
it
'make the application errored'
do
...
...
@@ -110,7 +110,7 @@ describe Clusters::Applications::CheckUninstallProgressService do
let
(
:application
)
{
create
(
:clusters_applications_prometheus
,
:timed_out
,
:uninstalling
)
}
before
do
expect
(
service
).
to
receive
(
:
installation
_phase
).
once
.
and_return
(
phase
)
expect
(
service
).
to
receive
(
:
pod
_phase
).
once
.
and_return
(
phase
)
end
it
'make the application errored'
do
...
...
@@ -131,7 +131,7 @@ describe Clusters::Applications::CheckUninstallProgressService do
before
do
application
.
update!
(
cluster:
cluster
)
expect
(
service
).
to
receive
(
:
installation
_phase
).
and_raise
(
error
)
expect
(
service
).
to
receive
(
:
pod
_phase
).
and_raise
(
error
)
end
include_examples
'logs kubernetes errors'
do
...
...
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