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
69b91d38
Commit
69b91d38
authored
Nov 19, 2019
by
Rémy Coutable
Committed by
Lin Jen-Shin
Nov 21, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure we set 'tiller-namespace' for 'helm' commands
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
d008a870
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
117 additions
and
90 deletions
+117
-90
lib/quality/helm_client.rb
lib/quality/helm_client.rb
+5
-4
scripts/review_apps/automated_cleanup.rb
scripts/review_apps/automated_cleanup.rb
+3
-2
scripts/review_apps/review-apps.sh
scripts/review_apps/review-apps.sh
+96
-72
spec/lib/quality/helm_client_spec.rb
spec/lib/quality/helm_client_spec.rb
+13
-12
No files found.
lib/quality/helm_client.rb
View file @
69b91d38
...
@@ -7,7 +7,7 @@ module Quality
...
@@ -7,7 +7,7 @@ module Quality
class
HelmClient
class
HelmClient
CommandFailedError
=
Class
.
new
(
StandardError
)
CommandFailedError
=
Class
.
new
(
StandardError
)
attr_reader
:namespace
attr_reader
:
tiller_namespace
,
:
namespace
RELEASE_JSON_ATTRIBUTES
=
%w[Name Revision Updated Status Chart AppVersion Namespace]
.
freeze
RELEASE_JSON_ATTRIBUTES
=
%w[Name Revision Updated Status Chart AppVersion Namespace]
.
freeze
...
@@ -24,7 +24,8 @@ module Quality
...
@@ -24,7 +24,8 @@ module Quality
# A single page of data and the corresponding page number.
# A single page of data and the corresponding page number.
Page
=
Struct
.
new
(
:releases
,
:number
)
Page
=
Struct
.
new
(
:releases
,
:number
)
def
initialize
(
namespace
:)
def
initialize
(
tiller_namespace
:,
namespace
:)
@tiller_namespace
=
tiller_namespace
@namespace
=
namespace
@namespace
=
namespace
end
end
...
@@ -35,7 +36,7 @@ module Quality
...
@@ -35,7 +36,7 @@ module Quality
def
delete
(
release_name
:)
def
delete
(
release_name
:)
run_command
([
run_command
([
'delete'
,
'delete'
,
%(--tiller-namespace "#{namespace}")
,
%(--tiller-namespace "#{
tiller_
namespace}")
,
'--purge'
,
'--purge'
,
release_name
release_name
])
])
...
@@ -60,7 +61,7 @@ module Quality
...
@@ -60,7 +61,7 @@ module Quality
command
=
[
command
=
[
'list'
,
'list'
,
%(--namespace "#{namespace}")
,
%(--namespace "#{namespace}")
,
%(--tiller-namespace "#{namespace}" --output json)
,
%(--tiller-namespace "#{
tiller_
namespace}" --output json)
,
*
args
*
args
]
]
json
=
JSON
.
parse
(
run_command
(
command
))
json
=
JSON
.
parse
(
run_command
(
command
))
...
...
scripts/review_apps/automated_cleanup.rb
View file @
69b91d38
...
@@ -25,7 +25,6 @@ class AutomatedCleanup
...
@@ -25,7 +25,6 @@ class AutomatedCleanup
def
initialize
(
project_path:
ENV
[
'CI_PROJECT_PATH'
],
gitlab_token:
ENV
[
'GITLAB_BOT_REVIEW_APPS_CLEANUP_TOKEN'
])
def
initialize
(
project_path:
ENV
[
'CI_PROJECT_PATH'
],
gitlab_token:
ENV
[
'GITLAB_BOT_REVIEW_APPS_CLEANUP_TOKEN'
])
@project_path
=
project_path
@project_path
=
project_path
@gitlab_token
=
gitlab_token
@gitlab_token
=
gitlab_token
ENV
[
'TILLER_NAMESPACE'
]
||=
review_apps_namespace
end
end
def
gitlab
def
gitlab
...
@@ -45,7 +44,9 @@ class AutomatedCleanup
...
@@ -45,7 +44,9 @@ class AutomatedCleanup
end
end
def
helm
def
helm
@helm
||=
Quality
::
HelmClient
.
new
(
namespace:
review_apps_namespace
)
@helm
||=
Quality
::
HelmClient
.
new
(
tiller_namespace:
review_apps_namespace
,
namespace:
review_apps_namespace
)
end
end
def
kubernetes
def
kubernetes
...
...
scripts/review_apps/review-apps.sh
View file @
69b91d38
This diff is collapsed.
Click to expand it.
spec/lib/quality/helm_client_spec.rb
View file @
69b91d38
...
@@ -3,7 +3,8 @@
...
@@ -3,7 +3,8 @@
require
'fast_spec_helper'
require
'fast_spec_helper'
RSpec
.
describe
Quality
::
HelmClient
do
RSpec
.
describe
Quality
::
HelmClient
do
let
(
:namespace
)
{
'review-apps-ee'
}
let
(
:tiller_namespace
)
{
'review-apps-ee'
}
let
(
:namespace
)
{
tiller_namespace
}
let
(
:release_name
)
{
'my-release'
}
let
(
:release_name
)
{
'my-release'
}
let
(
:raw_helm_list_page1
)
do
let
(
:raw_helm_list_page1
)
do
<<~
OUTPUT
<<~
OUTPUT
...
@@ -30,12 +31,12 @@ RSpec.describe Quality::HelmClient do
...
@@ -30,12 +31,12 @@ RSpec.describe Quality::HelmClient do
OUTPUT
OUTPUT
end
end
subject
{
described_class
.
new
(
namespace:
namespace
)
}
subject
{
described_class
.
new
(
tiller_namespace:
tiller_namespace
,
namespace:
namespace
)
}
describe
'#releases'
do
describe
'#releases'
do
it
'raises an error if the Helm command fails'
do
it
'raises an error if the Helm command fails'
do
expect
(
Gitlab
::
Popen
).
to
receive
(
:popen_with_detail
)
expect
(
Gitlab
::
Popen
).
to
receive
(
:popen_with_detail
)
.
with
([
%(helm list --namespace "#{namespace}" --tiller-namespace "#{namespace}" --output json)
])
.
with
([
%(helm list --namespace "#{namespace}" --tiller-namespace "#{
tiller_
namespace}" --output json)
])
.
and_return
(
Gitlab
::
Popen
::
Result
.
new
([],
''
,
''
,
double
(
success?:
false
)))
.
and_return
(
Gitlab
::
Popen
::
Result
.
new
([],
''
,
''
,
double
(
success?:
false
)))
expect
{
subject
.
releases
.
to_a
}.
to
raise_error
(
described_class
::
CommandFailedError
)
expect
{
subject
.
releases
.
to_a
}.
to
raise_error
(
described_class
::
CommandFailedError
)
...
@@ -43,7 +44,7 @@ RSpec.describe Quality::HelmClient do
...
@@ -43,7 +44,7 @@ RSpec.describe Quality::HelmClient do
it
'calls helm list with default arguments'
do
it
'calls helm list with default arguments'
do
expect
(
Gitlab
::
Popen
).
to
receive
(
:popen_with_detail
)
expect
(
Gitlab
::
Popen
).
to
receive
(
:popen_with_detail
)
.
with
([
%(helm list --namespace "#{namespace}" --tiller-namespace "#{namespace}" --output json)
])
.
with
([
%(helm list --namespace "#{namespace}" --tiller-namespace "#{
tiller_
namespace}" --output json)
])
.
and_return
(
Gitlab
::
Popen
::
Result
.
new
([],
''
,
''
,
double
(
success?:
true
)))
.
and_return
(
Gitlab
::
Popen
::
Result
.
new
([],
''
,
''
,
double
(
success?:
true
)))
subject
.
releases
.
to_a
subject
.
releases
.
to_a
...
@@ -51,7 +52,7 @@ RSpec.describe Quality::HelmClient do
...
@@ -51,7 +52,7 @@ RSpec.describe Quality::HelmClient do
it
'calls helm list with extra arguments'
do
it
'calls helm list with extra arguments'
do
expect
(
Gitlab
::
Popen
).
to
receive
(
:popen_with_detail
)
expect
(
Gitlab
::
Popen
).
to
receive
(
:popen_with_detail
)
.
with
([
%(helm list --namespace "#{namespace}" --tiller-namespace "#{namespace}" --output json --deployed)
])
.
with
([
%(helm list --namespace "#{namespace}" --tiller-namespace "#{
tiller_
namespace}" --output json --deployed)
])
.
and_return
(
Gitlab
::
Popen
::
Result
.
new
([],
''
,
''
,
double
(
success?:
true
)))
.
and_return
(
Gitlab
::
Popen
::
Result
.
new
([],
''
,
''
,
double
(
success?:
true
)))
subject
.
releases
(
args:
[
'--deployed'
]).
to_a
subject
.
releases
(
args:
[
'--deployed'
]).
to_a
...
@@ -59,7 +60,7 @@ RSpec.describe Quality::HelmClient do
...
@@ -59,7 +60,7 @@ RSpec.describe Quality::HelmClient do
it
'returns a list of Release objects'
do
it
'returns a list of Release objects'
do
expect
(
Gitlab
::
Popen
).
to
receive
(
:popen_with_detail
)
expect
(
Gitlab
::
Popen
).
to
receive
(
:popen_with_detail
)
.
with
([
%(helm list --namespace "#{namespace}" --tiller-namespace "#{namespace}" --output json --deployed)
])
.
with
([
%(helm list --namespace "#{namespace}" --tiller-namespace "#{
tiller_
namespace}" --output json --deployed)
])
.
and_return
(
Gitlab
::
Popen
::
Result
.
new
([],
raw_helm_list_page2
,
''
,
double
(
success?:
true
)))
.
and_return
(
Gitlab
::
Popen
::
Result
.
new
([],
raw_helm_list_page2
,
''
,
double
(
success?:
true
)))
releases
=
subject
.
releases
(
args:
[
'--deployed'
]).
to_a
releases
=
subject
.
releases
(
args:
[
'--deployed'
]).
to_a
...
@@ -78,10 +79,10 @@ RSpec.describe Quality::HelmClient do
...
@@ -78,10 +79,10 @@ RSpec.describe Quality::HelmClient do
it
'automatically paginates releases'
do
it
'automatically paginates releases'
do
expect
(
Gitlab
::
Popen
).
to
receive
(
:popen_with_detail
).
ordered
expect
(
Gitlab
::
Popen
).
to
receive
(
:popen_with_detail
).
ordered
.
with
([
%(helm list --namespace "#{namespace}" --tiller-namespace "#{namespace}" --output json)
])
.
with
([
%(helm list --namespace "#{namespace}" --tiller-namespace "#{
tiller_
namespace}" --output json)
])
.
and_return
(
Gitlab
::
Popen
::
Result
.
new
([],
raw_helm_list_page1
,
''
,
double
(
success?:
true
)))
.
and_return
(
Gitlab
::
Popen
::
Result
.
new
([],
raw_helm_list_page1
,
''
,
double
(
success?:
true
)))
expect
(
Gitlab
::
Popen
).
to
receive
(
:popen_with_detail
).
ordered
expect
(
Gitlab
::
Popen
).
to
receive
(
:popen_with_detail
).
ordered
.
with
([
%(helm list --namespace "#{namespace}" --tiller-namespace "#{namespace}" --output json --offset review-6709-group-t40qbv)
])
.
with
([
%(helm list --namespace "#{namespace}" --tiller-namespace "#{
tiller_
namespace}" --output json --offset review-6709-group-t40qbv)
])
.
and_return
(
Gitlab
::
Popen
::
Result
.
new
([],
raw_helm_list_page2
,
''
,
double
(
success?:
true
)))
.
and_return
(
Gitlab
::
Popen
::
Result
.
new
([],
raw_helm_list_page2
,
''
,
double
(
success?:
true
)))
releases
=
subject
.
releases
.
to_a
releases
=
subject
.
releases
.
to_a
...
@@ -94,7 +95,7 @@ RSpec.describe Quality::HelmClient do
...
@@ -94,7 +95,7 @@ RSpec.describe Quality::HelmClient do
describe
'#delete'
do
describe
'#delete'
do
it
'raises an error if the Helm command fails'
do
it
'raises an error if the Helm command fails'
do
expect
(
Gitlab
::
Popen
).
to
receive
(
:popen_with_detail
)
expect
(
Gitlab
::
Popen
).
to
receive
(
:popen_with_detail
)
.
with
([
%(helm delete --tiller-namespace "#{namespace}" --purge #{release_name})
])
.
with
([
%(helm delete --tiller-namespace "#{
tiller_
namespace}" --purge #{release_name})
])
.
and_return
(
Gitlab
::
Popen
::
Result
.
new
([],
''
,
''
,
double
(
success?:
false
)))
.
and_return
(
Gitlab
::
Popen
::
Result
.
new
([],
''
,
''
,
double
(
success?:
false
)))
expect
{
subject
.
delete
(
release_name:
release_name
)
}.
to
raise_error
(
described_class
::
CommandFailedError
)
expect
{
subject
.
delete
(
release_name:
release_name
)
}.
to
raise_error
(
described_class
::
CommandFailedError
)
...
@@ -102,7 +103,7 @@ RSpec.describe Quality::HelmClient do
...
@@ -102,7 +103,7 @@ RSpec.describe Quality::HelmClient do
it
'calls helm delete with default arguments'
do
it
'calls helm delete with default arguments'
do
expect
(
Gitlab
::
Popen
).
to
receive
(
:popen_with_detail
)
expect
(
Gitlab
::
Popen
).
to
receive
(
:popen_with_detail
)
.
with
([
%(helm delete --tiller-namespace "#{namespace}" --purge #{release_name})
])
.
with
([
%(helm delete --tiller-namespace "#{
tiller_
namespace}" --purge #{release_name})
])
.
and_return
(
Gitlab
::
Popen
::
Result
.
new
([],
''
,
''
,
double
(
success?:
true
)))
.
and_return
(
Gitlab
::
Popen
::
Result
.
new
([],
''
,
''
,
double
(
success?:
true
)))
expect
(
subject
.
delete
(
release_name:
release_name
)).
to
eq
(
''
)
expect
(
subject
.
delete
(
release_name:
release_name
)).
to
eq
(
''
)
...
@@ -113,7 +114,7 @@ RSpec.describe Quality::HelmClient do
...
@@ -113,7 +114,7 @@ RSpec.describe Quality::HelmClient do
it
'raises an error if the Helm command fails'
do
it
'raises an error if the Helm command fails'
do
expect
(
Gitlab
::
Popen
).
to
receive
(
:popen_with_detail
)
expect
(
Gitlab
::
Popen
).
to
receive
(
:popen_with_detail
)
.
with
([
%(helm delete --tiller-namespace "#{namespace}" --purge #{release_name.join(' ')})
])
.
with
([
%(helm delete --tiller-namespace "#{
tiller_
namespace}" --purge #{release_name.join(' ')})
])
.
and_return
(
Gitlab
::
Popen
::
Result
.
new
([],
''
,
''
,
double
(
success?:
false
)))
.
and_return
(
Gitlab
::
Popen
::
Result
.
new
([],
''
,
''
,
double
(
success?:
false
)))
expect
{
subject
.
delete
(
release_name:
release_name
)
}.
to
raise_error
(
described_class
::
CommandFailedError
)
expect
{
subject
.
delete
(
release_name:
release_name
)
}.
to
raise_error
(
described_class
::
CommandFailedError
)
...
@@ -121,7 +122,7 @@ RSpec.describe Quality::HelmClient do
...
@@ -121,7 +122,7 @@ RSpec.describe Quality::HelmClient do
it
'calls helm delete with multiple release names'
do
it
'calls helm delete with multiple release names'
do
expect
(
Gitlab
::
Popen
).
to
receive
(
:popen_with_detail
)
expect
(
Gitlab
::
Popen
).
to
receive
(
:popen_with_detail
)
.
with
([
%(helm delete --tiller-namespace "#{namespace}" --purge #{release_name.join(' ')})
])
.
with
([
%(helm delete --tiller-namespace "#{
tiller_
namespace}" --purge #{release_name.join(' ')})
])
.
and_return
(
Gitlab
::
Popen
::
Result
.
new
([],
''
,
''
,
double
(
success?:
true
)))
.
and_return
(
Gitlab
::
Popen
::
Result
.
new
([],
''
,
''
,
double
(
success?:
true
)))
expect
(
subject
.
delete
(
release_name:
release_name
)).
to
eq
(
''
)
expect
(
subject
.
delete
(
release_name:
release_name
)).
to
eq
(
''
)
...
...
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