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
0
Merge Requests
0
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
Boxiang Sun
gitlab-ce
Commits
93e9793c
Commit
93e9793c
authored
Jan 04, 2018
by
Mayra Cabrera
Committed by
Kamil Trzciński
Jan 04, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Create Kubernetes based on Application Templates
parent
6f1b4dc7
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
140 additions
and
26 deletions
+140
-26
app/models/concerns/deployment_platform.rb
app/models/concerns/deployment_platform.rb
+47
-0
app/models/project.rb
app/models/project.rb
+1
-6
app/models/service.rb
app/models/service.rb
+5
-0
changelogs/unreleased/41056-create-cluster-from-kubernetes-integration-application-template.yml
...ster-from-kubernetes-integration-application-template.yml
+5
-0
spec/features/projects/import_export/export_file_spec.rb
spec/features/projects/import_export/export_file_spec.rb
+1
-1
spec/models/concerns/deployment_platform_spec.rb
spec/models/concerns/deployment_platform_spec.rb
+73
-0
spec/models/project_spec.rb
spec/models/project_spec.rb
+0
-19
spec/models/service_spec.rb
spec/models/service_spec.rb
+8
-0
No files found.
app/models/concerns/deployment_platform.rb
0 → 100644
View file @
93e9793c
module
DeploymentPlatform
def
deployment_platform
@deployment_platform
||=
find_cluster_platform_kubernetes
@deployment_platform
||=
find_kubernetes_service_integration
@deployment_platform
||=
build_cluster_and_deployment_platform
end
private
def
find_cluster_platform_kubernetes
clusters
.
find_by
(
enabled:
true
)
&
.
platform_kubernetes
end
def
find_kubernetes_service_integration
services
.
deployment
.
reorder
(
nil
).
find_by
(
active:
true
)
end
def
build_cluster_and_deployment_platform
return
unless
kubernetes_service_template
cluster
=
::
Clusters
::
Cluster
.
create
(
cluster_attributes_from_service_template
)
cluster
.
platform_kubernetes
if
cluster
.
persisted?
end
def
kubernetes_service_template
@kubernetes_service_template
||=
KubernetesService
.
active
.
find_by_template
end
def
cluster_attributes_from_service_template
{
name:
'kubernetes-template'
,
projects:
[
self
],
provider_type: :user
,
platform_type: :kubernetes
,
platform_kubernetes_attributes:
platform_kubernetes_attributes_from_service_template
}
end
def
platform_kubernetes_attributes_from_service_template
{
api_url:
kubernetes_service_template
.
api_url
,
ca_pem:
kubernetes_service_template
.
ca_pem
,
token:
kubernetes_service_template
.
token
,
namespace:
kubernetes_service_template
.
namespace
}
end
end
app/models/project.rb
View file @
93e9793c
...
@@ -19,6 +19,7 @@ class Project < ActiveRecord::Base
...
@@ -19,6 +19,7 @@ class Project < ActiveRecord::Base
include
Routable
include
Routable
include
GroupDescendant
include
GroupDescendant
include
Gitlab
::
SQL
::
Pattern
include
Gitlab
::
SQL
::
Pattern
include
DeploymentPlatform
extend
Gitlab
::
ConfigHelper
extend
Gitlab
::
ConfigHelper
extend
Gitlab
::
CurrentSettings
extend
Gitlab
::
CurrentSettings
...
@@ -904,12 +905,6 @@ class Project < ActiveRecord::Base
...
@@ -904,12 +905,6 @@ class Project < ActiveRecord::Base
@ci_service
||=
ci_services
.
reorder
(
nil
).
find_by
(
active:
true
)
@ci_service
||=
ci_services
.
reorder
(
nil
).
find_by
(
active:
true
)
end
end
# TODO: This will be extended for multiple enviroment clusters
def
deployment_platform
@deployment_platform
||=
clusters
.
find_by
(
enabled:
true
)
&
.
platform_kubernetes
@deployment_platform
||=
services
.
where
(
category: :deployment
).
reorder
(
nil
).
find_by
(
active:
true
)
end
def
monitoring_services
def
monitoring_services
services
.
where
(
category: :monitoring
)
services
.
where
(
category: :monitoring
)
end
end
...
...
app/models/service.rb
View file @
93e9793c
...
@@ -44,6 +44,7 @@ class Service < ActiveRecord::Base
...
@@ -44,6 +44,7 @@ class Service < ActiveRecord::Base
scope
:pipeline_hooks
,
->
{
where
(
pipeline_events:
true
,
active:
true
)
}
scope
:pipeline_hooks
,
->
{
where
(
pipeline_events:
true
,
active:
true
)
}
scope
:wiki_page_hooks
,
->
{
where
(
wiki_page_events:
true
,
active:
true
)
}
scope
:wiki_page_hooks
,
->
{
where
(
wiki_page_events:
true
,
active:
true
)
}
scope
:external_issue_trackers
,
->
{
issue_trackers
.
active
.
without_defaults
}
scope
:external_issue_trackers
,
->
{
issue_trackers
.
active
.
without_defaults
}
scope
:deployment
,
->
{
where
(
category:
'deployment'
)
}
default_value_for
:category
,
'common'
default_value_for
:category
,
'common'
...
@@ -271,6 +272,10 @@ class Service < ActiveRecord::Base
...
@@ -271,6 +272,10 @@ class Service < ActiveRecord::Base
nil
nil
end
end
def
self
.
find_by_template
find_by
(
template:
true
)
end
private
private
def
cache_project_has_external_issue_tracker
def
cache_project_has_external_issue_tracker
...
...
changelogs/unreleased/41056-create-cluster-from-kubernetes-integration-application-template.yml
0 → 100644
View file @
93e9793c
---
title
:
Allow automatic creation of Kubernetes Integration from template
merge_request
:
16104
author
:
type
:
added
spec/features/projects/import_export/export_file_spec.rb
View file @
93e9793c
...
@@ -2,7 +2,7 @@ require 'spec_helper'
...
@@ -2,7 +2,7 @@ require 'spec_helper'
# Integration test that exports a file using the Import/Export feature
# Integration test that exports a file using the Import/Export feature
# It looks up for any sensitive word inside the JSON, so if a sensitive word is found
# It looks up for any sensitive word inside the JSON, so if a sensitive word is found
# we'
'
l have to either include it adding the model that includes it to the +safe_list+
# we'
l
l have to either include it adding the model that includes it to the +safe_list+
# or make sure the attribute is blacklisted in the +import_export.yml+ configuration
# or make sure the attribute is blacklisted in the +import_export.yml+ configuration
feature
'Import/Export - project export integration test'
,
:js
do
feature
'Import/Export - project export integration test'
,
:js
do
include
Select2Helper
include
Select2Helper
...
...
spec/models/concerns/deployment_platform_spec.rb
0 → 100644
View file @
93e9793c
require
'rails_helper'
describe
DeploymentPlatform
do
let
(
:project
)
{
create
(
:project
)
}
describe
'#deployment_platform'
do
subject
{
project
.
deployment_platform
}
context
'with no Kubernetes configuration on CI/CD, no Kubernetes Service and a Kubernetes template configured'
do
let!
(
:kubernetes_service
)
{
create
(
:kubernetes_service
,
template:
true
)
}
it
'returns a platform kubernetes'
do
expect
(
subject
).
to
be_a_kind_of
(
Clusters
::
Platforms
::
Kubernetes
)
end
it
'creates a cluster and a platform kubernetes'
do
expect
{
subject
}
.
to
change
{
Clusters
::
Cluster
.
count
}.
by
(
1
)
.
and
change
{
Clusters
::
Platforms
::
Kubernetes
.
count
}.
by
(
1
)
end
it
'includes appropriate attributes for Cluster'
do
cluster
=
subject
.
cluster
expect
(
cluster
.
name
).
to
eq
(
'kubernetes-template'
)
expect
(
cluster
.
project
).
to
eq
(
project
)
expect
(
cluster
.
provider_type
).
to
eq
(
'user'
)
expect
(
cluster
.
platform_type
).
to
eq
(
'kubernetes'
)
end
it
'creates a platform kubernetes'
do
expect
{
subject
}.
to
change
{
Clusters
::
Platforms
::
Kubernetes
.
count
}.
by
(
1
)
end
it
'copies attributes from Clusters::Platform::Kubernetes template into the new Cluster::Platforms::Kubernetes'
do
expect
(
subject
.
api_url
).
to
eq
(
kubernetes_service
.
api_url
)
expect
(
subject
.
ca_pem
).
to
eq
(
kubernetes_service
.
ca_pem
)
expect
(
subject
.
token
).
to
eq
(
kubernetes_service
.
token
)
expect
(
subject
.
namespace
).
to
eq
(
kubernetes_service
.
namespace
)
end
end
context
'with no Kubernetes configuration on CI/CD, no Kubernetes Service and no Kubernetes template configured'
do
it
{
is_expected
.
to
be_nil
}
end
context
'when user configured kubernetes from CI/CD > Clusters'
do
let!
(
:cluster
)
{
create
(
:cluster
,
:provided_by_gcp
,
projects:
[
project
])
}
let
(
:platform_kubernetes
)
{
cluster
.
platform_kubernetes
}
it
'returns the Kubernetes platform'
do
expect
(
subject
).
to
eq
(
platform_kubernetes
)
end
end
context
'when user configured kubernetes integration from project services'
do
let!
(
:kubernetes_service
)
{
create
(
:kubernetes_service
,
project:
project
)
}
it
'returns the Kubernetes service'
do
expect
(
subject
).
to
eq
(
kubernetes_service
)
end
end
context
'when the cluster creation fails'
do
let!
(
:kubernetes_service
)
{
create
(
:kubernetes_service
,
template:
true
)
}
before
do
allow_any_instance_of
(
Clusters
::
Cluster
).
to
receive
(
:persisted?
).
and_return
(
false
)
end
it
{
is_expected
.
to
be_nil
}
end
end
end
spec/models/project_spec.rb
View file @
93e9793c
...
@@ -3137,25 +3137,6 @@ describe Project do
...
@@ -3137,25 +3137,6 @@ describe Project do
end
end
end
end
describe
'#deployment_platform'
do
subject
{
project
.
deployment_platform
}
let
(
:project
)
{
create
(
:project
)
}
context
'when user configured kubernetes from Integration > Kubernetes'
do
let!
(
:kubernetes_service
)
{
create
(
:kubernetes_service
,
project:
project
)
}
it
{
is_expected
.
to
eq
(
kubernetes_service
)
}
end
context
'when user configured kubernetes from CI/CD > Clusters'
do
let!
(
:cluster
)
{
create
(
:cluster
,
:provided_by_gcp
,
projects:
[
project
])
}
let
(
:platform_kubernetes
)
{
cluster
.
platform_kubernetes
}
it
{
is_expected
.
to
eq
(
platform_kubernetes
)
}
end
end
describe
'#write_repository_config'
do
describe
'#write_repository_config'
do
set
(
:project
)
{
create
(
:project
,
:repository
)
}
set
(
:project
)
{
create
(
:project
,
:repository
)
}
...
...
spec/models/service_spec.rb
View file @
93e9793c
...
@@ -272,4 +272,12 @@ describe Service do
...
@@ -272,4 +272,12 @@ describe Service do
expect
(
service
.
deprecation_message
).
to
be_nil
expect
(
service
.
deprecation_message
).
to
be_nil
end
end
end
end
describe
'.find_by_template'
do
let!
(
:kubernetes_service
)
{
create
(
:kubernetes_service
,
template:
true
)
}
it
'returns service template'
do
expect
(
KubernetesService
.
find_by_template
).
to
eq
(
kubernetes_service
)
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