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
97225551
Commit
97225551
authored
Oct 03, 2017
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finish tests
parent
bfa42940
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
270 additions
and
46 deletions
+270
-46
app/controllers/projects/environments_controller.rb
app/controllers/projects/environments_controller.rb
+5
-0
app/models/concerns/reactive_caching.rb
app/models/concerns/reactive_caching.rb
+4
-0
ee/app/models/concerns/ee/kubernetes_service.rb
ee/app/models/concerns/ee/kubernetes_service.rb
+10
-1
lib/gitlab/kubernetes/rollout_status.rb
lib/gitlab/kubernetes/rollout_status.rb
+1
-1
spec/controllers/projects/environments_controller_spec.rb
spec/controllers/projects/environments_controller_spec.rb
+4
-0
spec/ee/spec/models/project_services/kubernetes_service_spec.rb
...e/spec/models/project_services/kubernetes_service_spec.rb
+25
-0
spec/fixtures/api/schemas/deployment.json
spec/fixtures/api/schemas/deployment.json
+45
-0
spec/fixtures/api/schemas/deployments.json
spec/fixtures/api/schemas/deployments.json
+1
-43
spec/fixtures/api/schemas/environment.json
spec/fixtures/api/schemas/environment.json
+67
-0
spec/fixtures/api/schemas/environments.json
spec/fixtures/api/schemas/environments.json
+24
-0
spec/fixtures/api/schemas/environments_group.json
spec/fixtures/api/schemas/environments_group.json
+20
-0
spec/fixtures/api/schemas/rollout_status.json
spec/fixtures/api/schemas/rollout_status.json
+45
-0
spec/lib/gitlab/kubernetes/rollout_status_spec.rb
spec/lib/gitlab/kubernetes/rollout_status_spec.rb
+13
-1
spec/models/concerns/reactive_caching_spec.rb
spec/models/concerns/reactive_caching_spec.rb
+6
-0
No files found.
app/controllers/projects/environments_controller.rb
View file @
97225551
...
...
@@ -7,6 +7,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController
before_action
:authorize_admin_environment!
,
only:
[
:terminal
,
:terminal_websocket_authorize
]
before_action
:environment
,
only:
[
:show
,
:edit
,
:update
,
:stop
,
:terminal
,
:terminal_websocket_authorize
,
:metrics
]
before_action
:verify_api_request!
,
only: :terminal_websocket_authorize
before_action
:refresh_rollout_status
,
only:
[
:index
]
def
index
@environments
=
project
.
environments
...
...
@@ -147,6 +148,10 @@ class Projects::EnvironmentsController < Projects::ApplicationController
Gitlab
::
Workhorse
.
verify_api_request!
(
request
.
headers
)
end
def
refresh_rollout_status
environment
.
rollout_status
end
def
environment_params
params
.
require
(
:environment
).
permit
(
:name
,
:external_url
)
end
...
...
app/models/concerns/reactive_caching.rb
View file @
97225551
...
...
@@ -59,6 +59,9 @@ module ReactiveCaching
raise
NotImplementedError
end
def
reactive_cache_updated
(
*
args
)
end
def
with_reactive_cache
(
*
args
,
&
blk
)
within_reactive_cache_lifetime
(
*
args
)
do
data
=
Rails
.
cache
.
read
(
full_reactive_cache_key
(
*
args
))
...
...
@@ -79,6 +82,7 @@ module ReactiveCaching
enqueuing_update
(
*
args
)
do
value
=
calculate_reactive_cache
(
*
args
)
Rails
.
cache
.
write
(
full_reactive_cache_key
(
*
args
),
value
)
reactive_cache_updated
(
*
args
)
end
end
end
...
...
ee/app/models/concerns/ee/kubernetes_service.rb
View file @
97225551
...
...
@@ -6,7 +6,7 @@ module EE
::
Gitlab
::
Kubernetes
::
RolloutStatus
.
from_specs
(
*
specs
)
end
result
||
::
Gitlab
::
Kubernetes
::
RolloutStatus
.
loading
_status
result
||
::
Gitlab
::
Kubernetes
::
RolloutStatus
.
loading
end
def
calculate_reactive_cache
...
...
@@ -16,6 +16,15 @@ module EE
result
end
def
reactive_cache_updated
super
Gitlab
::
EtagCaching
::
Store
.
new
.
tap
do
|
store
|
store
.
touch
(
Gitlab
::
Routing
.
url_helpers
.
project_environments_path
(
project
,
format: :json
))
end
end
def
read_deployments
kubeclient
=
build_kubeclient!
(
api_path:
'apis/extensions'
,
api_version:
'v1beta1'
)
...
...
lib/gitlab/kubernetes/rollout_status.rb
View file @
97225551
...
...
@@ -36,7 +36,7 @@ module Gitlab
new
(
deployments
)
end
def
self
.
loading
_rollout
def
self
.
loading
new
([],
status: :loading
)
end
...
...
spec/controllers/projects/environments_controller_spec.rb
View file @
97225551
...
...
@@ -52,6 +52,10 @@ describe Projects::EnvironmentsController do
get
:index
,
environment_params
(
format: :json
,
scope: :available
)
end
it
'responds with matching schema'
do
expect
(
response
).
to
match_response_schema
(
'environments'
)
end
it
'responds with a payload describing available environments'
do
expect
(
environments
.
count
).
to
eq
2
expect
(
environments
.
first
[
'name'
]).
to
eq
'production'
...
...
spec/ee/spec/models/project_services/kubernetes_service_spec.rb
View file @
97225551
...
...
@@ -25,5 +25,30 @@ describe KubernetesService, models: true, use_clean_rails_memory_store_caching:
expect
(
rollout_status
.
deployments
.
map
(
&
:labels
)).
to
eq
([{
'app'
=>
'env-000000'
}])
end
end
context
'with empty list of deployments'
do
before
do
stub_reactive_cache
(
service
,
deployments:
[]
)
end
it
'creates a matching RolloutStatus'
do
expect
(
rollout_status
).
to
be_kind_of
(
::
Gitlab
::
Kubernetes
::
RolloutStatus
)
expect
(
rollout_status
).
to
be_not_found
end
end
context
'not yet loaded deployments'
do
before
do
stub_reactive_cache
end
it
'creates a matching RolloutStatus'
do
expect
(
rollout_status
).
to
be_kind_of
(
::
Gitlab
::
Kubernetes
::
RolloutStatus
)
expect
(
rollout_status
).
to
be_loading
end
end
end
end
spec/fixtures/api/schemas/deployment.json
0 → 100644
View file @
97225551
{
"additionalProperties"
:
false
,
"properties"
:
{
"created_at"
:
{
"type"
:
"string"
},
"id"
:
{
"type"
:
"integer"
},
"iid"
:
{
"type"
:
"integer"
},
"last?"
:
{
"type"
:
"boolean"
},
"ref"
:
{
"additionalProperties"
:
false
,
"properties"
:
{
"name"
:
{
"type"
:
"string"
}
},
"required"
:
[
"name"
],
"type"
:
"object"
},
"sha"
:
{
"type"
:
"string"
},
"tag"
:
{
"type"
:
"boolean"
}
},
"required"
:
[
"sha"
,
"created_at"
,
"iid"
,
"tag"
,
"last?"
,
"ref"
,
"id"
],
"type"
:
"object"
}
spec/fixtures/api/schemas/deployments.json
View file @
97225551
...
...
@@ -3,49 +3,7 @@
"properties"
:
{
"deployments"
:
{
"items"
:
{
"additionalProperties"
:
false
,
"properties"
:
{
"created_at"
:
{
"type"
:
"string"
},
"id"
:
{
"type"
:
"integer"
},
"iid"
:
{
"type"
:
"integer"
},
"last?"
:
{
"type"
:
"boolean"
},
"ref"
:
{
"additionalProperties"
:
false
,
"properties"
:
{
"name"
:
{
"type"
:
"string"
}
},
"required"
:
[
"name"
],
"type"
:
"object"
},
"sha"
:
{
"type"
:
"string"
},
"tag"
:
{
"type"
:
"boolean"
}
},
"required"
:
[
"sha"
,
"created_at"
,
"iid"
,
"tag"
,
"last?"
,
"ref"
,
"id"
],
"type"
:
"object"
"$ref"
:
"deployment.json"
},
"minItems"
:
1
,
"type"
:
"array"
...
...
spec/fixtures/api/schemas/environment.json
0 → 100644
View file @
97225551
{
"type"
:
"object"
,
"additionalProperties"
:
false
,
"required"
:
[
"id"
,
"name"
,
"state"
,
"last_deployment"
,
"environment_path"
,
"created_at"
,
"updated_at"
],
"properties"
:
{
"id"
:
{
"type"
:
"integer"
},
"name"
:
{
"type"
:
"string"
},
"state"
:
{
"type"
:
"string"
},
"external_url"
:
{
"type"
:
"string"
},
"environment_type"
:
{
"type"
:
[
"string"
,
"null"
]
},
"last_deployment"
:
{
"oneOf"
:
[
{
"$ref"
:
"deployment.json"
},
{
"type"
:
[
"null"
]
}
]
},
"stop_action?"
:
{
"type"
:
"boolean"
},
"rollout_status"
:
{
"$ref"
:
"rollout_status.json"
},
"environment_path"
:
{
"type"
:
"string"
},
"stop_path"
:
{
"type"
:
"string"
},
"terminal_path"
:
{
"type"
:
"string"
},
"folder_path"
:
{
"type"
:
"string"
},
"created_at"
:
{
"type"
:
"date"
},
"updated_at"
:
{
"type"
:
"date"
}
}
}
spec/fixtures/api/schemas/environments.json
0 → 100644
View file @
97225551
{
"additionalProperties"
:
false
,
"properties"
:
{
"environments"
:
{
"items"
:
{
"$ref"
:
"environments_group.json"
},
"minItems"
:
1
,
"type"
:
"array"
},
"available_count"
:
{
"type"
:
"integer"
},
"stopped_count"
:
{
"type"
:
"integer"
}
},
"required"
:
[
"environments"
,
"available_count"
,
"stopped_count"
],
"type"
:
"object"
}
spec/fixtures/api/schemas/environments_group.json
0 → 100644
View file @
97225551
{
"type"
:
"object"
,
"required"
:
[
"name"
,
"size"
,
"latest"
],
"additionalProperties"
:
false
,
"properties"
:
{
"name"
:
{
"type"
:
"string"
},
"size"
:
{
"type"
:
"integer"
},
"latest"
:
{
"$ref"
:
"environment.json"
}
}
}
spec/fixtures/api/schemas/rollout_status.json
0 → 100644
View file @
97225551
{
"type"
:
"object"
,
"additionalProperties"
:
false
,
"required"
:
[
"status"
],
"properties"
:
{
"status"
:
{
"type"
:
"string"
},
"completion"
:
{
"type"
:
"integer"
},
"is_completed"
:
{
"type"
:
"boolean"
},
"instances"
:
{
"type"
:
"array"
,
"items"
:
{
"additionalProperties"
:
false
,
"type"
:
"object"
,
"required"
:
[
"status"
,
"tooltip"
,
"track"
,
"stable"
],
"properties"
:
{
"status"
:
{
"type"
:
"string"
},
"tooltip"
:
{
"type"
:
"string"
},
"track"
:
{
"type"
:
"string"
},
"stable"
:
{
"type"
:
"boolean"
}
}
}
}
}
}
spec/lib/gitlab/kubernetes/rollout_status_spec.rb
View file @
97225551
...
...
@@ -94,12 +94,24 @@ describe Gitlab::Kubernetes::RolloutStatus do
end
end
describe
'#not_found?'
do
context
'when the specs are passed'
do
it
{
is_expected
.
not_to
be_not_found
}
end
context
'when list of specs is empty'
do
let
(
:specs
)
{
specs_none
}
it
{
is_expected
.
to
be_not_found
}
end
end
describe
'#found?'
do
context
'when the specs are passed'
do
it
{
is_expected
.
to
be_found
}
end
context
'when
no specs are passed
'
do
context
'when
list of specs is empty
'
do
let
(
:specs
)
{
specs_none
}
it
{
is_expected
.
not_to
be_found
}
...
...
spec/models/concerns/reactive_caching_spec.rb
View file @
97225551
...
...
@@ -115,6 +115,12 @@ describe ReactiveCaching, :use_clean_rails_memory_store_caching do
go!
end
it
"calls a reactive_cache_updated after updated"
do
expect
(
instance
).
to
receive
(
:reactive_cache_updated
)
go!
end
context
'and #calculate_reactive_cache raises an exception'
do
before
do
stub_reactive_cache
(
instance
,
"preexisting"
)
...
...
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