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
Léo-Paul Géneau
gitlab-ce
Commits
6b07aa5e
Commit
6b07aa5e
authored
Oct 05, 2017
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
integrate_cluster_service_spec. provision_cluster_service_spec. update_cluster_service_spec.
parent
88cc9d52
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
137 additions
and
15 deletions
+137
-15
app/models/gcp/cluster.rb
app/models/gcp/cluster.rb
+1
-1
app/services/ci/integrate_cluster_service.rb
app/services/ci/integrate_cluster_service.rb
+1
-1
spec/factories/gcp/cluster.rb
spec/factories/gcp/cluster.rb
+10
-1
spec/services/ci/integrate_cluster_service_spec.rb
spec/services/ci/integrate_cluster_service_spec.rb
+27
-2
spec/services/ci/provision_cluster_service_spec.rb
spec/services/ci/provision_cluster_service_spec.rb
+73
-5
spec/services/ci/update_cluster_service_spec.rb
spec/services/ci/update_cluster_service_spec.rb
+25
-5
No files found.
app/models/gcp/cluster.rb
View file @
6b07aa5e
...
...
@@ -97,7 +97,7 @@ module Gcp
end
def
api_url
'https://'
+
endpoint
'https://'
+
endpoint
if
endpoint
end
def
restrict_modification
...
...
app/services/ci/integrate_cluster_service.rb
View file @
6b07aa5e
...
...
@@ -20,7 +20,7 @@ module Ci
token:
token
)
end
rescue
ActiveRecord
::
RecordInvalid
=>
e
cluster
.
error
!
(
"Failed to integrate cluster into kubernetes_service:
#{
e
.
message
}
"
)
cluster
.
make_errored
!
(
"Failed to integrate cluster into kubernetes_service:
#{
e
.
message
}
"
)
end
end
end
spec/factories/gcp/cluster.rb
View file @
6b07aa5e
...
...
@@ -7,9 +7,18 @@ FactoryGirl.define do
gcp_cluster_name
'test-cluster'
gcp_cluster_zone
'us-central1-a'
gcp_cluster_size
1
gcp_machine_type
'n1-standard-4'
trait
:with_kubernetes_service
do
service
:kubernetes_service
after
(
:create
)
do
|
cluster
,
evaluator
|
create
(
:kubernetes_service
,
project:
cluster
.
project
).
tap
do
|
service
|
cluster
.
update
(
service:
service
)
end
end
end
trait
:custom_project_namespace
do
project_namespace
'sample-app'
end
trait
:created_on_gke
do
...
...
spec/services/ci/integrate_cluster_service_spec.rb
View file @
6b07aa5e
...
...
@@ -2,15 +2,40 @@ require 'spec_helper'
describe
Ci
::
IntegrateClusterService
do
describe
'#execute'
do
let
(
:cluster
)
{
create
(
:gcp_cluster
,
:custom_project_namespace
)
}
let
(
:endpoint
)
{
'123.123.123.123'
}
let
(
:ca_cert
)
{
'ca_cert_xxx'
}
let
(
:token
)
{
'token_xxx'
}
let
(
:username
)
{
'username_xxx'
}
let
(
:password
)
{
'password_xxx'
}
before
do
described_class
.
new
.
execute
(
cluster
,
endpoint
,
ca_cert
,
token
,
username
,
password
)
cluster
.
reload
end
context
'when correct params'
do
it
'creates a cluster object'
do
expect
(
cluster
.
endpoint
).
to
eq
(
endpoint
)
expect
(
cluster
.
ca_cert
).
to
eq
(
ca_cert
)
expect
(
cluster
.
kubernetes_token
).
to
eq
(
token
)
expect
(
cluster
.
username
).
to
eq
(
username
)
expect
(
cluster
.
password
).
to
eq
(
password
)
expect
(
cluster
.
service
.
active
).
to
be_truthy
expect
(
cluster
.
service
.
api_url
).
to
eq
(
cluster
.
api_url
)
expect
(
cluster
.
service
.
ca_pem
).
to
eq
(
ca_cert
)
expect
(
cluster
.
service
.
namespace
).
to
eq
(
cluster
.
project_namespace
)
expect
(
cluster
.
service
.
token
).
to
eq
(
token
)
end
end
context
'when invalid params'
do
it
'returns a cluster object with error'
do
let
(
:endpoint
)
{
nil
}
it
'sets an error to cluster object'
do
expect
(
cluster
).
to
be_errored
end
end
end
...
...
spec/services/ci/provision_cluster_service_spec.rb
View file @
6b07aa5e
...
...
@@ -2,16 +2,84 @@ require 'spec_helper'
describe
Ci
::
ProvisionClusterService
do
describe
'#execute'
do
context
'when correct params'
do
it
'creates a cluster on gke'
do
let
(
:cluster
)
{
create
(
:gcp_cluster
)
}
let
(
:operation
)
{
spy
}
shared_examples
'error'
do
it
'sets an error to cluster object'
do
described_class
.
new
.
execute
(
cluster
)
expect
(
cluster
.
reload
).
to
be_errored
end
end
context
'when suceeded to request provision'
do
before
do
allow_any_instance_of
(
GoogleApi
::
CloudPlatform
::
Client
)
.
to
receive
(
:projects_zones_clusters_create
).
and_return
(
operation
)
end
context
'when operation status is RUNNING'
do
before
do
allow
(
operation
).
to
receive
(
:status
).
and_return
(
'RUNNING'
)
end
context
'when suceeded to parse gcp operation id'
do
before
do
allow_any_instance_of
(
GoogleApi
::
CloudPlatform
::
Client
)
.
to
receive
(
:parse_operation_id
).
and_return
(
'operation-123'
)
end
context
'when invalid params'
do
it
'returns a cluster object with error'
do
context
'when cluster status is scheduled'
do
before
do
allow_any_instance_of
(
GoogleApi
::
CloudPlatform
::
Client
)
.
to
receive
(
:parse_operation_id
).
and_return
(
'operation-123'
)
end
it
'schedules a worker for status minitoring'
do
expect
(
WaitForClusterCreationWorker
).
to
receive
(
:perform_in
)
described_class
.
new
.
execute
(
cluster
)
end
end
context
'when cluster status is creating'
do
before
do
cluster
.
make_creating!
end
it_behaves_like
'error'
end
end
context
'when failed to parse gcp operation id'
do
before
do
allow_any_instance_of
(
GoogleApi
::
CloudPlatform
::
Client
)
.
to
receive
(
:parse_operation_id
).
and_return
(
nil
)
end
it_behaves_like
'error'
end
end
context
'when operation status is others'
do
before
do
allow
(
operation
).
to
receive
(
:status
).
and_return
(
'others'
)
end
it_behaves_like
'error'
end
end
context
'when failed to request provision'
do
let
(
:error
)
{
Google
::
Apis
::
ServerError
.
new
(
'a'
)
}
before
do
allow_any_instance_of
(
GoogleApi
::
CloudPlatform
::
Client
)
.
to
receive
(
:projects_zones_clusters_create
).
and_raise
(
error
)
end
it_behaves_like
'error'
end
end
end
spec/services/ci/update_cluster_service_spec.rb
View file @
6b07aa5e
...
...
@@ -2,15 +2,35 @@ require 'spec_helper'
describe
Ci
::
UpdateClusterService
do
describe
'#execute'
do
let
(
:cluster
)
{
create
(
:gcp_cluster
,
:created_on_gke
,
:with_kubernetes_service
)
}
before
do
described_class
.
new
(
cluster
.
project
,
cluster
.
user
,
params
).
execute
(
cluster
)
cluster
.
reload
end
context
'when correct params'
do
it
'updates the cluster and the service'
do
context
'when enabled is true'
do
let
(
:params
)
{
{
'enabled'
=>
'true'
}
}
it
'enables cluster and overwrite kubernetes service'
do
expect
(
cluster
.
enabled
).
to
be_truthy
expect
(
cluster
.
service
.
active
).
to
be_truthy
expect
(
cluster
.
service
.
api_url
).
to
eq
(
cluster
.
api_url
)
expect
(
cluster
.
service
.
ca_pem
).
to
eq
(
cluster
.
ca_cert
)
expect
(
cluster
.
service
.
namespace
).
to
eq
(
cluster
.
project_namespace
)
expect
(
cluster
.
service
.
token
).
to
eq
(
cluster
.
kubernetes_token
)
end
end
context
'when invalid params
'
do
it
'returns a cluster object with error'
do
context
'when enabled is false
'
do
let
(
:params
)
{
{
'enabled'
=>
'false'
}
}
it
'disables cluster and kubernetes service'
do
expect
(
cluster
.
enabled
).
to
be_falsy
expect
(
cluster
.
service
.
active
).
to
be_falsy
end
end
end
end
...
...
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