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
7d2740f0
Commit
7d2740f0
authored
Oct 23, 2019
by
Alishan Ladhani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix fetching of description for Knative 0.7 functions
parent
7e65fe67
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
31 deletions
+51
-31
app/serializers/projects/serverless/service_entity.rb
app/serializers/projects/serverless/service_entity.rb
+31
-7
spec/controllers/projects/serverless/functions_controller_spec.rb
...trollers/projects/serverless/functions_controller_spec.rb
+20
-24
No files found.
app/serializers/projects/serverless/service_entity.rb
View file @
7d2740f0
...
@@ -44,28 +44,52 @@ module Projects
...
@@ -44,28 +44,52 @@ module Projects
end
end
expose
:url
do
|
service
|
expose
:url
do
|
service
|
service
.
dig
(
'status'
,
'url'
)
||
"http://
#{
service
.
dig
(
'status'
,
'domain'
)
}
"
knative_06_07_url
(
service
)
||
knative_05_url
(
service
)
end
end
expose
:description
do
|
service
|
expose
:description
do
|
service
|
knative_07_description
(
service
)
||
knative_05_06_description
(
service
)
end
expose
:image
do
|
service
|
service
.
dig
(
service
.
dig
(
'spec'
,
'spec'
,
'runLatest'
,
'runLatest'
,
'configuration'
,
'configuration'
,
'revisionTemplate'
,
'build'
,
'template'
,
'name'
)
end
private
def
knative_07_description
(
service
)
service
.
dig
(
'spec'
,
'template'
,
'metadata'
,
'metadata'
,
'annotations'
,
'annotations'
,
'Description'
)
'Description'
)
end
end
expose
:image
do
|
service
|
def
knative_05_url
(
service
)
"http://
#{
service
.
dig
(
'status'
,
'domain'
)
}
"
end
def
knative_06_07_url
(
service
)
service
.
dig
(
'status'
,
'url'
)
end
def
knative_05_06_description
(
service
)
service
.
dig
(
service
.
dig
(
'spec'
,
'spec'
,
'runLatest'
,
'runLatest'
,
'configuration'
,
'configuration'
,
'build'
,
'revisionTemplate'
,
'template'
,
'metadata'
,
'name'
)
'annotations'
,
'Description'
)
end
end
end
end
end
end
...
...
spec/controllers/projects/serverless/functions_controller_spec.rb
View file @
7d2740f0
...
@@ -13,6 +13,10 @@ describe Projects::Serverless::FunctionsController do
...
@@ -13,6 +13,10 @@ describe Projects::Serverless::FunctionsController do
let
(
:environment
)
{
create
(
:environment
,
project:
project
)
}
let
(
:environment
)
{
create
(
:environment
,
project:
project
)
}
let!
(
:deployment
)
{
create
(
:deployment
,
:success
,
environment:
environment
,
cluster:
cluster
)
}
let!
(
:deployment
)
{
create
(
:deployment
,
:success
,
environment:
environment
,
cluster:
cluster
)
}
let
(
:knative_services_finder
)
{
environment
.
knative_services_finder
}
let
(
:knative_services_finder
)
{
environment
.
knative_services_finder
}
let
(
:function_description
)
{
'A serverless function'
}
let
(
:knative_stub_options
)
do
{
namespace:
namespace
.
namespace
,
name:
cluster
.
project
.
name
,
description:
function_description
}
end
let
(
:namespace
)
do
let
(
:namespace
)
do
create
(
:cluster_kubernetes_namespace
,
create
(
:cluster_kubernetes_namespace
,
...
@@ -114,16 +118,17 @@ describe Projects::Serverless::FunctionsController do
...
@@ -114,16 +118,17 @@ describe Projects::Serverless::FunctionsController do
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
).
to
include
(
expect
(
json_response
).
to
include
(
"name"
=>
project
.
name
,
'name'
=>
project
.
name
,
"url"
=>
"http://
#{
project
.
name
}
.
#{
namespace
.
namespace
}
.example.com"
,
'url'
=>
"http://
#{
project
.
name
}
.
#{
namespace
.
namespace
}
.example.com"
,
"podcount"
=>
1
'description'
=>
function_description
,
'podcount'
=>
1
)
)
end
end
end
end
context
'on Knative 0.5.0'
do
context
'on Knative 0.5.0'
do
before
do
before
do
prepare_knative_stubs
(
'0.5.0'
,
namespace:
namespace
.
namespace
,
name:
cluster
.
project
.
name
)
prepare_knative_stubs
(
knative_05_service
(
knative_stub_options
)
)
end
end
include_examples
'GET #show with valid data'
include_examples
'GET #show with valid data'
...
@@ -131,7 +136,7 @@ describe Projects::Serverless::FunctionsController do
...
@@ -131,7 +136,7 @@ describe Projects::Serverless::FunctionsController do
context
'on Knative 0.6.0'
do
context
'on Knative 0.6.0'
do
before
do
before
do
prepare_knative_stubs
(
'0.6.0'
,
namespace:
namespace
.
namespace
,
name:
cluster
.
project
.
name
)
prepare_knative_stubs
(
knative_06_service
(
knative_stub_options
)
)
end
end
include_examples
'GET #show with valid data'
include_examples
'GET #show with valid data'
...
@@ -139,7 +144,7 @@ describe Projects::Serverless::FunctionsController do
...
@@ -139,7 +144,7 @@ describe Projects::Serverless::FunctionsController do
context
'on Knative 0.7.0'
do
context
'on Knative 0.7.0'
do
before
do
before
do
prepare_knative_stubs
(
'0.7.0'
,
namespace:
namespace
.
namespace
,
name:
cluster
.
project
.
name
)
prepare_knative_stubs
(
knative_07_service
(
knative_stub_options
)
)
end
end
include_examples
'GET #show with valid data'
include_examples
'GET #show with valid data'
...
@@ -164,11 +169,12 @@ describe Projects::Serverless::FunctionsController do
...
@@ -164,11 +169,12 @@ describe Projects::Serverless::FunctionsController do
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
response
).
to
have_gitlab_http_status
(
200
)
expect
(
json_response
).
to
match
({
expect
(
json_response
).
to
match
({
"knative_installed"
=>
"checking"
,
'knative_installed'
=>
'checking'
,
"functions"
=>
[
'functions'
=>
[
a_hash_including
(
a_hash_including
(
"name"
=>
project
.
name
,
'name'
=>
project
.
name
,
"url"
=>
"http://
#{
project
.
name
}
.
#{
namespace
.
namespace
}
.example.com"
'url'
=>
"http://
#{
project
.
name
}
.
#{
namespace
.
namespace
}
.example.com"
,
'description'
=>
function_description
)
)
]
]
})
})
...
@@ -183,7 +189,7 @@ describe Projects::Serverless::FunctionsController do
...
@@ -183,7 +189,7 @@ describe Projects::Serverless::FunctionsController do
context
'on Knative 0.5.0'
do
context
'on Knative 0.5.0'
do
before
do
before
do
prepare_knative_stubs
(
'0.5.0'
,
namespace:
namespace
.
namespace
,
name:
cluster
.
project
.
name
)
prepare_knative_stubs
(
knative_05_service
(
knative_stub_options
)
)
end
end
include_examples
'GET #index with data'
include_examples
'GET #index with data'
...
@@ -191,7 +197,7 @@ describe Projects::Serverless::FunctionsController do
...
@@ -191,7 +197,7 @@ describe Projects::Serverless::FunctionsController do
context
'on Knative 0.6.0'
do
context
'on Knative 0.6.0'
do
before
do
before
do
prepare_knative_stubs
(
'0.6.0'
,
namespace:
namespace
.
namespace
,
name:
cluster
.
project
.
name
)
prepare_knative_stubs
(
knative_06_service
(
knative_stub_options
)
)
end
end
include_examples
'GET #index with data'
include_examples
'GET #index with data'
...
@@ -199,24 +205,14 @@ describe Projects::Serverless::FunctionsController do
...
@@ -199,24 +205,14 @@ describe Projects::Serverless::FunctionsController do
context
'on Knative 0.7.0'
do
context
'on Knative 0.7.0'
do
before
do
before
do
prepare_knative_stubs
(
'0.7.0'
,
namespace:
namespace
.
namespace
,
name:
cluster
.
project
.
name
)
prepare_knative_stubs
(
knative_07_service
(
knative_stub_options
)
)
end
end
include_examples
'GET #index with data'
include_examples
'GET #index with data'
end
end
end
end
def
prepare_knative_stubs
(
version
,
options
)
def
prepare_knative_stubs
(
knative_service
)
knative_service
=
case
version
when
'0.7.0'
knative_07_service
(
options
)
when
'0.6.0'
knative_06_service
(
options
)
when
'0.5.0'
knative_05_service
(
options
)
end
stub_kubeclient_service_pods
stub_kubeclient_service_pods
stub_reactive_cache
(
knative_services_finder
,
stub_reactive_cache
(
knative_services_finder
,
{
{
...
...
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