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
e4745492
Commit
e4745492
authored
Nov 29, 2017
by
Shinya Maeda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add test. Disable KubernetesService when migrated
parent
5b2ca1c6
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
201 additions
and
11 deletions
+201
-11
db/post_migrate/20171124104327_migrate_kubernetes_service_to_new_clusters_architectures.rb
...grate_kubernetes_service_to_new_clusters_architectures.rb
+12
-11
spec/migrations/migrate_kubernetes_service_to_new_clusters_architectures_spec.rb
..._kubernetes_service_to_new_clusters_architectures_spec.rb
+189
-0
No files found.
db/post_migrate/20171124104327_migrate_kubernetes_service_to_new_clusters_architectures.rb
View file @
e4745492
...
...
@@ -46,18 +46,16 @@ class MigrateKubernetesServiceToNewClustersArchitectures < ActiveRecord::Migrati
# with Platforms::Kubernetes due to delegate Kubernetes specific logic.
# We only target unmanaged KubernetesService records.
scope
:unmanaged_kubernetes_service
,
->
do
joins
(
'INNER JOIN projects ON projects.id = services.project_id'
\
'INNER JOIN cluster_projects ON projects.id = cluster_projects.project_id'
\
'INNER JOIN clusters ON cluster_projects.cluster_id = clusters.id'
\
joins
(
'INNER JOIN projects ON projects.id = services.project_id '
\
'INNER JOIN cluster_projects ON projects.id = cluster_projects.project_id '
\
'INNER JOIN clusters ON cluster_projects.cluster_id = clusters.id '
\
'INNER JOIN cluster_platforms_kubernetes ON cluster_platforms_kubernetes.cluster_id = clusters.id'
)
.
where
(
"services.category = 'deployment' AND services.type = 'KubernetesService'"
\
"AND ("
\
" cluster_projects.project_id IS NULL"
\
" OR"
\
" services.properties NOT LIKE CONCAT('%', cluster_platforms_kubernetes.api_url, '%')"
\
")"
)
.
where
(
"services.category = 'deployment' AND services.type = 'KubernetesService' "
\
"AND ( "
\
" cluster_projects.project_id IS NULL "
\
" OR "
\
" services.properties NOT LIKE CONCAT('%', cluster_platforms_kubernetes.api_url, '%') "
\
") "
)
end
end
...
...
@@ -95,6 +93,9 @@ class MigrateKubernetesServiceToNewClustersArchitectures < ActiveRecord::Migrati
encrypted_password_iv:
nil
,
# KubernetesService doesn't have
token:
kubernetes_service
.
token
# encrypted_token and encrypted_token_iv
}
)
# Disable the service, so that new cluster archetecture is going to be used
kubernetes_service
.
updated
(
active:
false
)
end
end
...
...
spec/migrations/migrate_kubernetes_service_to_new_clusters_architectures_spec.rb
0 → 100644
View file @
e4745492
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20171124104327_migrate_kubernetes_service_to_new_clusters_architectures.rb'
)
describe
MigrateKubernetesServiceToNewClustersArchitectures
,
:migration
do
context
'when user configured kubernetes from CI/CD > Clusters'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:user
)
{
create
(
:user
)
}
# Platforms::Kubernetes (New archtecture)
let!
(
:cluster
)
do
create
(
:cluster
,
projects:
[
project
],
user:
user
,
provider_type: :gcp
,
platform_type: :kubernetes
,
provider_gcp:
provider_gcp
,
platform_kubernetes:
platform_kubernetes
)
end
let
(
:provider_gcp
)
{
create
(
:cluster_provider_gcp
,
:created
)
}
let
(
:platform_kubernetes
)
{
create
(
:cluster_platform_kubernetes
,
:configured
)
}
# KubernetesService (Automatically synchronized when Platforms::Kubernetes created)
let!
(
:kubernetes_service
)
{
create
(
:kubernetes_service
,
project:
project
)
}
context
'when user is using the cluster'
do
it
'migrates'
do
expect
{
migrate!
}.
not_to
change
{
Clusters
::
Cluster
.
count
}
expect
(
cluster
).
to
be_active
expect
(
kubernetes_service
).
not_to
be_active
end
end
context
'when user disabled cluster'
do
before
do
disable_cluster!
end
context
'when user configured kubernetes from Integration > Kubernetes'
do
before
do
kubernetes_service
.
update
(
active:
true
,
api_url:
'http://new.kube.com'
,
ca_pem:
nil
,
token:
'z'
*
40
).
reload
end
context
'when user is using the kubernetes service'
do
it
'migrates'
do
expect
{
migrate!
}.
to
change
{
Clusters
::
Cluster
.
count
}.
by
(
1
)
Clusters
::
Cluster
.
last
.
tap
do
|
c
|
expect
(
c
).
to
be_active
expect
(
c
.
platform_kubernetes
.
api_url
).
to
eq
(
kubernetes_service
.
api_url
)
expect
(
c
.
platform_kubernetes
.
ca_pem
).
to
eq
(
kubernetes_service
.
ca_pem
)
expect
(
c
.
platform_kubernetes
.
token
).
to
eq
(
kubernetes_service
.
token
)
end
expect
(
kubernetes_service
).
not_to
be_active
end
end
context
'when user stopped using the kubernetes service'
do
before
do
kubernetes_service
.
update
(
active:
false
)
end
it
'migrates'
do
expect
{
migrate!
}.
to
change
{
Clusters
::
Cluster
.
count
}.
by
(
1
)
Clusters
::
Cluster
.
last
.
tap
do
|
c
|
expect
(
c
).
not_to
be_active
expect
(
c
.
platform_kubernetes
.
api_url
).
to
eq
(
kubernetes_service
.
api_url
)
expect
(
c
.
platform_kubernetes
.
ca_pem
).
to
eq
(
kubernetes_service
.
ca_pem
)
expect
(
c
.
platform_kubernetes
.
token
).
to
eq
(
kubernetes_service
.
token
)
end
expect
(
kubernetes_service
).
not_to
be_active
end
end
end
end
context
'when user deleted cluster'
do
before
do
destory_cluster!
end
context
'when user configured kubernetes from Integration > Kubernetes'
do
let!
(
:new_kubernetes_service
)
do
project
.
create_kubernetes_service
(
active:
true
,
api_url:
'http://123.123.123.123'
,
ca_pem:
nil
,
token:
'a'
*
40
)
end
context
'when user is using the kubernetes service'
do
it
'migrates'
do
expect
{
migrate!
}.
to
change
{
Clusters
::
Cluster
.
count
}.
by
(
1
)
Clusters
::
Cluster
.
last
.
tap
do
|
c
|
expect
(
c
).
to
be_active
expect
(
c
.
platform_kubernetes
.
api_url
).
to
eq
(
new_kubernetes_service
.
api_url
)
expect
(
c
.
platform_kubernetes
.
ca_pem
).
to
eq
(
new_kubernetes_service
.
ca_pem
)
expect
(
c
.
platform_kubernetes
.
token
).
to
eq
(
new_kubernetes_service
.
token
)
end
expect
(
new_kubernetes_service
).
not_to
be_active
end
end
context
'when user stopped using the kubernetes service'
do
before
do
new_kubernetes_service
.
update
(
active:
false
)
end
it
'migrates'
do
expect
{
migrate!
}.
to
change
{
Clusters
::
Cluster
.
count
}.
by
(
1
)
Clusters
::
Cluster
.
last
.
tap
do
|
c
|
expect
(
c
).
not_to
be_active
expect
(
c
.
platform_kubernetes
.
api_url
).
to
eq
(
new_kubernetes_service
.
api_url
)
expect
(
c
.
platform_kubernetes
.
ca_pem
).
to
eq
(
new_kubernetes_service
.
ca_pem
)
expect
(
c
.
platform_kubernetes
.
token
).
to
eq
(
new_kubernetes_service
.
token
)
end
expect
(
new_kubernetes_service
).
not_to
be_active
end
end
end
end
end
context
'when user configured kubernetes from Integration > Kubernetes'
do
let
(
:project
)
{
create
(
:project
)
}
let!
(
:kubernetes_service
)
{
create
(
:kubernetes_service
,
project:
project
)
}
context
'when user is using the kubernetes service'
do
it
'migrates'
do
expect
{
migrate!
}.
to
change
{
Clusters
::
Cluster
.
count
}.
by
(
1
)
Clusters
::
Cluster
.
last
.
tap
do
|
c
|
expect
(
c
).
to
be_active
expect
(
c
.
platform_kubernetes
.
api_url
).
to
eq
(
kubernetes_service
.
api_url
)
expect
(
c
.
platform_kubernetes
.
ca_pem
).
to
eq
(
kubernetes_service
.
ca_pem
)
expect
(
c
.
platform_kubernetes
.
token
).
to
eq
(
kubernetes_service
.
token
)
end
expect
(
kubernetes_service
).
not_to
be_active
end
end
context
'when user stopped using the kubernetes service'
do
before
do
kubernetes_service
.
update
(
active:
false
)
end
it
'migrates'
do
expect
{
migrate!
}.
to
change
{
Clusters
::
Cluster
.
count
}.
by
(
1
)
Clusters
::
Cluster
.
last
.
tap
do
|
c
|
expect
(
c
).
not_to
be_active
expect
(
c
.
platform_kubernetes
.
api_url
).
to
eq
(
kubernetes_service
.
api_url
)
expect
(
c
.
platform_kubernetes
.
ca_pem
).
to
eq
(
kubernetes_service
.
ca_pem
)
expect
(
c
.
platform_kubernetes
.
token
).
to
eq
(
kubernetes_service
.
token
)
end
expect
(
kubernetes_service
).
not_to
be_active
end
end
end
context
'when nothing is configured'
do
it
'migrates'
do
expect
{
migrate!
}.
not_to
change
{
Clusters
::
Cluster
.
count
}
end
end
def
disable_cluster!
cluster
.
update!
(
enabled:
false
)
kubernetes_service
.
update!
(
active:
false
)
end
def
destory_cluster!
cluster
.
destroy!
kubernetes_service
.
destroy!
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