BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
8d8a860f
Commit
8d8a860f
authored
Nov 03, 2017
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix MigrateGcpClustersToNewClustersArchitectures. Improve spec
parent
b6d0c9b2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
169 additions
and
77 deletions
+169
-77
20171013104327_migrate_gcp_clusters_to_new_clusters_architectures.rb
...327_migrate_gcp_clusters_to_new_clusters_architectures.rb
+5
-1
migrate_gcp_clusters_to_new_clusters_architectures_spec.rb
...igrate_gcp_clusters_to_new_clusters_architectures_spec.rb
+164
-76
No files found.
db/migrate/20171013104327_migrate_gcp_clusters_to_new_clusters_architectures.rb
View file @
8d8a860f
...
...
@@ -71,7 +71,7 @@ class MigrateGcpClustersToNewClustersArchitectures < ActiveRecord::Migration
def
params_for_cluster_platforms_kubernetes
(
gcp_cluster
)
{
cluster_id:
gcp_cluster
[
'id'
],
api_url:
'https://'
+
gcp_cluster
[
'endpoint'
]
,
api_url:
api_url
(
gcp_cluster
[
'endpoint'
])
,
ca_cert:
gcp_cluster
[
'ca_cert'
],
namespace:
gcp_cluster
[
'project_namespace'
],
username:
gcp_cluster
[
'username'
],
...
...
@@ -83,4 +83,8 @@ class MigrateGcpClustersToNewClustersArchitectures < ActiveRecord::Migration
updated_at:
gcp_cluster
[
'updated_at'
]
}
end
def
api_url
(
endpoint
)
endpoint
?
'https://'
+
endpoint
:
nil
end
end
spec/migrations/migrate_gcp_clusters_to_new_clusters_architectures_spec.rb
View file @
8d8a860f
...
...
@@ -6,83 +6,171 @@ describe MigrateGcpClustersToNewClustersArchitectures, :migration do
let
(
:user
)
{
create
(
:user
)
}
let
(
:service
)
{
create
(
:kubernetes_service
,
project:
project
)
}
let
(
:project_id
)
{
project
.
id
}
let
(
:user_id
)
{
user
.
id
}
let
(
:service_id
)
{
service
.
id
}
let
(
:status
)
{
3
}
let
(
:gcp_cluster_size
)
{
1
}
let
(
:created_at
)
{
'2017-10-17 20:24:02.219679'
}
let
(
:updated_at
)
{
'2017-10-17 20:28:44.738998'
}
let
(
:enabled
)
{
1
}
# true
let
(
:status_reason
)
{
'general error'
}
let
(
:project_namespace
)
{
'sample-app'
}
let
(
:endpoint
)
{
'111.111.111.111'
}
let
(
:ca_cert
)
{
'ca_cert'
}
let
(
:encrypted_kubernetes_token
)
{
'encrypted_kubernetes_token'
}
let
(
:encrypted_kubernetes_token_iv
)
{
'encrypted_kubernetes_token_iv'
}
let
(
:username
)
{
'username'
}
let
(
:encrypted_password
)
{
'encrypted_password'
}
let
(
:encrypted_password_iv
)
{
'encrypted_password_iv'
}
let
(
:gcp_project_id
)
{
'gcp_project_id'
}
let
(
:gcp_cluster_zone
)
{
'gcp_cluster_zone'
}
let
(
:gcp_cluster_name
)
{
'gcp_cluster_name'
}
let
(
:gcp_machine_type
)
{
'gcp_machine_type'
}
let
(
:gcp_operation_id
)
{
'gcp_operation_id'
}
let
(
:encrypted_gcp_token
)
{
'encrypted_gcp_token'
}
let
(
:encrypted_gcp_token_iv
)
{
'encrypted_gcp_token_iv'
}
let
(
:cluster
)
{
Clusters
::
Cluster
.
last
}
let
(
:cluster_id
)
{
cluster
.
id
}
before
do
ActiveRecord
::
Base
.
connection
.
execute
<<-
SQL
INSERT INTO gcp_clusters (project_id, user_id, service_id, status, gcp_cluster_size, created_at, updated_at, enabled, status_reason, project_namespace, endpoint, ca_cert, encrypted_kubernetes_token, encrypted_kubernetes_token_iv, username, encrypted_password, encrypted_password_iv, gcp_project_id, gcp_cluster_zone, gcp_cluster_name, gcp_machine_type, gcp_operation_id, encrypted_gcp_token, encrypted_gcp_token_iv)
VALUES ('
#{
project_id
}
', '
#{
user_id
}
', '
#{
service_id
}
', '
#{
status
}
', '
#{
gcp_cluster_size
}
', '
#{
created_at
}
', '
#{
updated_at
}
', '
#{
enabled
}
', '
#{
status_reason
}
', '
#{
project_namespace
}
', '
#{
endpoint
}
', '
#{
ca_cert
}
', '
#{
encrypted_kubernetes_token
}
', '
#{
encrypted_kubernetes_token_iv
}
', '
#{
username
}
', '
#{
encrypted_password
}
', '
#{
encrypted_password_iv
}
', '
#{
gcp_project_id
}
', '
#{
gcp_cluster_zone
}
', '
#{
gcp_cluster_name
}
', '
#{
gcp_machine_type
}
', '
#{
gcp_operation_id
}
', '
#{
encrypted_gcp_token
}
', '
#{
encrypted_gcp_token_iv
}
');
SQL
context
'when cluster is being created'
do
let
(
:project_id
)
{
project
.
id
}
let
(
:user_id
)
{
user
.
id
}
let
(
:service_id
)
{
service
.
id
}
let
(
:status
)
{
2
}
# creating
let
(
:gcp_cluster_size
)
{
1
}
let
(
:created_at
)
{
"'2017-10-17 20:24:02'"
}
let
(
:updated_at
)
{
"'2017-10-17 20:28:44'"
}
let
(
:enabled
)
{
true
}
let
(
:status_reason
)
{
"''"
}
let
(
:project_namespace
)
{
"'sample-app'"
}
let
(
:endpoint
)
{
'NULL'
}
let
(
:ca_cert
)
{
'NULL'
}
let
(
:encrypted_kubernetes_token
)
{
'NULL'
}
let
(
:encrypted_kubernetes_token_iv
)
{
'NULL'
}
let
(
:username
)
{
'NULL'
}
let
(
:encrypted_password
)
{
'NULL'
}
let
(
:encrypted_password_iv
)
{
'NULL'
}
let
(
:gcp_project_id
)
{
"'gcp_project_id'"
}
let
(
:gcp_cluster_zone
)
{
"'gcp_cluster_zone'"
}
let
(
:gcp_cluster_name
)
{
"'gcp_cluster_name'"
}
let
(
:gcp_machine_type
)
{
"'gcp_machine_type'"
}
let
(
:gcp_operation_id
)
{
'NULL'
}
let
(
:encrypted_gcp_token
)
{
"'encrypted_gcp_token'"
}
let
(
:encrypted_gcp_token_iv
)
{
"'encrypted_gcp_token_iv'"
}
let
(
:cluster
)
{
Clusters
::
Cluster
.
last
}
let
(
:cluster_id
)
{
cluster
.
id
}
before
do
ActiveRecord
::
Base
.
connection
.
execute
<<-
SQL
INSERT INTO gcp_clusters (project_id, user_id, service_id, status, gcp_cluster_size, created_at, updated_at, enabled, status_reason, project_namespace, endpoint, ca_cert, encrypted_kubernetes_token, encrypted_kubernetes_token_iv, username, encrypted_password, encrypted_password_iv, gcp_project_id, gcp_cluster_zone, gcp_cluster_name, gcp_machine_type, gcp_operation_id, encrypted_gcp_token, encrypted_gcp_token_iv)
VALUES (
#{
project_id
}
,
#{
user_id
}
,
#{
service_id
}
,
#{
status
}
,
#{
gcp_cluster_size
}
,
#{
created_at
}
,
#{
updated_at
}
,
#{
enabled
}
,
#{
status_reason
}
,
#{
project_namespace
}
,
#{
endpoint
}
,
#{
ca_cert
}
,
#{
encrypted_kubernetes_token
}
,
#{
encrypted_kubernetes_token_iv
}
,
#{
username
}
,
#{
encrypted_password
}
,
#{
encrypted_password_iv
}
,
#{
gcp_project_id
}
,
#{
gcp_cluster_zone
}
,
#{
gcp_cluster_name
}
,
#{
gcp_machine_type
}
,
#{
gcp_operation_id
}
,
#{
encrypted_gcp_token
}
,
#{
encrypted_gcp_token_iv
}
);
SQL
end
it
'correctly migrate to new clusters architectures'
do
migrate!
expect
(
Clusters
::
Cluster
.
count
).
to
eq
(
1
)
expect
(
Clusters
::
Project
.
count
).
to
eq
(
1
)
expect
(
Clusters
::
Providers
::
Gcp
.
count
).
to
eq
(
1
)
expect
(
Clusters
::
Platforms
::
Kubernetes
.
count
).
to
eq
(
1
)
expect
(
cluster
.
user
).
to
eq
(
user
)
expect
(
cluster
.
enabled
).
to
be_truthy
expect
(
cluster
.
name
).
to
eq
(
gcp_cluster_name
.
delete!
(
"'"
))
expect
(
cluster
.
provider_type
).
to
eq
(
'gcp'
)
expect
(
cluster
.
platform_type
).
to
eq
(
'kubernetes'
)
expect
(
cluster
.
created_at
).
to
eq
(
created_at
)
expect
(
cluster
.
updated_at
).
to
eq
(
updated_at
)
expect
(
cluster
.
project
).
to
eq
(
project
)
expect
(
cluster
.
provider_gcp
.
cluster
).
to
eq
(
cluster
)
expect
(
cluster
.
provider_gcp
.
status
).
to
eq
(
status
)
expect
(
cluster
.
provider_gcp
.
status_reason
).
to
eq
(
tr
(
status_reason
))
expect
(
cluster
.
provider_gcp
.
gcp_project_id
).
to
eq
(
tr
(
gcp_project_id
))
expect
(
cluster
.
provider_gcp
.
zone
).
to
eq
(
tr
(
gcp_cluster_zone
))
expect
(
cluster
.
provider_gcp
.
num_nodes
).
to
eq
(
gcp_cluster_size
)
expect
(
cluster
.
provider_gcp
.
machine_type
).
to
eq
(
tr
(
gcp_machine_type
))
expect
(
cluster
.
provider_gcp
.
operation_id
).
to
be_nil
expect
(
cluster
.
provider_gcp
.
endpoint
).
to
be_nil
expect
(
cluster
.
provider_gcp
.
encrypted_access_token
).
to
eq
(
tr
(
encrypted_gcp_token
))
expect
(
cluster
.
provider_gcp
.
encrypted_access_token_iv
).
to
eq
(
tr
(
encrypted_gcp_token_iv
))
expect
(
cluster
.
provider_gcp
.
created_at
).
to
eq
(
created_at
)
expect
(
cluster
.
provider_gcp
.
updated_at
).
to
eq
(
updated_at
)
expect
(
cluster
.
platform_kubernetes
.
cluster
).
to
eq
(
cluster
)
expect
(
cluster
.
platform_kubernetes
.
api_url
).
to
be_nil
expect
(
cluster
.
platform_kubernetes
.
ca_cert
).
to
be_nil
expect
(
cluster
.
platform_kubernetes
.
namespace
).
to
eq
(
tr
(
project_namespace
))
expect
(
cluster
.
platform_kubernetes
.
username
).
to
be_nil
expect
(
cluster
.
platform_kubernetes
.
encrypted_password
).
to
be_nil
expect
(
cluster
.
platform_kubernetes
.
encrypted_password_iv
).
to
be_nil
expect
(
cluster
.
platform_kubernetes
.
encrypted_token
).
to
be_nil
expect
(
cluster
.
platform_kubernetes
.
encrypted_token_iv
).
to
be_nil
expect
(
cluster
.
platform_kubernetes
.
created_at
).
to
eq
(
created_at
)
expect
(
cluster
.
platform_kubernetes
.
updated_at
).
to
eq
(
updated_at
)
end
end
context
'when cluster has been created'
do
let
(
:project_id
)
{
project
.
id
}
let
(
:user_id
)
{
user
.
id
}
let
(
:service_id
)
{
service
.
id
}
let
(
:status
)
{
3
}
# created
let
(
:gcp_cluster_size
)
{
1
}
let
(
:created_at
)
{
"'2017-10-17 20:24:02'"
}
let
(
:updated_at
)
{
"'2017-10-17 20:28:44'"
}
let
(
:enabled
)
{
true
}
let
(
:status_reason
)
{
"'general error'"
}
let
(
:project_namespace
)
{
"'sample-app'"
}
let
(
:endpoint
)
{
"'111.111.111.111'"
}
let
(
:ca_cert
)
{
"'ca_cert'"
}
let
(
:encrypted_kubernetes_token
)
{
"'encrypted_kubernetes_token'"
}
let
(
:encrypted_kubernetes_token_iv
)
{
"'encrypted_kubernetes_token_iv'"
}
let
(
:username
)
{
"'username'"
}
let
(
:encrypted_password
)
{
"'encrypted_password'"
}
let
(
:encrypted_password_iv
)
{
"'encrypted_password_iv'"
}
let
(
:gcp_project_id
)
{
"'gcp_project_id'"
}
let
(
:gcp_cluster_zone
)
{
"'gcp_cluster_zone'"
}
let
(
:gcp_cluster_name
)
{
"'gcp_cluster_name'"
}
let
(
:gcp_machine_type
)
{
"'gcp_machine_type'"
}
let
(
:gcp_operation_id
)
{
"'gcp_operation_id'"
}
let
(
:encrypted_gcp_token
)
{
"'encrypted_gcp_token'"
}
let
(
:encrypted_gcp_token_iv
)
{
"'encrypted_gcp_token_iv'"
}
let
(
:cluster
)
{
Clusters
::
Cluster
.
last
}
let
(
:cluster_id
)
{
cluster
.
id
}
before
do
ActiveRecord
::
Base
.
connection
.
execute
<<-
SQL
INSERT INTO gcp_clusters (project_id, user_id, service_id, status, gcp_cluster_size, created_at, updated_at, enabled, status_reason, project_namespace, endpoint, ca_cert, encrypted_kubernetes_token, encrypted_kubernetes_token_iv, username, encrypted_password, encrypted_password_iv, gcp_project_id, gcp_cluster_zone, gcp_cluster_name, gcp_machine_type, gcp_operation_id, encrypted_gcp_token, encrypted_gcp_token_iv)
VALUES (
#{
project_id
}
,
#{
user_id
}
,
#{
service_id
}
,
#{
status
}
,
#{
gcp_cluster_size
}
,
#{
created_at
}
,
#{
updated_at
}
,
#{
enabled
}
,
#{
status_reason
}
,
#{
project_namespace
}
,
#{
endpoint
}
,
#{
ca_cert
}
,
#{
encrypted_kubernetes_token
}
,
#{
encrypted_kubernetes_token_iv
}
,
#{
username
}
,
#{
encrypted_password
}
,
#{
encrypted_password_iv
}
,
#{
gcp_project_id
}
,
#{
gcp_cluster_zone
}
,
#{
gcp_cluster_name
}
,
#{
gcp_machine_type
}
,
#{
gcp_operation_id
}
,
#{
encrypted_gcp_token
}
,
#{
encrypted_gcp_token_iv
}
);
SQL
end
it
'correctly migrate to new clusters architectures'
do
migrate!
expect
(
Clusters
::
Cluster
.
count
).
to
eq
(
1
)
expect
(
Clusters
::
Project
.
count
).
to
eq
(
1
)
expect
(
Clusters
::
Providers
::
Gcp
.
count
).
to
eq
(
1
)
expect
(
Clusters
::
Platforms
::
Kubernetes
.
count
).
to
eq
(
1
)
expect
(
cluster
.
user
).
to
eq
(
user
)
expect
(
cluster
.
enabled
).
to
be_truthy
expect
(
cluster
.
name
).
to
eq
(
tr
(
gcp_cluster_name
))
expect
(
cluster
.
provider_type
).
to
eq
(
'gcp'
)
expect
(
cluster
.
platform_type
).
to
eq
(
'kubernetes'
)
expect
(
cluster
.
created_at
).
to
eq
(
created_at
)
expect
(
cluster
.
updated_at
).
to
eq
(
updated_at
)
expect
(
cluster
.
project
).
to
eq
(
project
)
expect
(
cluster
.
provider_gcp
.
cluster
).
to
eq
(
cluster
)
expect
(
cluster
.
provider_gcp
.
status
).
to
eq
(
status
)
expect
(
cluster
.
provider_gcp
.
status_reason
).
to
eq
(
tr
(
status_reason
))
expect
(
cluster
.
provider_gcp
.
gcp_project_id
).
to
eq
(
tr
(
gcp_project_id
))
expect
(
cluster
.
provider_gcp
.
zone
).
to
eq
(
tr
(
gcp_cluster_zone
))
expect
(
cluster
.
provider_gcp
.
num_nodes
).
to
eq
(
gcp_cluster_size
)
expect
(
cluster
.
provider_gcp
.
machine_type
).
to
eq
(
tr
(
gcp_machine_type
))
expect
(
cluster
.
provider_gcp
.
operation_id
).
to
eq
(
tr
(
gcp_operation_id
))
expect
(
cluster
.
provider_gcp
.
endpoint
).
to
eq
(
tr
(
endpoint
))
expect
(
cluster
.
provider_gcp
.
encrypted_access_token
).
to
eq
(
tr
(
encrypted_gcp_token
))
expect
(
cluster
.
provider_gcp
.
encrypted_access_token_iv
).
to
eq
(
tr
(
encrypted_gcp_token_iv
))
expect
(
cluster
.
provider_gcp
.
created_at
).
to
eq
(
created_at
)
expect
(
cluster
.
provider_gcp
.
updated_at
).
to
eq
(
updated_at
)
expect
(
cluster
.
platform_kubernetes
.
cluster
).
to
eq
(
cluster
)
expect
(
cluster
.
platform_kubernetes
.
api_url
).
to
eq
(
'https://'
+
tr
(
endpoint
))
expect
(
cluster
.
platform_kubernetes
.
ca_cert
).
to
eq
(
tr
(
ca_cert
))
expect
(
cluster
.
platform_kubernetes
.
namespace
).
to
eq
(
tr
(
project_namespace
))
expect
(
cluster
.
platform_kubernetes
.
username
).
to
eq
(
tr
(
username
))
expect
(
cluster
.
platform_kubernetes
.
encrypted_password
).
to
eq
(
tr
(
encrypted_password
))
expect
(
cluster
.
platform_kubernetes
.
encrypted_password_iv
).
to
eq
(
tr
(
encrypted_password_iv
))
expect
(
cluster
.
platform_kubernetes
.
encrypted_token
).
to
eq
(
tr
(
encrypted_kubernetes_token
))
expect
(
cluster
.
platform_kubernetes
.
encrypted_token_iv
).
to
eq
(
tr
(
encrypted_kubernetes_token_iv
))
expect
(
cluster
.
platform_kubernetes
.
created_at
).
to
eq
(
created_at
)
expect
(
cluster
.
platform_kubernetes
.
updated_at
).
to
eq
(
updated_at
)
end
end
it
'correctly migrate to new clusters architectures'
do
migrate!
expect
(
Clusters
::
Cluster
.
count
).
to
eq
(
1
)
expect
(
Clusters
::
Project
.
count
).
to
eq
(
1
)
expect
(
Clusters
::
Providers
::
Gcp
.
count
).
to
eq
(
1
)
expect
(
Clusters
::
Platforms
::
Kubernetes
.
count
).
to
eq
(
1
)
expect
(
cluster
.
user
).
to
eq
(
user
)
expect
(
cluster
.
enabled
).
to
be_truthy
expect
(
cluster
.
name
).
to
eq
(
gcp_cluster_name
)
expect
(
cluster
.
provider_type
).
to
eq
(
'gcp'
)
expect
(
cluster
.
platform_type
).
to
eq
(
'kubernetes'
)
expect
(
cluster
.
created_at
).
to
eq
(
created_at
)
expect
(
cluster
.
updated_at
).
to
eq
(
updated_at
)
expect
(
cluster
.
project
).
to
eq
(
project
)
expect
(
cluster
.
provider_gcp
.
cluster
).
to
eq
(
cluster
)
expect
(
cluster
.
provider_gcp
.
status
).
to
eq
(
status
)
expect
(
cluster
.
provider_gcp
.
status_reason
).
to
eq
(
status_reason
)
expect
(
cluster
.
provider_gcp
.
gcp_project_id
).
to
eq
(
gcp_project_id
)
expect
(
cluster
.
provider_gcp
.
zone
).
to
eq
(
gcp_cluster_zone
)
expect
(
cluster
.
provider_gcp
.
num_nodes
).
to
eq
(
gcp_cluster_size
)
expect
(
cluster
.
provider_gcp
.
machine_type
).
to
eq
(
gcp_machine_type
)
expect
(
cluster
.
provider_gcp
.
operation_id
).
to
eq
(
gcp_operation_id
)
expect
(
cluster
.
provider_gcp
.
endpoint
).
to
eq
(
endpoint
)
expect
(
cluster
.
provider_gcp
.
encrypted_access_token
).
to
eq
(
encrypted_gcp_token
)
expect
(
cluster
.
provider_gcp
.
encrypted_access_token_iv
).
to
eq
(
encrypted_gcp_token_iv
)
expect
(
cluster
.
provider_gcp
.
created_at
).
to
eq
(
created_at
)
expect
(
cluster
.
provider_gcp
.
updated_at
).
to
eq
(
updated_at
)
expect
(
cluster
.
platform_kubernetes
.
cluster
).
to
eq
(
cluster
)
expect
(
cluster
.
platform_kubernetes
.
api_url
).
to
eq
(
'https://'
+
endpoint
)
expect
(
cluster
.
platform_kubernetes
.
ca_cert
).
to
eq
(
ca_cert
)
expect
(
cluster
.
platform_kubernetes
.
namespace
).
to
eq
(
project_namespace
)
expect
(
cluster
.
platform_kubernetes
.
username
).
to
eq
(
username
)
expect
(
cluster
.
platform_kubernetes
.
encrypted_password
).
to
eq
(
encrypted_password
)
expect
(
cluster
.
platform_kubernetes
.
encrypted_password_iv
).
to
eq
(
encrypted_password_iv
)
expect
(
cluster
.
platform_kubernetes
.
encrypted_token
).
to
eq
(
encrypted_kubernetes_token
)
expect
(
cluster
.
platform_kubernetes
.
encrypted_token_iv
).
to
eq
(
encrypted_kubernetes_token_iv
)
expect
(
cluster
.
platform_kubernetes
.
created_at
).
to
eq
(
created_at
)
expect
(
cluster
.
platform_kubernetes
.
updated_at
).
to
eq
(
updated_at
)
def
tr
(
s
)
s
.
delete
(
"'"
)
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