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
faa5b22e
Commit
faa5b22e
authored
Jan 11, 2019
by
Mayra Cabrera
Committed by
Kamil Trzciński
Jan 11, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
EE Port: Improves restriction of multiple Kubernetes clusters via API
parent
b64f59d1
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
48 additions
and
7 deletions
+48
-7
changelogs/unreleased/56110-cluster-kubernetes-api-500-error-on-post-request.yml
...6110-cluster-kubernetes-api-500-error-on-post-request.yml
+5
-0
ee/spec/requests/api/project_clusters_spec.rb
ee/spec/requests/api/project_clusters_spec.rb
+23
-4
lib/api/helpers.rb
lib/api/helpers.rb
+2
-2
lib/api/project_clusters.rb
lib/api/project_clusters.rb
+1
-1
spec/requests/api/project_clusters_spec.rb
spec/requests/api/project_clusters_spec.rb
+17
-0
No files found.
changelogs/unreleased/56110-cluster-kubernetes-api-500-error-on-post-request.yml
0 → 100644
View file @
faa5b22e
---
title
:
Improves restriction of multiple Kubernetes clusters through API
merge_request
:
24251
author
:
type
:
fixed
ee/spec/requests/api/project_clusters_spec.rb
View file @
faa5b22e
...
@@ -56,12 +56,10 @@ describe API::ProjectClusters do
...
@@ -56,12 +56,10 @@ describe API::ProjectClusters do
}
}
end
end
before
do
post
api
(
"/projects/
#{
project
.
id
}
/clusters/user"
,
current_user
),
params:
cluster_params
end
context
'when user sets specific environment scope'
do
context
'when user sets specific environment scope'
do
it
'should create a cluster with that specific environment'
do
it
'should create a cluster with that specific environment'
do
post
api
(
"/projects/
#{
project
.
id
}
/clusters/user"
,
current_user
),
params:
cluster_params
expect
(
json_response
[
'environment_scope'
]).
to
eq
(
'production/*'
)
expect
(
json_response
[
'environment_scope'
]).
to
eq
(
'production/*'
)
end
end
end
end
...
@@ -75,9 +73,30 @@ describe API::ProjectClusters do
...
@@ -75,9 +73,30 @@ describe API::ProjectClusters do
end
end
it
'should set default environment'
do
it
'should set default environment'
do
post
api
(
"/projects/
#{
project
.
id
}
/clusters/user"
,
current_user
),
params:
cluster_params
expect
(
json_response
[
'environment_scope'
]).
to
eq
(
'*'
)
expect
(
json_response
[
'environment_scope'
]).
to
eq
(
'*'
)
end
end
end
end
context
'when license has multiple clusters feature'
do
before
do
stub_licensed_features
(
multiple_clusters:
true
)
create
(
:cluster
,
:provided_by_gcp
,
:project
,
projects:
[
project
])
post
api
(
"/projects/
#{
project
.
id
}
/clusters/user"
,
current_user
),
params:
cluster_params
end
it
'should respond with 201'
do
expect
(
response
).
to
have_gitlab_http_status
(
201
)
end
it
'should allow to associate multiple cluster to project'
do
expect
(
project
.
reload
.
clusters
.
count
).
to
eq
(
2
)
end
end
end
end
describe
'PUT /projects/:id/clusters/:cluster_id'
do
describe
'PUT /projects/:id/clusters/:cluster_id'
do
...
...
lib/api/helpers.rb
View file @
faa5b22e
...
@@ -248,8 +248,8 @@ module API
...
@@ -248,8 +248,8 @@ module API
forbidden!
unless
current_user
.
admin?
forbidden!
unless
current_user
.
admin?
end
end
def
authorize!
(
action
,
subject
=
:global
)
def
authorize!
(
action
,
subject
=
:global
,
reason
=
nil
)
forbidden!
unless
can?
(
current_user
,
action
,
subject
)
forbidden!
(
reason
)
unless
can?
(
current_user
,
action
,
subject
)
end
end
def
authorize_push_project
def
authorize_push_project
...
...
lib/api/project_clusters.rb
View file @
faa5b22e
...
@@ -65,7 +65,7 @@ module API
...
@@ -65,7 +65,7 @@ module API
use
:create_params_ee
use
:create_params_ee
end
end
post
':id/clusters/user'
do
post
':id/clusters/user'
do
authorize!
:
create_cluster
,
user_project
authorize!
:
add_cluster
,
user_project
,
'Instance does not support multiple Kubernetes clusters'
user_cluster
=
::
Clusters
::
CreateService
user_cluster
=
::
Clusters
::
CreateService
.
new
(
current_user
,
create_cluster_user_params
)
.
new
(
current_user
,
create_cluster_user_params
)
...
...
spec/requests/api/project_clusters_spec.rb
View file @
faa5b22e
...
@@ -266,6 +266,23 @@ describe API::ProjectClusters do
...
@@ -266,6 +266,23 @@ describe API::ProjectClusters do
end
end
end
end
end
end
context
'when user tries to add multiple clusters'
do
before
do
create
(
:cluster
,
:provided_by_gcp
,
:project
,
projects:
[
project
])
post
api
(
"/projects/
#{
project
.
id
}
/clusters/user"
,
current_user
),
params:
cluster_params
end
it
'should respond with 403'
do
expect
(
response
).
to
have_gitlab_http_status
(
403
)
end
it
'should return an appropriate message'
do
expect
(
json_response
[
'message'
]).
to
include
(
'Instance does not support multiple Kubernetes clusters'
)
end
end
end
end
describe
'PUT /projects/:id/clusters/:cluster_id'
do
describe
'PUT /projects/:id/clusters/:cluster_id'
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