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
11d24176
Commit
11d24176
authored
Jun 21, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
6f864d8b
4562ea32
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
113 additions
and
0 deletions
+113
-0
changelogs/unreleased/63079-migrate-clusters-with-no-token-to-unmanaged.yml
...sed/63079-migrate-clusters-with-no-token-to-unmanaged.yml
+6
-0
db/post_migrate/20190613231640_migrate_managed_clusters_with_no_token_to_unmanaged.rb
...40_migrate_managed_clusters_with_no_token_to_unmanaged.rb
+48
-0
spec/migrations/migrate_managed_clusters_with_no_token_to_unmanaged_spec.rb
...grate_managed_clusters_with_no_token_to_unmanaged_spec.rb
+59
-0
No files found.
changelogs/unreleased/63079-migrate-clusters-with-no-token-to-unmanaged.yml
0 → 100644
View file @
11d24176
---
title
:
Migrate GitLab managed project-level clusters to unmanaged if they are missing
a Kubernetes service account token
merge_request
:
29648
author
:
type
:
other
db/post_migrate/20190613231640_migrate_managed_clusters_with_no_token_to_unmanaged.rb
0 → 100644
View file @
11d24176
# frozen_string_literal: true
# See http://doc.gitlab.com/ce/development/migration_style_guide.html
# for more information on how to write migrations for GitLab.
class
MigrateManagedClustersWithNoTokenToUnmanaged
<
ActiveRecord
::
Migration
[
5.1
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
class
Cluster
<
ActiveRecord
::
Base
include
EachBatch
self
.
table_name
=
'clusters'
has_many
:kubernetes_namespaces
,
class_name:
'MigrateManagedClustersWithNoTokenToUnmanaged::KubernetesNamespace'
scope
:managed
,
->
{
where
(
managed:
true
)
}
enum
cluster_type:
{
instance_type:
1
,
group_type:
2
,
project_type:
3
}
end
class
KubernetesNamespace
<
ActiveRecord
::
Base
self
.
table_name
=
'clusters_kubernetes_namespaces'
belongs_to
:cluster
,
class_name:
'MigrateManagedClustersWithNoTokenToUnmanaged::Cluster'
end
def
up
Cluster
.
managed
.
project_type
.
joins
(
:kubernetes_namespaces
)
.
where
(
clusters_kubernetes_namespaces:
{
encrypted_service_account_token:
nil
})
.
where
(
'clusters.created_at < ?'
,
Date
.
new
(
2018
,
12
,
1
).
midnight
)
.
each_batch
do
|
batch
|
batch
.
update_all
(
managed:
false
)
end
end
def
down
end
end
spec/migrations/migrate_managed_clusters_with_no_token_to_unmanaged_spec.rb
0 → 100644
View file @
11d24176
# frozen_string_literal: true
require
'spec_helper'
require
Rails
.
root
.
join
(
'db'
,
'post_migrate'
,
'20190613231640_migrate_managed_clusters_with_no_token_to_unmanaged.rb'
)
describe
MigrateManagedClustersWithNoTokenToUnmanaged
,
:migration
do
let
(
:cluster_type
)
{
'project_type'
}
let
(
:created_at
)
{
Date
.
new
(
2018
,
11
,
1
).
midnight
}
let!
(
:cluster
)
do
table
(
:clusters
).
create!
(
name:
'cluster'
,
cluster_type:
described_class
::
Cluster
.
cluster_types
[
cluster_type
],
managed:
true
,
created_at:
created_at
)
end
let!
(
:kubernetes_namespace
)
do
table
(
:clusters_kubernetes_namespaces
).
create!
(
cluster_id:
cluster
.
id
,
namespace:
'namespace'
)
end
it
'marks the cluster as unmanaged'
do
migrate!
expect
(
cluster
.
reload
).
not_to
be_managed
end
context
'cluster is not project type'
do
let
(
:cluster_type
)
{
'group_type'
}
it
'does not update the cluster'
do
migrate!
expect
(
cluster
.
reload
).
to
be_managed
end
end
context
'kubernetes namespace has a service account token'
do
before
do
kubernetes_namespace
.
update!
(
encrypted_service_account_token:
"TOKEN"
)
end
it
'does not update the cluster'
do
migrate!
expect
(
cluster
.
reload
).
to
be_managed
end
end
context
'cluster was created after the cutoff'
do
let
(
:created_at
)
{
Date
.
new
(
2019
,
1
,
1
).
midnight
}
it
'does not update the cluster'
do
migrate!
expect
(
cluster
.
reload
).
to
be_managed
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