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
0c15c5b5
Commit
0c15c5b5
authored
Nov 28, 2019
by
Tiger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validate unique environment scope for instance clusters
https://gitlab.com/gitlab-org/gitlab/merge_requests/20886
parent
f88ed9ed
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
79 additions
and
13 deletions
+79
-13
app/models/clusters/cluster.rb
app/models/clusters/cluster.rb
+15
-0
changelogs/unreleased/37480-validate-instance-level-cluster-environment-scope.yml
...480-validate-instance-level-cluster-environment-scope.yml
+5
-0
ee/app/models/ee/clusters/cluster.rb
ee/app/models/ee/clusters/cluster.rb
+7
-13
ee/spec/models/ee/clusters/cluster_spec.rb
ee/spec/models/ee/clusters/cluster_spec.rb
+18
-0
spec/models/clusters/cluster_spec.rb
spec/models/clusters/cluster_spec.rb
+34
-0
No files found.
app/models/clusters/cluster.rb
View file @
0c15c5b5
...
...
@@ -271,6 +271,21 @@ module Clusters
kubernetes_namespaces
.
delete_all
(
:delete_all
)
end
def
clusterable
return
unless
cluster_type
case
cluster_type
when
'project_type'
project
when
'group_type'
group
when
'instance_type'
instance
else
raise
NotImplementedError
end
end
private
def
unique_management_project_environment_scope
...
...
changelogs/unreleased/37480-validate-instance-level-cluster-environment-scope.yml
0 → 100644
View file @
0c15c5b5
---
title
:
Validate unique environment scope for instance clusters
merge_request
:
20886
author
:
type
:
fixed
ee/app/models/ee/clusters/cluster.rb
View file @
0c15c5b5
...
...
@@ -12,22 +12,16 @@ module EE
validate
:unique_environment_scope
end
def
unique_environment_scope
if
project
&&
project
.
clusters
.
where
(
environment_scope:
environment_scope
).
where
.
not
(
id:
id
).
exists?
errors
.
add
(
:environment_scope
,
"cannot add duplicated environment scope"
)
return
false
end
def
prometheus_adapter
application_prometheus
end
private
if
group
&&
group
.
clusters
.
where
(
environment_scope:
environment_scope
).
where
.
not
(
id:
id
).
exists?
def
unique_environment_scope
if
clusterable
.
present?
&&
clusterable
.
clusters
.
where
(
environment_scope:
environment_scope
).
where
.
not
(
id:
id
).
exists?
errors
.
add
(
:environment_scope
,
'cannot add duplicated environment scope'
)
return
false
end
true
end
def
prometheus_adapter
application_prometheus
end
end
end
...
...
ee/spec/models/ee/clusters/cluster_spec.rb
View file @
0c15c5b5
...
...
@@ -61,6 +61,24 @@ describe Clusters::Cluster do
it
{
is_expected
.
to
be_truthy
}
end
end
context
'for an instance cluster'
do
before
do
create
(
:cluster
,
:instance
,
environment_scope:
'product/*'
)
end
context
'identical environment scope exists'
do
let
(
:cluster
)
{
build
(
:cluster
,
:instance
,
environment_scope:
'product/*'
)
}
it
{
is_expected
.
to
be_falsey
}
end
context
'identical environment scope does not exist'
do
let
(
:cluster
)
{
build
(
:cluster
,
:instance
,
environment_scope:
'*'
)
}
it
{
is_expected
.
to
be_truthy
}
end
end
end
end
end
spec/models/clusters/cluster_spec.rb
View file @
0c15c5b5
...
...
@@ -976,4 +976,38 @@ describe Clusters::Cluster, :use_clean_rails_memory_store_caching do
expect
(
cluster
.
kubernetes_namespaces
).
to
be_empty
end
end
describe
'#clusterable'
do
subject
{
cluster
.
clusterable
}
context
'project type'
do
let
(
:cluster
)
{
create
(
:cluster
,
:project
)
}
it
{
is_expected
.
to
eq
(
cluster
.
project
)
}
end
context
'group type'
do
let
(
:cluster
)
{
create
(
:cluster
,
:group
)
}
it
{
is_expected
.
to
eq
(
cluster
.
group
)
}
end
context
'instance type'
do
let
(
:cluster
)
{
create
(
:cluster
,
:instance
)
}
it
{
is_expected
.
to
be_a
(
Clusters
::
Instance
)
}
end
context
'unknown type'
do
let
(
:cluster
)
{
create
(
:cluster
,
:project
)
}
before
do
allow
(
cluster
).
to
receive
(
:cluster_type
).
and_return
(
'unknown_type'
)
end
it
'raises NotImplementedError'
do
expect
{
subject
}.
to
raise_error
(
NotImplementedError
)
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