Commit 2aec11b3 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Merge branch '34301-serverless-page-seems-to-be-broken-after-knative-0-7-update' into 'master'

Resolve "Serverless page seems to be broken after Knative 0.7 update"

Closes #34301

See merge request gitlab-org/gitlab!18763
parents 70a191a7 625cea68
...@@ -44,7 +44,7 @@ module Projects ...@@ -44,7 +44,7 @@ module Projects
end end
expose :url do |service| expose :url do |service|
service.dig('status', 'url') service.dig('status', 'url') || "http://#{service.dig('status', 'domain')}"
end end
expose :description do |service| expose :description do |service|
......
...@@ -107,26 +107,50 @@ describe Projects::Serverless::FunctionsController do ...@@ -107,26 +107,50 @@ describe Projects::Serverless::FunctionsController do
end end
end end
context 'valid data', :use_clean_rails_memory_store_caching do context 'with valid data', :use_clean_rails_memory_store_caching do
before do shared_examples 'GET #show with valid data' do
stub_kubeclient_service_pods it 'has a valid function name' do
stub_reactive_cache(knative_services_finder, get :show, params: params({ format: :json, environment_id: "*", id: cluster.project.name })
{ expect(response).to have_gitlab_http_status(200)
services: kube_knative_services_body(namespace: namespace.namespace, name: cluster.project.name)["items"],
pods: kube_knative_pods_body(cluster.project.name, namespace.namespace)["items"] expect(json_response).to include(
}, "name" => project.name,
*knative_services_finder.cache_args) "url" => "http://#{project.name}.#{namespace.namespace}.example.com",
"podcount" => 1
)
end
end end
it 'has a valid function name' do context 'on Knative 0.5' do
get :show, params: params({ format: :json, environment_id: "*", id: cluster.project.name }) before do
expect(response).to have_gitlab_http_status(200) stub_kubeclient_service_pods
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
expect(json_response).to include( include_examples 'GET #show with valid data'
"name" => project.name, end
"url" => "http://#{project.name}.#{namespace.namespace}.example.com",
"podcount" => 1 context 'on Knative 0.6 or 0.7' do
) before do
stub_kubeclient_service_pods
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
include_examples 'GET #show with valid data'
end end
end end
end end
...@@ -141,38 +165,60 @@ describe Projects::Serverless::FunctionsController do ...@@ -141,38 +165,60 @@ describe Projects::Serverless::FunctionsController do
end end
describe 'GET #index with data', :use_clean_rails_memory_store_caching do describe 'GET #index with data', :use_clean_rails_memory_store_caching do
before do shared_examples 'GET #index with data' do
stub_kubeclient_service_pods it 'has data' do
stub_reactive_cache(knative_services_finder, get :index, params: params({ format: :json })
{
services: kube_knative_services_body(namespace: namespace.namespace, name: cluster.project.name)["items"], expect(response).to have_gitlab_http_status(200)
pods: kube_knative_pods_body(cluster.project.name, namespace.namespace)["items"]
}, expect(json_response).to match({
*knative_services_finder.cache_args) "knative_installed" => "checking",
"functions" => [
a_hash_including(
"name" => project.name,
"url" => "http://#{project.name}.#{namespace.namespace}.example.com"
)
]
})
end
it 'has data in html' do
get :index, params: params
expect(response).to have_gitlab_http_status(200)
end
end end
it 'has data' do context 'on Knative 0.5' do
get :index, params: params({ format: :json }) before do
stub_kubeclient_service_pods
expect(response).to have_gitlab_http_status(200) stub_reactive_cache(knative_services_finder,
{
expect(json_response).to match( services: kube_knative_services_body(
{ legacy_knative: true,
"knative_installed" => "checking", namespace: namespace.namespace,
"functions" => [ name: cluster.project.name
a_hash_including( )["items"],
"name" => project.name, pods: kube_knative_pods_body(cluster.project.name, namespace.namespace)["items"]
"url" => "http://#{project.name}.#{namespace.namespace}.example.com" },
) *knative_services_finder.cache_args)
] end
}
) include_examples 'GET #index with data'
end end
it 'has data in html' do context 'on Knative 0.6 or 0.7' do
get :index, params: params before do
stub_kubeclient_service_pods
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
expect(response).to have_gitlab_http_status(200) include_examples 'GET #index with data'
end end
end end
end end
...@@ -319,10 +319,10 @@ module KubernetesHelpers ...@@ -319,10 +319,10 @@ module KubernetesHelpers
} }
end end
def kube_knative_services_body(**options) def kube_knative_services_body(legacy_knative: false, **options)
{ {
"kind" => "List", "kind" => "List",
"items" => [kube_service(options)] "items" => [legacy_knative ? knative_05_service(options) : kube_service(options)]
} }
end end
...@@ -421,6 +421,27 @@ module KubernetesHelpers ...@@ -421,6 +421,27 @@ module KubernetesHelpers
} }
end end
def knative_05_service(name: "kubetest", namespace: "default", domain: "example.com")
{
"metadata" => {
"creationTimestamp" => "2018-11-21T06:16:33Z",
"name" => name,
"namespace" => namespace,
"selfLink" => "/apis/serving.knative.dev/v1alpha1/namespaces/#{namespace}/services/#{name}"
},
"spec" => {
"generation" => 2
},
"status" => {
"domain" => "#{name}.#{namespace}.#{domain}",
"domainInternal" => "#{name}.#{namespace}.svc.cluster.local",
"latestCreatedRevisionName" => "#{name}-00002",
"latestReadyRevisionName" => "#{name}-00002",
"observedGeneration" => 2
}
}
end
def kube_service_full(name: "kubetest", namespace: "kube-ns", domain: "example.com") def kube_service_full(name: "kubetest", namespace: "kube-ns", domain: "example.com")
{ {
"metadata" => { "metadata" => {
......
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