Commit 1fb87fa9 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch...

Merge branch '34372-serverless-function-description-does-not-show-up-for-newly-created-functions' into 'master'

Resolve "Serverless function description missing on Knative 0.7"

Closes #34372

See merge request gitlab-org/gitlab!18973
parents c7865861 a09a2f30
...@@ -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
......
---
title: Fix serverless function descriptions not showing on Knative 0.7
merge_request: 18973
author:
type: fixed
...@@ -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,40 +118,33 @@ describe Projects::Serverless::FunctionsController do ...@@ -114,40 +118,33 @@ 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' do context 'on Knative 0.5.0' do
before do
prepare_knative_stubs(knative_05_service(knative_stub_options))
end
include_examples 'GET #show with valid data'
end
context 'on Knative 0.6.0' do
before do before do
stub_kubeclient_service_pods prepare_knative_stubs(knative_06_service(knative_stub_options))
stub_reactive_cache(knative_services_finder,
{
services: kube_knative_services_body(
legacy_knative: true,
namespace: namespace.namespace,
name: cluster.project.name
)["items"],
pods: kube_knative_pods_body(cluster.project.name, namespace.namespace)["items"]
},
*knative_services_finder.cache_args)
end end
include_examples 'GET #show with valid data' include_examples 'GET #show with valid data'
end end
context 'on Knative 0.6 or 0.7' do context 'on Knative 0.7.0' do
before do before do
stub_kubeclient_service_pods prepare_knative_stubs(knative_07_service(knative_stub_options))
stub_reactive_cache(knative_services_finder,
{
services: kube_knative_services_body(namespace: namespace.namespace, name: cluster.project.name)["items"],
pods: kube_knative_pods_body(cluster.project.name, namespace.namespace)["items"]
},
*knative_services_finder.cache_args)
end end
include_examples 'GET #show with valid data' include_examples 'GET #show with valid data'
...@@ -172,11 +169,12 @@ describe Projects::Serverless::FunctionsController do ...@@ -172,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
) )
] ]
}) })
...@@ -189,36 +187,38 @@ describe Projects::Serverless::FunctionsController do ...@@ -189,36 +187,38 @@ describe Projects::Serverless::FunctionsController do
end end
end end
context 'on Knative 0.5' do context 'on Knative 0.5.0' do
before do before do
stub_kubeclient_service_pods prepare_knative_stubs(knative_05_service(knative_stub_options))
stub_reactive_cache(knative_services_finder,
{
services: kube_knative_services_body(
legacy_knative: true,
namespace: namespace.namespace,
name: cluster.project.name
)["items"],
pods: kube_knative_pods_body(cluster.project.name, namespace.namespace)["items"]
},
*knative_services_finder.cache_args)
end end
include_examples 'GET #index with data' include_examples 'GET #index with data'
end end
context 'on Knative 0.6 or 0.7' do context 'on Knative 0.6.0' do
before do before do
stub_kubeclient_service_pods prepare_knative_stubs(knative_06_service(knative_stub_options))
stub_reactive_cache(knative_services_finder,
{
services: kube_knative_services_body(namespace: namespace.namespace, name: cluster.project.name)["items"],
pods: kube_knative_pods_body(cluster.project.name, namespace.namespace)["items"]
},
*knative_services_finder.cache_args)
end end
include_examples 'GET #index with data' include_examples 'GET #index with data'
end end
context 'on Knative 0.7.0' do
before do
prepare_knative_stubs(knative_07_service(knative_stub_options))
end
include_examples 'GET #index with data'
end
end
def prepare_knative_stubs(knative_service)
stub_kubeclient_service_pods
stub_reactive_cache(knative_services_finder,
{
services: [knative_service],
pods: kube_knative_pods_body(cluster.project.name, namespace.namespace)["items"]
},
*knative_services_finder.cache_args)
end end
end end
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment