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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
e395a2c1
Commit
e395a2c1
authored
Dec 21, 2017
by
Matija Čupić
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement GCP billing check in cluster form
parent
59c7f46e
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
9 deletions
+38
-9
app/controllers/projects/clusters/gcp_controller.rb
app/controllers/projects/clusters/gcp_controller.rb
+21
-7
spec/controllers/projects/clusters/gcp_controller_spec.rb
spec/controllers/projects/clusters/gcp_controller_spec.rb
+16
-1
spec/support/google_api/cloud_platform_helpers.rb
spec/support/google_api/cloud_platform_helpers.rb
+1
-1
No files found.
app/controllers/projects/clusters/gcp_controller.rb
View file @
e395a2c1
class
Projects::Clusters::GcpController
<
Projects
::
ApplicationController
class
Projects::Clusters::GcpController
<
Projects
::
ApplicationController
before_action
:authorize_read_cluster!
before_action
:authorize_read_cluster!
before_action
:authorize_google_api
,
except:
[
:login
]
before_action
:authorize_google_api
,
except:
[
:login
]
before_action
:authorize_google_project_billing
,
except:
[
:login
,
:check
,
:run_check
]
before_action
:authorize_google_project_billing
,
only:
[
:new
]
before_action
:authorize_create_cluster!
,
only:
[
:new
,
:create
]
before_action
:authorize_create_cluster!
,
only:
[
:new
,
:create
]
STATUS_POLLING_INTERVAL
=
1
.
minute
.
to_i
STATUS_POLLING_INTERVAL
=
1
.
minute
.
to_i
...
@@ -25,15 +25,20 @@ class Projects::Clusters::GcpController < Projects::ApplicationController
...
@@ -25,15 +25,20 @@ class Projects::Clusters::GcpController < Projects::ApplicationController
end
end
def
create
def
create
case
google_project_billing_status
when
'true'
@cluster
=
::
Clusters
::
CreateService
@cluster
=
::
Clusters
::
CreateService
.
new
(
project
,
current_user
,
create_params
)
.
new
(
project
,
current_user
,
create_params
)
.
execute
(
token_in_session
)
.
execute
(
token_in_session
)
if
@cluster
.
persisted?
return
redirect_to
project_cluster_path
(
project
,
@cluster
)
if
@cluster
.
persisted?
redirect_to
project_cluster_path
(
project
,
@cluster
)
when
'false'
flash
[
:error
]
=
_
(
'Please enable billing for one of your projects to be able to create a cluster.'
)
else
else
render
:new
flash
[
:error
]
=
_
(
'We could not verify that one of your projects on GCP has billing enabled. Please try again.'
)
end
end
render
:new
end
end
private
private
...
@@ -61,6 +66,15 @@ class Projects::Clusters::GcpController < Projects::ApplicationController
...
@@ -61,6 +66,15 @@ class Projects::Clusters::GcpController < Projects::ApplicationController
end
end
end
end
def
authorize_google_project_billing
CheckGcpProjectBillingWorker
.
perform_async
(
token_in_session
)
end
def
google_project_billing_status
Gitlab
::
Redis
::
SharedState
.
with
do
|
redis
|
redis
.
get
(
CheckGcpProjectBillingWorker
.
redis_shared_state_key_for
(
token_in_session
))
end
end
def
token_in_session
def
token_in_session
@token_in_session
||=
@token_in_session
||=
...
...
spec/controllers/projects/clusters/gcp_controller_spec.rb
View file @
e395a2c1
...
@@ -77,6 +77,8 @@ describe Projects::Clusters::GcpController do
...
@@ -77,6 +77,8 @@ describe Projects::Clusters::GcpController do
end
end
it
'has new object'
do
it
'has new object'
do
expect
(
controller
).
to
receive
(
:authorize_google_project_billing
)
go
go
expect
(
assigns
(
:cluster
)).
to
be_an_instance_of
(
Clusters
::
Cluster
)
expect
(
assigns
(
:cluster
)).
to
be_an_instance_of
(
Clusters
::
Cluster
)
...
@@ -137,7 +139,11 @@ describe Projects::Clusters::GcpController do
...
@@ -137,7 +139,11 @@ describe Projects::Clusters::GcpController do
stub_google_api_validate_token
stub_google_api_validate_token
end
end
context
'when creates a cluster on gke'
do
context
'when google project billing is enabled'
do
before
do
stub_google_project_billing_status
end
it
'creates a new cluster'
do
it
'creates a new cluster'
do
expect
(
ClusterProvisionWorker
).
to
receive
(
:perform_async
)
expect
(
ClusterProvisionWorker
).
to
receive
(
:perform_async
)
expect
{
go
}.
to
change
{
Clusters
::
Cluster
.
count
}
expect
{
go
}.
to
change
{
Clusters
::
Cluster
.
count
}
...
@@ -147,6 +153,15 @@ describe Projects::Clusters::GcpController do
...
@@ -147,6 +153,15 @@ describe Projects::Clusters::GcpController do
expect
(
project
.
clusters
.
first
).
to
be_kubernetes
expect
(
project
.
clusters
.
first
).
to
be_kubernetes
end
end
end
end
context
'when google project billing is not enabled'
do
it
'renders the cluster form with an error'
do
go
expect
(
response
).
to
set_flash
[
:error
]
expect
(
response
).
to
render_template
(
'new'
)
end
end
end
end
context
'when access token is expired'
do
context
'when access token is expired'
do
...
...
spec/support/google_api/cloud_platform_helpers.rb
View file @
e395a2c1
...
@@ -13,7 +13,7 @@ module GoogleApi
...
@@ -13,7 +13,7 @@ module GoogleApi
def
stub_google_project_billing_status
def
stub_google_project_billing_status
redis_double
=
double
redis_double
=
double
allow
(
Gitlab
::
Redis
::
SharedState
).
to
receive
(
:with
).
and_yield
(
redis_double
)
allow
(
Gitlab
::
Redis
::
SharedState
).
to
receive
(
:with
).
and_yield
(
redis_double
)
allow
(
redis_double
).
to
receive
(
:get
).
with
(
CheckGcpProjectBillingWorker
.
redis_shared_state_key_for
).
and_return
(
'true'
)
allow
(
redis_double
).
to
receive
(
:get
).
with
(
CheckGcpProjectBillingWorker
.
redis_shared_state_key_for
(
'token'
)
).
and_return
(
'true'
)
end
end
def
stub_cloud_platform_get_zone_cluster
(
project_id
,
zone
,
cluster_id
,
**
options
)
def
stub_cloud_platform_get_zone_cluster
(
project_id
,
zone
,
cluster_id
,
**
options
)
...
...
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