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
6c1de637
Commit
6c1de637
authored
Jul 01, 2019
by
GitLab Bot
Browse files
Options
Browse Files
Download
Plain Diff
Automatic merge of gitlab-org/gitlab-ce master
parents
99ac56ac
bc71d0b4
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
163 additions
and
50 deletions
+163
-50
app/models/concerns/deployable.rb
app/models/concerns/deployable.rb
+1
-0
app/models/deployment.rb
app/models/deployment.rb
+17
-1
changelogs/unreleased/add-clusters-to-deployment.yml
changelogs/unreleased/add-clusters-to-deployment.yml
+5
-0
db/migrate/20190623212503_add_cluster_id_to_deployments.rb
db/migrate/20190623212503_add_cluster_id_to_deployments.rb
+9
-0
db/migrate/20190627051902_add_cluster_id_index_fk_to_deployments.rb
.../20190627051902_add_cluster_id_index_fk_to_deployments.rb
+21
-0
db/schema.rb
db/schema.rb
+4
-1
doc/raketasks/web_hooks.md
doc/raketasks/web_hooks.md
+25
-25
lib/gitlab/ci/build/prerequisite/kubernetes_namespace.rb
lib/gitlab/ci/build/prerequisite/kubernetes_namespace.rb
+1
-1
spec/factories/deployments.rb
spec/factories/deployments.rb
+4
-0
spec/lib/gitlab/ci/build/prerequisite/kubernetes_namespace_spec.rb
...gitlab/ci/build/prerequisite/kubernetes_namespace_spec.rb
+4
-18
spec/models/concerns/deployable_spec.rb
spec/models/concerns/deployable_spec.rb
+10
-4
spec/models/deployment_spec.rb
spec/models/deployment_spec.rb
+62
-0
No files found.
app/models/concerns/deployable.rb
View file @
6c1de637
...
...
@@ -18,6 +18,7 @@ module Deployable
return
unless
environment
.
persisted?
create_deployment!
(
cluster_id:
environment
.
deployment_platform
&
.
cluster_id
,
project_id:
environment
.
project_id
,
environment:
environment
,
ref:
ref
,
...
...
app/models/deployment.rb
View file @
6c1de637
...
...
@@ -7,6 +7,7 @@ class Deployment < ApplicationRecord
belongs_to
:project
,
required:
true
belongs_to
:environment
,
required:
true
belongs_to
:cluster
,
class_name:
'Clusters::Cluster'
,
optional:
true
belongs_to
:user
belongs_to
:deployable
,
polymorphic:
true
# rubocop:disable Cop/PolymorphicAssociations
...
...
@@ -196,7 +197,22 @@ class Deployment < ApplicationRecord
private
def
prometheus_adapter
environment
.
prometheus_adapter
service
=
project
.
find_or_initialize_service
(
'prometheus'
)
if
service
.
can_query?
service
else
cluster_prometheus
end
end
# TODO remove fallback case to deployment_platform_cluster.
# Otherwise we will continue to pay the performance penalty described in
# https://gitlab.com/gitlab-org/gitlab-ce/issues/63475
def
cluster_prometheus
cluster_with_fallback
=
cluster
||
deployment_platform_cluster
cluster_with_fallback
.
application_prometheus
if
cluster_with_fallback
&
.
application_prometheus_available?
end
def
ref_path
...
...
changelogs/unreleased/add-clusters-to-deployment.yml
0 → 100644
View file @
6c1de637
---
title
:
Persist the cluster a deployment was deployed to
merge_request
:
29960
author
:
type
:
fixed
db/migrate/20190623212503_add_cluster_id_to_deployments.rb
0 → 100644
View file @
6c1de637
# frozen_string_literal: true
class
AddClusterIdToDeployments
<
ActiveRecord
::
Migration
[
5.1
]
DOWNTIME
=
false
def
change
add_column
:deployments
,
:cluster_id
,
:integer
end
end
db/migrate/20190627051902_add_cluster_id_index_fk_to_deployments.rb
0 → 100644
View file @
6c1de637
# frozen_string_literal: true
class
AddClusterIdIndexFkToDeployments
<
ActiveRecord
::
Migration
[
5.1
]
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
disable_ddl_transaction!
def
up
add_concurrent_index
:deployments
,
:cluster_id
add_concurrent_foreign_key
:deployments
,
:clusters
,
column: :cluster_id
,
on_delete: :nullify
end
def
down
remove_foreign_key
:deployments
,
:clusters
remove_concurrent_index
:deployments
,
:cluster_id
end
end
db/schema.rb
View file @
6c1de637
...
...
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord
::
Schema
.
define
(
version:
2019062
5184066
)
do
ActiveRecord
::
Schema
.
define
(
version:
2019062
7051902
)
do
# These are extensions that must be enabled in order to support this database
enable_extension
"plpgsql"
...
...
@@ -1066,6 +1066,8 @@ ActiveRecord::Schema.define(version: 20190625184066) do
t
.
string
"on_stop"
t
.
integer
"status"
,
limit:
2
,
null:
false
t
.
datetime_with_timezone
"finished_at"
t
.
integer
"cluster_id"
t
.
index
[
"cluster_id"
],
name:
"index_deployments_on_cluster_id"
,
using: :btree
t
.
index
[
"created_at"
],
name:
"index_deployments_on_created_at"
,
using: :btree
t
.
index
[
"deployable_type"
,
"deployable_id"
],
name:
"index_deployments_on_deployable_type_and_deployable_id"
,
using: :btree
t
.
index
[
"environment_id"
,
"id"
],
name:
"index_deployments_on_environment_id_and_id"
,
using: :btree
...
...
@@ -3659,6 +3661,7 @@ ActiveRecord::Schema.define(version: 20190625184066) do
add_foreign_key
"dependency_proxy_blobs"
,
"namespaces"
,
column:
"group_id"
,
on_delete: :cascade
add_foreign_key
"dependency_proxy_group_settings"
,
"namespaces"
,
column:
"group_id"
,
on_delete: :cascade
add_foreign_key
"deploy_keys_projects"
,
"projects"
,
name:
"fk_58a901ca7e"
,
on_delete: :cascade
add_foreign_key
"deployments"
,
"clusters"
,
name:
"fk_289bba3222"
,
on_delete: :nullify
add_foreign_key
"deployments"
,
"projects"
,
name:
"fk_b9a3851b82"
,
on_delete: :cascade
add_foreign_key
"design_management_designs"
,
"issues"
,
on_delete: :cascade
add_foreign_key
"design_management_designs"
,
"projects"
,
on_delete: :cascade
...
...
doc/raketasks/web_hooks.md
View file @
6c1de637
...
...
@@ -3,53 +3,53 @@
## Add a webhook for **ALL** projects:
```
sh
# omnibus-gitlab
sudo
gitlab-rake gitlab:web_hook:add
URL
=
"http://example.com/hook"
# source installations
bundle
exec
rake gitlab:web_hook:add
URL
=
"http://example.com/hook"
RAILS_ENV
=
production
# omnibus-gitlab
sudo
gitlab-rake gitlab:web_hook:add
URL
=
"http://example.com/hook"
# source installations
bundle
exec
rake gitlab:web_hook:add
URL
=
"http://example.com/hook"
RAILS_ENV
=
production
```
## Add a webhook for projects in a given **NAMESPACE**:
```
sh
# omnibus-gitlab
sudo
gitlab-rake gitlab:web_hook:add
URL
=
"http://example.com/hook"
NAMESPACE
=
acme
# source installations
bundle
exec
rake gitlab:web_hook:add
URL
=
"http://example.com/hook"
NAMESPACE
=
acme
RAILS_ENV
=
production
# omnibus-gitlab
sudo
gitlab-rake gitlab:web_hook:add
URL
=
"http://example.com/hook"
NAMESPACE
=
acme
# source installations
bundle
exec
rake gitlab:web_hook:add
URL
=
"http://example.com/hook"
NAMESPACE
=
acme
RAILS_ENV
=
production
```
## Remove a webhook from **ALL** projects using:
```
sh
# omnibus-gitlab
sudo
gitlab-rake gitlab:web_hook:rm
URL
=
"http://example.com/hook"
# source installations
bundle
exec
rake gitlab:web_hook:rm
URL
=
"http://example.com/hook"
RAILS_ENV
=
production
# omnibus-gitlab
sudo
gitlab-rake gitlab:web_hook:rm
URL
=
"http://example.com/hook"
# source installations
bundle
exec
rake gitlab:web_hook:rm
URL
=
"http://example.com/hook"
RAILS_ENV
=
production
```
## Remove a webhook from projects in a given **NAMESPACE**:
```
sh
# omnibus-gitlab
sudo
gitlab-rake gitlab:web_hook:rm
URL
=
"http://example.com/hook"
NAMESPACE
=
acme
# source installations
bundle
exec
rake gitlab:web_hook:rm
URL
=
"http://example.com/hook"
NAMESPACE
=
acme
RAILS_ENV
=
production
# omnibus-gitlab
sudo
gitlab-rake gitlab:web_hook:rm
URL
=
"http://example.com/hook"
NAMESPACE
=
acme
# source installations
bundle
exec
rake gitlab:web_hook:rm
URL
=
"http://example.com/hook"
NAMESPACE
=
acme
RAILS_ENV
=
production
```
## List **ALL** webhooks:
```
sh
# omnibus-gitlab
sudo
gitlab-rake gitlab:web_hook:list
# source installations
bundle
exec
rake gitlab:web_hook:list
RAILS_ENV
=
production
# omnibus-gitlab
sudo
gitlab-rake gitlab:web_hook:list
# source installations
bundle
exec
rake gitlab:web_hook:list
RAILS_ENV
=
production
```
## List the webhooks from projects in a given **NAMESPACE**:
```
sh
# omnibus-gitlab
sudo
gitlab-rake gitlab:web_hook:list
NAMESPACE
=
acme
# source installations
bundle
exec
rake gitlab:web_hook:list
NAMESPACE
=
acme
RAILS_ENV
=
production
```
\ No newline at end of file
# omnibus-gitlab
sudo
gitlab-rake gitlab:web_hook:list
NAMESPACE
=
acme
# source installations
bundle
exec
rake gitlab:web_hook:list
NAMESPACE
=
acme
RAILS_ENV
=
production
```
lib/gitlab/ci/build/prerequisite/kubernetes_namespace.rb
View file @
6c1de637
...
...
@@ -20,7 +20,7 @@ module Gitlab
private
def
deployment_cluster
build
.
deployment
&
.
deployment_platform_
cluster
build
.
deployment
&
.
cluster
end
def
kubernetes_namespace
...
...
spec/factories/deployments.rb
View file @
6c1de637
...
...
@@ -22,6 +22,10 @@ FactoryBot.define do
ref
'pages-deploy'
end
trait
:on_cluster
do
cluster
factory:
%i(cluster provided_by_gcp)
end
trait
:running
do
status
:running
end
...
...
spec/lib/gitlab/ci/build/prerequisite/kubernetes_namespace_spec.rb
View file @
6c1de637
...
...
@@ -17,15 +17,12 @@ describe Gitlab::Ci::Build::Prerequisite::KubernetesNamespace do
end
context
'build has a deployment'
do
let!
(
:deployment
)
{
create
(
:deployment
,
deployable:
build
)
}
let!
(
:deployment
)
{
create
(
:deployment
,
deployable:
build
,
cluster:
cluster
)
}
let
(
:cluster
)
{
nil
}
context
'and a cluster to deploy to'
do
let
(
:cluster
)
{
create
(
:cluster
,
:group
)
}
before
do
allow
(
build
.
deployment
).
to
receive
(
:deployment_platform_cluster
).
and_return
(
cluster
)
end
it
{
is_expected
.
to
be_truthy
}
context
'and the cluster is not managed'
do
...
...
@@ -48,28 +45,21 @@ describe Gitlab::Ci::Build::Prerequisite::KubernetesNamespace do
end
context
'and no cluster to deploy to'
do
before
do
expect
(
deployment
.
deployment_platform_cluster
).
to
be_nil
end
it
{
is_expected
.
to
be_falsey
}
end
end
end
describe
'#complete!'
do
let!
(
:deployment
)
{
create
(
:deployment
,
deployable:
build
)
}
let!
(
:deployment
)
{
create
(
:deployment
,
deployable:
build
,
cluster:
cluster
)
}
let
(
:service
)
{
double
(
execute:
true
)
}
let
(
:cluster
)
{
nil
}
subject
{
described_class
.
new
(
build
).
complete!
}
context
'completion is required'
do
let
(
:cluster
)
{
create
(
:cluster
,
:group
)
}
before
do
allow
(
build
.
deployment
).
to
receive
(
:deployment_platform_cluster
).
and_return
(
cluster
)
end
it
'creates a kubernetes namespace'
do
expect
(
Clusters
::
Gcp
::
Kubernetes
::
CreateOrUpdateNamespaceService
)
.
to
receive
(
:new
)
...
...
@@ -83,10 +73,6 @@ describe Gitlab::Ci::Build::Prerequisite::KubernetesNamespace do
end
context
'completion is not required'
do
before
do
expect
(
deployment
.
deployment_platform_cluster
).
to
be_nil
end
it
'does not create a namespace'
do
expect
(
Clusters
::
Gcp
::
Kubernetes
::
CreateOrUpdateNamespaceService
).
not_to
receive
(
:new
)
...
...
spec/models/concerns/deployable_spec.rb
View file @
6c1de637
...
...
@@ -7,10 +7,6 @@ describe Deployable do
let
(
:deployment
)
{
job
.
deployment
}
let
(
:environment
)
{
deployment
&
.
environment
}
before
do
job
.
reload
end
context
'when the deployable object will deploy to production'
do
let!
(
:job
)
{
create
(
:ci_build
,
:start_review_app
)
}
...
...
@@ -26,6 +22,16 @@ describe Deployable do
end
end
context
'when the deployable object will deploy to a cluster'
do
let
(
:project
)
{
create
(
:project
)
}
let!
(
:cluster
)
{
create
(
:cluster
,
:provided_by_user
,
projects:
[
project
])
}
let!
(
:job
)
{
create
(
:ci_build
,
:start_review_app
,
project:
project
)
}
it
'creates a deployment with cluster association'
do
expect
(
deployment
.
cluster
).
to
eq
(
cluster
)
end
end
context
'when the deployable object will stop an environment'
do
let!
(
:job
)
{
create
(
:ci_build
,
:stop_review_app
)
}
...
...
spec/models/deployment_spec.rb
View file @
6c1de637
...
...
@@ -7,6 +7,7 @@ describe Deployment do
it
{
is_expected
.
to
belong_to
(
:project
).
required
}
it
{
is_expected
.
to
belong_to
(
:environment
).
required
}
it
{
is_expected
.
to
belong_to
(
:cluster
).
class_name
(
'Clusters::Cluster'
)
}
it
{
is_expected
.
to
belong_to
(
:user
)
}
it
{
is_expected
.
to
belong_to
(
:deployable
)
}
...
...
@@ -294,6 +295,67 @@ describe Deployment do
end
end
describe
'#has_metrics?'
do
subject
{
deployment
.
has_metrics?
}
context
'when deployment is failed'
do
let
(
:deployment
)
{
create
(
:deployment
,
:failed
)
}
it
{
is_expected
.
to
be_falsy
}
end
context
'when deployment is success'
do
let
(
:deployment
)
{
create
(
:deployment
,
:success
)
}
context
'without a monitoring service'
do
it
{
is_expected
.
to
be_falsy
}
end
context
'with a Prometheus Service'
do
let
(
:prometheus_service
)
{
double
(
:prometheus_service
,
can_query?:
true
)
}
before
do
allow
(
deployment
.
project
).
to
receive
(
:find_or_initialize_service
).
with
(
'prometheus'
).
and_return
prometheus_service
end
it
{
is_expected
.
to
be_truthy
}
end
context
'with a Prometheus Service that cannot query'
do
let
(
:prometheus_service
)
{
double
(
:prometheus_service
,
can_query?:
false
)
}
before
do
allow
(
deployment
.
project
).
to
receive
(
:find_or_initialize_service
).
with
(
'prometheus'
).
and_return
prometheus_service
end
it
{
is_expected
.
to
be_falsy
}
end
context
'with a cluster Prometheus'
do
let
(
:deployment
)
{
create
(
:deployment
,
:success
,
:on_cluster
)
}
let!
(
:prometheus
)
{
create
(
:clusters_applications_prometheus
,
:installed
,
cluster:
deployment
.
cluster
)
}
before
do
expect
(
deployment
.
cluster
.
application_prometheus
).
to
receive
(
:can_query?
).
and_return
(
true
)
end
it
{
is_expected
.
to
be_truthy
}
end
context
'fallback deployment platform'
do
let
(
:cluster
)
{
create
(
:cluster
,
:provided_by_user
,
environment_scope:
'*'
,
projects:
[
deployment
.
project
])
}
let!
(
:prometheus
)
{
create
(
:clusters_applications_prometheus
,
:installed
,
cluster:
cluster
)
}
before
do
expect
(
deployment
.
project
).
to
receive
(
:deployment_platform
).
and_return
(
cluster
.
platform
)
expect
(
cluster
.
application_prometheus
).
to
receive
(
:can_query?
).
and_return
(
true
)
end
it
{
is_expected
.
to
be_truthy
}
end
end
end
describe
'#metrics'
do
let
(
:deployment
)
{
create
(
:deployment
,
:success
)
}
let
(
:prometheus_adapter
)
{
double
(
'prometheus_adapter'
,
can_query?:
true
)
}
...
...
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