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
af04ad57
Commit
af04ad57
authored
Jan 05, 2018
by
Mayra Cabrera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create separate EE::DeploymentPlatform module
parent
87f770d4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
151 additions
and
144 deletions
+151
-144
ee/app/models/concerns/ee/deployment_platform.rb
ee/app/models/concerns/ee/deployment_platform.rb
+13
-0
ee/app/models/ee/project.rb
ee/app/models/ee/project.rb
+1
-10
spec/ee/spec/models/concerns/ee/deployment_platform_spec.rb
spec/ee/spec/models/concerns/ee/deployment_platform_spec.rb
+137
-0
spec/ee/spec/models/ee/project_spec.rb
spec/ee/spec/models/ee/project_spec.rb
+0
-134
No files found.
ee/app/models/concerns/ee/deployment_platform.rb
0 → 100644
View file @
af04ad57
module
EE
module
DeploymentPlatform
def
deployment_platform
(
environment:
nil
)
return
super
unless
environment
&&
feature_available?
(
:multiple_clusters
)
@deployment_platform
||=
# rubocop:disable Gitlab/ModuleWithInstanceVariables
clusters
.
enabled
.
on_environment
(
environment
.
name
)
.
last
&
.
platform_kubernetes
super
# Wildcard or KubernetesService
end
end
end
ee/app/models/ee/project.rb
View file @
af04ad57
...
...
@@ -10,6 +10,7 @@ module EE
prepended
do
include
Elastic
::
ProjectsSearch
prepend
ImportStatusStateMachine
include
EE
::
DeploymentPlatform
before_validation
:mark_remote_mirrors_for_removal
...
...
@@ -255,16 +256,6 @@ module EE
end
end
def
deployment_platform
(
environment:
nil
)
return
super
unless
environment
&&
feature_available?
(
:multiple_clusters
)
@deployment_platform
||=
# rubocop:disable Gitlab/ModuleWithInstanceVariables
clusters
.
enabled
.
on_environment
(
environment
.
name
)
.
last
&
.
platform_kubernetes
super
# Wildcard or KubernetesService
end
def
secret_variables_for
(
ref
:,
environment:
nil
)
return
super
.
where
(
environment_scope:
'*'
)
unless
environment
&&
feature_available?
(
:variable_environment_scope
)
...
...
spec/ee/spec/models/concerns/ee/deployment_platform_spec.rb
0 → 100644
View file @
af04ad57
require
'rails_helper'
describe
EE
::
DeploymentPlatform
do
describe
'#deployment_platform'
do
let
(
:project
)
{
create
(
:project
)
}
context
'when environment is specified'
do
let
(
:environment
)
{
create
(
:environment
,
project:
project
,
name:
'review/name'
)
}
let!
(
:default_cluster
)
{
create
(
:cluster
,
:provided_by_user
,
projects:
[
project
],
environment_scope:
'*'
)
}
let!
(
:cluster
)
{
create
(
:cluster
,
:provided_by_user
,
environment_scope:
'review/*'
,
projects:
[
project
])
}
subject
{
project
.
deployment_platform
(
environment:
environment
)
}
shared_examples
'matching environment scope'
do
context
'when multiple clusters is available'
do
before
do
stub_licensed_features
(
multiple_clusters:
true
)
end
it
'returns environment specific cluster'
do
is_expected
.
to
eq
(
cluster
.
platform_kubernetes
)
end
end
context
'when multiple clusters is unavailable'
do
before
do
stub_licensed_features
(
multiple_clusters:
false
)
end
it
'returns a kubernetes platform'
do
is_expected
.
to
be_kind_of
(
Clusters
::
Platforms
::
Kubernetes
)
end
end
end
shared_examples
'not matching environment scope'
do
context
'when multiple clusters is available'
do
before
do
stub_licensed_features
(
multiple_clusters:
true
)
end
it
'returns default cluster'
do
is_expected
.
to
eq
(
default_cluster
.
platform_kubernetes
)
end
end
context
'when multiple clusters is unavailable'
do
before
do
stub_licensed_features
(
multiple_clusters:
false
)
end
it
'returns a kubernetes platform'
do
is_expected
.
to
be_kind_of
(
Clusters
::
Platforms
::
Kubernetes
)
end
end
end
context
'when environment scope is exactly matched'
do
before
do
cluster
.
update!
(
environment_scope:
'review/name'
)
end
it_behaves_like
'matching environment scope'
end
context
'when environment scope is matched by wildcard'
do
before
do
cluster
.
update!
(
environment_scope:
'review/*'
)
end
it_behaves_like
'matching environment scope'
end
context
'when environment scope does not match'
do
before
do
cluster
.
update!
(
environment_scope:
'review/*/special'
)
end
it_behaves_like
'not matching environment scope'
end
context
'when environment scope has _'
do
before
do
stub_licensed_features
(
multiple_clusters:
true
)
end
it
'does not treat it as wildcard'
do
cluster
.
update!
(
environment_scope:
'foo_bar/*'
)
is_expected
.
to
eq
(
default_cluster
.
platform_kubernetes
)
end
it
'matches literally for _'
do
cluster
.
update!
(
environment_scope:
'foo_bar/*'
)
environment
.
update!
(
name:
'foo_bar/test'
)
is_expected
.
to
eq
(
cluster
.
platform_kubernetes
)
end
end
# The environment name and scope cannot have % at the moment,
# but we're considering relaxing it and we should also make sure
# it doesn't break in case some data sneaked in somehow as we're
# not checking this integrity in database level.
context
'when environment scope has %'
do
before
do
stub_licensed_features
(
multiple_clusters:
true
)
end
it
'does not treat it as wildcard'
do
cluster
.
update_attribute
(
:environment_scope
,
'*%*'
)
is_expected
.
to
eq
(
default_cluster
.
platform_kubernetes
)
end
it
'matches literally for %'
do
cluster
.
update_attribute
(
:environment_scope
,
'foo%bar/*'
)
environment
.
update_attribute
(
:name
,
'foo%bar/test'
)
is_expected
.
to
eq
(
cluster
.
platform_kubernetes
)
end
end
context
'when perfectly matched cluster exists'
do
let!
(
:perfectly_matched_cluster
)
{
create
(
:cluster
,
:provided_by_user
,
projects:
[
project
],
environment_scope:
'review/name'
)
}
before
do
stub_licensed_features
(
multiple_clusters:
true
)
end
it
'returns perfectly matched cluster as highest precedence'
do
is_expected
.
to
eq
(
perfectly_matched_cluster
.
platform_kubernetes
)
end
end
end
end
end
spec/ee/spec/models/ee/project_spec.rb
View file @
af04ad57
...
...
@@ -703,140 +703,6 @@ describe Project do
end
end
describe
'#deployment_platform'
do
let
(
:project
)
{
create
(
:project
)
}
context
'when environment is specified'
do
let
(
:environment
)
{
create
(
:environment
,
project:
project
,
name:
'review/name'
)
}
let!
(
:default_cluster
)
{
create
(
:cluster
,
:provided_by_user
,
projects:
[
project
],
environment_scope:
'*'
)
}
let!
(
:cluster
)
{
create
(
:cluster
,
:provided_by_user
,
environment_scope:
'review/*'
,
projects:
[
project
])
}
subject
{
project
.
deployment_platform
(
environment:
environment
)
}
shared_examples
'matching environment scope'
do
context
'when multiple clusters is available'
do
before
do
stub_licensed_features
(
multiple_clusters:
true
)
end
it
'returns environment specific cluster'
do
is_expected
.
to
eq
(
cluster
.
platform_kubernetes
)
end
end
context
'when multiple clusters is unavailable'
do
before
do
stub_licensed_features
(
multiple_clusters:
false
)
end
it
'returns a kubernetes platform'
do
is_expected
.
to
be_kind_of
(
Clusters
::
Platforms
::
Kubernetes
)
end
end
end
shared_examples
'not matching environment scope'
do
context
'when multiple clusters is available'
do
before
do
stub_licensed_features
(
multiple_clusters:
true
)
end
it
'returns default cluster'
do
is_expected
.
to
eq
(
default_cluster
.
platform_kubernetes
)
end
end
context
'when multiple clusters is unavailable'
do
before
do
stub_licensed_features
(
multiple_clusters:
false
)
end
it
'returns a kubernetes platform'
do
is_expected
.
to
be_kind_of
(
Clusters
::
Platforms
::
Kubernetes
)
end
end
end
context
'when environment scope is exactly matched'
do
before
do
cluster
.
update!
(
environment_scope:
'review/name'
)
end
it_behaves_like
'matching environment scope'
end
context
'when environment scope is matched by wildcard'
do
before
do
cluster
.
update!
(
environment_scope:
'review/*'
)
end
it_behaves_like
'matching environment scope'
end
context
'when environment scope does not match'
do
before
do
cluster
.
update!
(
environment_scope:
'review/*/special'
)
end
it_behaves_like
'not matching environment scope'
end
context
'when environment scope has _'
do
before
do
stub_licensed_features
(
multiple_clusters:
true
)
end
it
'does not treat it as wildcard'
do
cluster
.
update!
(
environment_scope:
'foo_bar/*'
)
is_expected
.
to
eq
(
default_cluster
.
platform_kubernetes
)
end
it
'matches literally for _'
do
cluster
.
update!
(
environment_scope:
'foo_bar/*'
)
environment
.
update!
(
name:
'foo_bar/test'
)
is_expected
.
to
eq
(
cluster
.
platform_kubernetes
)
end
end
# The environment name and scope cannot have % at the moment,
# but we're considering relaxing it and we should also make sure
# it doesn't break in case some data sneaked in somehow as we're
# not checking this integrity in database level.
context
'when environment scope has %'
do
before
do
stub_licensed_features
(
multiple_clusters:
true
)
end
it
'does not treat it as wildcard'
do
cluster
.
update_attribute
(
:environment_scope
,
'*%*'
)
is_expected
.
to
eq
(
default_cluster
.
platform_kubernetes
)
end
it
'matches literally for %'
do
cluster
.
update_attribute
(
:environment_scope
,
'foo%bar/*'
)
environment
.
update_attribute
(
:name
,
'foo%bar/test'
)
is_expected
.
to
eq
(
cluster
.
platform_kubernetes
)
end
end
context
'when perfectly matched cluster exists'
do
let!
(
:perfectly_matched_cluster
)
{
create
(
:cluster
,
:provided_by_user
,
projects:
[
project
],
environment_scope:
'review/name'
)
}
before
do
stub_licensed_features
(
multiple_clusters:
true
)
end
it
'returns perfectly matched cluster as highest precedence'
do
is_expected
.
to
eq
(
perfectly_matched_cluster
.
platform_kubernetes
)
end
end
end
end
describe
'#secret_variables_for'
do
let
(
:project
)
{
create
(
:project
)
}
...
...
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