2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
module Clusters
|
|
|
|
class ClusterPresenter < Gitlab::View::Presenter::Delegated
|
2020-07-28 23:09:34 +05:30
|
|
|
include ::Gitlab::Utils::StrongMemoize
|
2019-02-15 15:39:39 +05:30
|
|
|
include ActionView::Helpers::SanitizeHelper
|
|
|
|
include ActionView::Helpers::UrlHelper
|
|
|
|
include IconsHelper
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
presents :cluster
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
# We do not want to show the group path for clusters belonging to the
|
|
|
|
# clusterable, only for the ancestor clusters.
|
2020-03-13 15:44:24 +05:30
|
|
|
def item_link(clusterable_presenter, *html_options)
|
2019-02-15 15:39:39 +05:30
|
|
|
if cluster.group_type? && clusterable != clusterable_presenter.subject
|
|
|
|
contracted_group_name(cluster.group) + ' / ' + link_to_cluster
|
|
|
|
else
|
2020-03-13 15:44:24 +05:30
|
|
|
link_to_cluster(*html_options)
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
def provider_label
|
|
|
|
if aws?
|
|
|
|
s_('ClusterIntegration|Elastic Kubernetes Service')
|
|
|
|
elsif gcp?
|
|
|
|
s_('ClusterIntegration|Google Kubernetes Engine')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def provider_management_url
|
|
|
|
if aws?
|
|
|
|
"https://console.aws.amazon.com/eks/home?region=#{provider.region}\#/clusters/#{name}"
|
|
|
|
elsif gcp?
|
|
|
|
"https://console.cloud.google.com/kubernetes/clusters/details/#{provider.zone}/#{name}"
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
def can_read_cluster?
|
|
|
|
can?(current_user, :read_cluster, cluster)
|
|
|
|
end
|
|
|
|
|
|
|
|
def cluster_type_description
|
|
|
|
if cluster.project_type?
|
|
|
|
s_("ClusterIntegration|Project cluster")
|
|
|
|
elsif cluster.group_type?
|
|
|
|
s_("ClusterIntegration|Group cluster")
|
2019-07-31 22:56:46 +05:30
|
|
|
elsif cluster.instance_type?
|
|
|
|
s_("ClusterIntegration|Instance cluster")
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-13 13:39:08 +05:30
|
|
|
def show_path
|
|
|
|
if cluster.project_type?
|
|
|
|
project_cluster_path(project, cluster)
|
2019-02-15 15:39:39 +05:30
|
|
|
elsif cluster.group_type?
|
|
|
|
group_cluster_path(group, cluster)
|
2019-07-31 22:56:46 +05:30
|
|
|
elsif cluster.instance_type?
|
|
|
|
admin_cluster_path(cluster)
|
2018-12-13 13:39:08 +05:30
|
|
|
else
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
end
|
2019-02-15 15:39:39 +05:30
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
def gitlab_managed_apps_logs_path
|
|
|
|
return unless logs_project && can_read_cluster?
|
|
|
|
|
|
|
|
if cluster.application_elastic_stack&.available?
|
|
|
|
elasticsearch_project_logs_path(logs_project, cluster_id: cluster.id, format: :json)
|
|
|
|
else
|
|
|
|
k8s_project_logs_path(logs_project, cluster_id: cluster.id, format: :json)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
def read_only_kubernetes_platform_fields?
|
|
|
|
!cluster.provided_by_user?
|
|
|
|
end
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
def health_data(clusterable)
|
|
|
|
{
|
|
|
|
'clusters-path': clusterable.index_path,
|
|
|
|
'dashboard-endpoint': clusterable.metrics_dashboard_path(cluster),
|
2020-11-24 15:15:51 +05:30
|
|
|
'documentation-path': help_page_path('user/project/clusters/index', anchor: 'monitoring-your-kubernetes-cluster'),
|
2020-10-24 23:57:45 +05:30
|
|
|
'add-dashboard-documentation-path': help_page_path('operations/metrics/dashboards/index.md', anchor: 'add-a-new-dashboard-to-your-project'),
|
2020-07-28 23:09:34 +05:30
|
|
|
'empty-getting-started-svg-path': image_path('illustrations/monitoring/getting_started.svg'),
|
|
|
|
'empty-loading-svg-path': image_path('illustrations/monitoring/loading.svg'),
|
|
|
|
'empty-no-data-svg-path': image_path('illustrations/monitoring/no_data.svg'),
|
|
|
|
'empty-no-data-small-svg-path': image_path('illustrations/chart-empty-state-small.svg'),
|
|
|
|
'empty-unable-to-connect-svg-path': image_path('illustrations/monitoring/unable_to_connect.svg'),
|
|
|
|
'settings-path': '',
|
|
|
|
'project-path': '',
|
|
|
|
'tags-path': ''
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
private
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
def image_path(path)
|
|
|
|
ActionController::Base.helpers.image_path(path)
|
|
|
|
end
|
|
|
|
|
|
|
|
# currently log explorer is only available in the scope of the project
|
|
|
|
# for group and instance level cluster selected project does not affects
|
|
|
|
# fetching logs from gitlab managed apps namespace, therefore any project
|
|
|
|
# available to user will be sufficient.
|
|
|
|
def logs_project
|
|
|
|
strong_memoize(:logs_project) do
|
|
|
|
cluster.all_projects.first
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-02-15 15:39:39 +05:30
|
|
|
def clusterable
|
|
|
|
if cluster.group_type?
|
|
|
|
cluster.group
|
|
|
|
elsif cluster.project_type?
|
|
|
|
cluster.project
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def contracted_group_name(group)
|
|
|
|
sanitize(group.full_name)
|
|
|
|
.sub(%r{\/.*\/}, "/ #{contracted_icon} /")
|
|
|
|
.html_safe
|
|
|
|
end
|
|
|
|
|
|
|
|
def contracted_icon
|
|
|
|
sprite_icon('ellipsis_h', size: 12, css_class: 'vertical-align-middle')
|
|
|
|
end
|
|
|
|
|
2020-03-13 15:44:24 +05:30
|
|
|
def link_to_cluster(html_options: {})
|
|
|
|
link_to_if(can_read_cluster?, cluster.name, show_path, html_options)
|
2019-02-15 15:39:39 +05:30
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
Clusters::ClusterPresenter.prepend_if_ee('EE::Clusters::ClusterPresenter')
|