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
78f85f3f
Commit
78f85f3f
authored
Dec 16, 2017
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add check step for creating GCP clusters
parent
1de0261d
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
97 additions
and
3 deletions
+97
-3
app/controllers/projects/clusters/gcp_controller.rb
app/controllers/projects/clusters/gcp_controller.rb
+24
-1
app/views/projects/clusters/gcp/check.html.haml
app/views/projects/clusters/gcp/check.html.haml
+1
-0
app/views/projects/clusters/new.html.haml
app/views/projects/clusters/new.html.haml
+1
-1
config/routes/project.rb
config/routes/project.rb
+1
-0
spec/controllers/projects/clusters/gcp_controller_spec.rb
spec/controllers/projects/clusters/gcp_controller_spec.rb
+70
-1
No files found.
app/controllers/projects/clusters/gcp_controller.rb
View file @
78f85f3f
class
Projects::Clusters::GcpController
<
Projects
::
ApplicationController
before_action
:authorize_read_cluster!
before_action
:authorize_google_api
,
except:
[
:login
]
before_action
:authorize_google_project_billing
,
only:
[
:check
]
before_action
:authorize_create_cluster!
,
only:
[
:new
,
:create
]
STATUS_POLLING_INTERVAL
=
10_000
def
login
begin
state
=
generate_session_key_redirect
(
gcp_
new
_namespace_project_clusters_path
.
to_s
)
state
=
generate_session_key_redirect
(
gcp_
check
_namespace_project_clusters_path
.
to_s
)
@authorize_url
=
GoogleApi
::
CloudPlatform
::
Client
.
new
(
nil
,
callback_google_api_auth_url
,
...
...
@@ -15,6 +18,18 @@ class Projects::Clusters::GcpController < Projects::ApplicationController
end
end
def
check
respond_to
do
|
format
|
format
.
json
do
Gitlab
::
PollingInterval
.
set_header
(
response
,
interval:
STATUS_POLLING_INTERVAL
)
Gitlab
::
Redis
::
SharedState
.
with
do
|
redis
|
render
json:
{
billing:
redis
.
get
(
CheckGcpProjectBillingWorker
.
redis_shared_state_key_for
(
token_in_session
))
}
end
end
end
end
def
new
@cluster
=
::
Clusters
::
Cluster
.
new
.
tap
do
|
cluster
|
cluster
.
build_provider_gcp
...
...
@@ -57,6 +72,14 @@ class Projects::Clusters::GcpController < Projects::ApplicationController
end
end
def
authorize_google_project_billing
Gitlab
::
Redis
::
SharedState
.
with
do
|
redis
|
unless
redis
.
get
(
CheckGcpProjectBillingWorker
.
redis_shared_state_key_for
(
token_in_session
))
==
'true'
CheckGcpProjectBillingWorker
.
perform_async
(
token_in_session
)
end
end
end
def
token_in_session
@token_in_session
||=
session
[
GoogleApi
::
CloudPlatform
::
Client
.
session_key_for_token
]
...
...
app/views/projects/clusters/gcp/check.html.haml
0 → 100644
View file @
78f85f3f
Hello
app/views/projects/clusters/new.html.haml
View file @
78f85f3f
...
...
@@ -8,6 +8,6 @@
%h4
.prepend-top-0
=
s_
(
'ClusterIntegration|Choose how to set up cluster integration'
)
%p
=
s_
(
'ClusterIntegration|Create a new cluster on Google Kubernetes Engine right from GitLab'
)
=
link_to
s_
(
'ClusterIntegration|Create on GKE'
),
gcp_
new
_namespace_project_clusters_path
(
@project
.
namespace
,
@project
),
class:
'btn append-bottom-20'
=
link_to
s_
(
'ClusterIntegration|Create on GKE'
),
gcp_
check
_namespace_project_clusters_path
(
@project
.
namespace
,
@project
),
class:
'btn append-bottom-20'
%p
=
s_
(
'ClusterIntegration|Enter the details for an existing Kubernetes cluster'
)
=
link_to
s_
(
'ClusterIntegration|Add an existing cluster'
),
user_new_namespace_project_clusters_path
(
@project
.
namespace
,
@project
),
class:
'btn append-bottom-20'
config/routes/project.rb
View file @
78f85f3f
...
...
@@ -189,6 +189,7 @@ constraints(ProjectUrlConstrainer.new) do
get
'/user/new'
,
to:
'clusters/user#new'
post
'/user'
,
to:
'clusters/user#create'
get
'/gcp/check'
,
to:
'clusters/gcp#check'
get
'/gcp/new'
,
to:
'clusters/gcp#new'
get
'/gcp/login'
,
to:
'clusters/gcp#login'
post
'/gcp'
,
to:
'clusters/gcp#create'
...
...
spec/controllers/projects/clusters/gcp_controller_spec.rb
View file @
78f85f3f
...
...
@@ -30,7 +30,7 @@ describe Projects::Clusters::GcpController do
go
expect
(
assigns
(
:authorize_url
)).
to
include
(
key
)
expect
(
session
[
session_key_for_redirect_uri
]).
to
eq
(
gcp_
new
_project_clusters_path
(
project
))
expect
(
session
[
session_key_for_redirect_uri
]).
to
eq
(
gcp_
check
_project_clusters_path
(
project
))
end
end
...
...
@@ -63,6 +63,75 @@ describe Projects::Clusters::GcpController do
end
end
describe
'GET check'
do
let
(
:user
)
{
create
(
:user
)
}
before
do
project
.
add_master
(
user
)
sign_in
(
user
)
end
describe
'functionality'
do
context
'when redis has wanted billing status'
do
let
(
:token
)
{
'bogustoken'
}
before
do
redis_double
=
double
allow
(
Gitlab
::
Redis
::
SharedState
).
to
receive
(
:with
).
and_yield
(
redis_double
)
allow
(
redis_double
).
to
receive
(
:get
).
and_return
(
'true'
)
end
it
'should render json with billing status'
do
go
expect
(
response
).
to
have_http_status
(
:ok
)
expect
(
response
.
body
).
to
include_json
(
billing:
'true'
)
end
it
'should not start worker'
do
expect
(
CheckGcpProjectBillingWorker
).
not_to
receive
(
:perform_async
)
go
end
end
context
'when redis does not have billing status'
do
before
do
redis_double
=
double
allow
(
Gitlab
::
Redis
::
SharedState
).
to
receive
(
:with
).
and_yield
(
redis_double
)
allow
(
redis_double
).
to
receive
(
:get
).
and_return
(
nil
)
end
it
'should render json with null billing status'
do
go
expect
(
response
).
to
have_http_status
(
:ok
)
expect
(
response
.
body
).
to
include_json
(
billing:
nil
)
end
it
'should start worker'
do
expect
(
CheckGcpProjectBillingWorker
).
to
receive
(
:perform_async
)
go
end
end
end
describe
'security'
do
it
{
expect
{
go
}.
to
be_allowed_for
(
:admin
)
}
it
{
expect
{
go
}.
to
be_allowed_for
(
:owner
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_allowed_for
(
:master
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:developer
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:reporter
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:guest
).
of
(
project
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:user
)
}
it
{
expect
{
go
}.
to
be_denied_for
(
:external
)
}
end
def
go
get
:check
,
namespace_id:
project
.
namespace
,
project_id:
project
,
format: :json
end
end
describe
'GET new'
do
describe
'functionality'
do
let
(
:user
)
{
create
(
:user
)
}
...
...
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