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
5786d4f2
Commit
5786d4f2
authored
Jul 29, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
55cb82cf
1d422655
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
2 additions
and
246 deletions
+2
-246
app/services/clusters/refresh_service.rb
app/services/clusters/refresh_service.rb
+0
-40
app/workers/cluster_configure_worker.rb
app/workers/cluster_configure_worker.rb
+1
-5
app/workers/cluster_project_configure_worker.rb
app/workers/cluster_project_configure_worker.rb
+1
-3
spec/services/clusters/refresh_service_spec.rb
spec/services/clusters/refresh_service_spec.rb
+0
-113
spec/workers/cluster_configure_worker_spec.rb
spec/workers/cluster_configure_worker_spec.rb
+0
-71
spec/workers/cluster_project_configure_worker_spec.rb
spec/workers/cluster_project_configure_worker_spec.rb
+0
-14
No files found.
app/services/clusters/refresh_service.rb
deleted
100644 → 0
View file @
55cb82cf
# frozen_string_literal: true
module
Clusters
class
RefreshService
def
self
.
create_or_update_namespaces_for_cluster
(
cluster
)
projects_with_missing_kubernetes_namespaces_for_cluster
(
cluster
).
each
do
|
project
|
create_or_update_namespace
(
cluster
,
project
)
end
end
def
self
.
create_or_update_namespaces_for_project
(
project
)
clusters_with_missing_kubernetes_namespaces_for_project
(
project
).
each
do
|
cluster
|
create_or_update_namespace
(
cluster
,
project
)
end
end
def
self
.
projects_with_missing_kubernetes_namespaces_for_cluster
(
cluster
)
cluster
.
all_projects
.
missing_kubernetes_namespace
(
cluster
.
kubernetes_namespaces
)
end
private_class_method
:projects_with_missing_kubernetes_namespaces_for_cluster
def
self
.
clusters_with_missing_kubernetes_namespaces_for_project
(
project
)
project
.
clusters
.
managed
.
missing_kubernetes_namespace
(
project
.
kubernetes_namespaces
)
end
private_class_method
:clusters_with_missing_kubernetes_namespaces_for_project
def
self
.
create_or_update_namespace
(
cluster
,
project
)
kubernetes_namespace
=
cluster
.
find_or_initialize_kubernetes_namespace_for_project
(
project
)
::
Clusters
::
Gcp
::
Kubernetes
::
CreateOrUpdateNamespaceService
.
new
(
cluster:
cluster
,
kubernetes_namespace:
kubernetes_namespace
).
execute
end
private_class_method
:create_or_update_namespace
end
end
app/workers/cluster_configure_worker.rb
View file @
5786d4f2
...
...
@@ -5,10 +5,6 @@ class ClusterConfigureWorker
include
ClusterQueue
def
perform
(
cluster_id
)
Clusters
::
Cluster
.
managed
.
find_by_id
(
cluster_id
).
try
do
|
cluster
|
if
cluster
.
project_type?
Clusters
::
RefreshService
.
create_or_update_namespaces_for_cluster
(
cluster
)
end
end
# Scheduled for removal in https://gitlab.com/gitlab-org/gitlab-ce/issues/59319
end
end
app/workers/cluster_project_configure_worker.rb
View file @
5786d4f2
...
...
@@ -5,8 +5,6 @@ class ClusterProjectConfigureWorker
include
ClusterQueue
def
perform
(
project_id
)
project
=
Project
.
find
(
project_id
)
::
Clusters
::
RefreshService
.
create_or_update_namespaces_for_project
(
project
)
# Scheduled for removal in https://gitlab.com/gitlab-org/gitlab-ce/issues/59319
end
end
spec/services/clusters/refresh_service_spec.rb
deleted
100644 → 0
View file @
55cb82cf
# frozen_string_literal: true
require
'spec_helper'
describe
Clusters
::
RefreshService
do
shared_examples
'creates a kubernetes namespace'
do
let
(
:token
)
{
'aaaaaa'
}
let
(
:service_account_creator
)
{
double
(
Clusters
::
Gcp
::
Kubernetes
::
CreateOrUpdateServiceAccountService
,
execute:
true
)
}
let
(
:secrets_fetcher
)
{
double
(
Clusters
::
Gcp
::
Kubernetes
::
FetchKubernetesTokenService
,
execute:
token
)
}
it
'creates a kubernetes namespace'
do
expect
(
Clusters
::
Gcp
::
Kubernetes
::
CreateOrUpdateServiceAccountService
).
to
receive
(
:namespace_creator
).
and_return
(
service_account_creator
)
expect
(
Clusters
::
Gcp
::
Kubernetes
::
FetchKubernetesTokenService
).
to
receive
(
:new
).
and_return
(
secrets_fetcher
)
expect
{
subject
}.
to
change
(
project
.
kubernetes_namespaces
,
:count
)
kubernetes_namespace
=
cluster
.
kubernetes_namespaces
.
first
expect
(
kubernetes_namespace
).
to
be_present
expect
(
kubernetes_namespace
.
project
).
to
eq
(
project
)
end
end
shared_examples
'does not create a kubernetes namespace'
do
it
'does not create a new kubernetes namespace'
do
expect
(
Clusters
::
Gcp
::
Kubernetes
::
CreateOrUpdateServiceAccountService
).
not_to
receive
(
:namespace_creator
)
expect
(
Clusters
::
Gcp
::
Kubernetes
::
FetchKubernetesTokenService
).
not_to
receive
(
:new
)
expect
{
subject
}.
not_to
change
(
Clusters
::
KubernetesNamespace
,
:count
)
end
end
describe
'.create_or_update_namespaces_for_cluster'
do
let
(
:cluster
)
{
create
(
:cluster
,
:provided_by_user
,
:project
)
}
let
(
:project
)
{
cluster
.
project
}
subject
{
described_class
.
create_or_update_namespaces_for_cluster
(
cluster
)
}
context
'cluster is project level'
do
include_examples
'creates a kubernetes namespace'
context
'when project already has kubernetes namespace'
do
before
do
create
(
:cluster_kubernetes_namespace
,
project:
project
,
cluster:
cluster
)
end
include_examples
'does not create a kubernetes namespace'
end
end
context
'cluster is group level'
do
let
(
:cluster
)
{
create
(
:cluster
,
:provided_by_user
,
:group
)
}
let
(
:group
)
{
cluster
.
group
}
let
(
:project
)
{
create
(
:project
,
group:
group
)
}
include_examples
'creates a kubernetes namespace'
context
'when project already has kubernetes namespace'
do
before
do
create
(
:cluster_kubernetes_namespace
,
project:
project
,
cluster:
cluster
)
end
include_examples
'does not create a kubernetes namespace'
end
end
end
describe
'.create_or_update_namespaces_for_project'
do
let
(
:project
)
{
create
(
:project
)
}
subject
{
described_class
.
create_or_update_namespaces_for_project
(
project
)
}
it
'creates no kubernetes namespaces'
do
expect
{
subject
}.
not_to
change
(
project
.
kubernetes_namespaces
,
:count
)
end
context
'project has a project cluster'
do
let!
(
:cluster
)
{
create
(
:cluster
,
:provided_by_gcp
,
cluster_type: :project_type
,
projects:
[
project
])
}
include_examples
'creates a kubernetes namespace'
context
'when project already has kubernetes namespace'
do
before
do
create
(
:cluster_kubernetes_namespace
,
project:
project
,
cluster:
cluster
)
end
include_examples
'does not create a kubernetes namespace'
end
end
context
'project belongs to a group cluster'
do
let!
(
:cluster
)
{
create
(
:cluster
,
:provided_by_gcp
,
:group
)
}
let
(
:group
)
{
cluster
.
group
}
let
(
:project
)
{
create
(
:project
,
group:
group
)
}
include_examples
'does not create a kubernetes namespace'
context
'when project already has kubernetes namespace'
do
before
do
create
(
:cluster_kubernetes_namespace
,
project:
project
,
cluster:
cluster
)
end
include_examples
'does not create a kubernetes namespace'
end
end
context
'cluster is not managed'
do
let!
(
:cluster
)
{
create
(
:cluster
,
:project
,
:not_managed
,
projects:
[
project
])
}
include_examples
'does not create a kubernetes namespace'
end
end
end
spec/workers/cluster_configure_worker_spec.rb
deleted
100644 → 0
View file @
55cb82cf
# frozen_string_literal: true
require
'spec_helper'
describe
ClusterConfigureWorker
,
'#perform'
do
let
(
:worker
)
{
described_class
.
new
}
shared_examples
'configured cluster'
do
it
'creates a namespace'
do
expect
(
Clusters
::
RefreshService
).
to
receive
(
:create_or_update_namespaces_for_cluster
).
with
(
cluster
).
once
worker
.
perform
(
cluster
.
id
)
end
end
shared_examples
'unconfigured cluster'
do
it
'does not create a namespace'
do
expect
(
Clusters
::
RefreshService
).
not_to
receive
(
:create_or_update_namespaces_for_cluster
)
worker
.
perform
(
cluster
.
id
)
end
end
context
'group cluster'
do
let
(
:cluster
)
{
create
(
:cluster
,
:group
,
:provided_by_gcp
)
}
let
(
:group
)
{
cluster
.
group
}
context
'when group has a project'
do
let!
(
:project
)
{
create
(
:project
,
group:
group
)
}
it_behaves_like
'unconfigured cluster'
end
context
'when group has project in a sub-group'
do
let!
(
:subgroup
)
{
create
(
:group
,
parent:
group
)
}
let!
(
:project
)
{
create
(
:project
,
group:
subgroup
)
}
it_behaves_like
'unconfigured cluster'
end
end
context
'when provider type is gcp'
do
let!
(
:cluster
)
{
create
(
:cluster
,
:project
,
:provided_by_gcp
)
}
it_behaves_like
'configured cluster'
end
context
'when provider type is user'
do
let!
(
:cluster
)
{
create
(
:cluster
,
:project
,
:provided_by_user
)
}
it_behaves_like
'configured cluster'
end
context
'when cluster is not managed'
do
let
(
:cluster
)
{
create
(
:cluster
,
:not_managed
)
}
it
'does not configure the cluster'
do
expect
(
Clusters
::
RefreshService
).
not_to
receive
(
:create_or_update_namespaces_for_cluster
)
described_class
.
new
.
perform
(
cluster
.
id
)
end
end
context
'when cluster does not exist'
do
it
'does not provision a cluster'
do
expect_any_instance_of
(
Clusters
::
Gcp
::
Kubernetes
::
CreateOrUpdateNamespaceService
).
not_to
receive
(
:execute
)
described_class
.
new
.
perform
(
123
)
end
end
end
spec/workers/cluster_project_configure_worker_spec.rb
deleted
100644 → 0
View file @
55cb82cf
# frozen_string_literal: true
require
'spec_helper'
describe
ClusterProjectConfigureWorker
,
'#perform'
do
let
(
:worker
)
{
described_class
.
new
}
let
(
:cluster
)
{
create
(
:cluster
,
:project
)
}
it
'configures the cluster'
do
expect
(
Clusters
::
RefreshService
).
to
receive
(
:create_or_update_namespaces_for_project
)
described_class
.
new
.
perform
(
cluster
.
projects
.
first
.
id
)
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