2018-07-24 10:00:56 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-10-23 08:36:35 +00:00
|
|
|
module Clusters
|
2017-10-05 17:45:15 +00:00
|
|
|
class ClusterPresenter < Gitlab::View::Presenter::Delegated
|
2022-02-17 15:18:08 +00:00
|
|
|
include ::Gitlab::Utils::StrongMemoize
|
|
|
|
|
|
|
|
delegator_override_with ::Gitlab::Utils::StrongMemoize # This module inclusion is expected. See https://gitlab.com/gitlab-org/gitlab/-/issues/352884.
|
|
|
|
|
2021-09-21 09:12:21 +00:00
|
|
|
presents ::Clusters::Cluster, as: :cluster
|
2017-10-05 17:45:15 +00:00
|
|
|
|
2019-11-22 00:06:08 +00:00
|
|
|
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
|
2017-10-05 17:45:15 +00:00
|
|
|
end
|
2017-12-05 16:09:04 +00:00
|
|
|
|
2018-12-10 04:05:23 +00:00
|
|
|
def can_read_cluster?
|
|
|
|
can?(current_user, :read_cluster, cluster)
|
|
|
|
end
|
|
|
|
|
2021-04-07 00:09:26 +00:00
|
|
|
def show_path(params: {})
|
2018-10-30 10:33:43 +00:00
|
|
|
if cluster.project_type?
|
2021-04-07 00:09:26 +00:00
|
|
|
project_cluster_path(project, cluster, params)
|
2018-10-23 03:51:29 +00:00
|
|
|
elsif cluster.group_type?
|
2021-04-07 00:09:26 +00:00
|
|
|
group_cluster_path(group, cluster, params)
|
2019-04-10 02:13:43 +00:00
|
|
|
elsif cluster.instance_type?
|
2021-04-07 00:09:26 +00:00
|
|
|
admin_cluster_path(cluster, params)
|
|
|
|
else
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def integrations_path
|
|
|
|
if cluster.project_type?
|
|
|
|
create_or_update_project_cluster_integration_path(project, cluster)
|
|
|
|
elsif cluster.group_type?
|
|
|
|
create_or_update_group_cluster_integration_path(group, cluster)
|
|
|
|
elsif cluster.instance_type?
|
|
|
|
create_or_update_admin_cluster_integration_path(cluster)
|
2018-10-30 10:33:43 +00:00
|
|
|
else
|
|
|
|
raise NotImplementedError
|
|
|
|
end
|
|
|
|
end
|
2018-12-10 04:05:23 +00:00
|
|
|
|
2019-03-29 18:23:18 +00:00
|
|
|
def read_only_kubernetes_platform_fields?
|
|
|
|
!cluster.provided_by_user?
|
|
|
|
end
|
|
|
|
|
2020-07-13 15:09:08 +00:00
|
|
|
def health_data(clusterable)
|
|
|
|
{
|
|
|
|
'clusters-path': clusterable.index_path,
|
|
|
|
'dashboard-endpoint': clusterable.metrics_dashboard_path(cluster),
|
2022-04-25 15:08:44 +00:00
|
|
|
'documentation-path': help_page_path('user/infrastructure/clusters/manage/clusters_health'),
|
2020-07-30 00:09:53 +00:00
|
|
|
'add-dashboard-documentation-path': help_page_path('operations/metrics/dashboards/index.md', anchor: 'add-a-new-dashboard-to-your-project'),
|
2020-07-13 15:09:08 +00:00
|
|
|
'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'),
|
2020-07-15 09:09:34 +00:00
|
|
|
'empty-no-data-small-svg-path': image_path('illustrations/chart-empty-state-small.svg'),
|
2020-07-13 15:09:08 +00:00
|
|
|
'empty-unable-to-connect-svg-path': image_path('illustrations/monitoring/unable_to_connect.svg'),
|
|
|
|
'settings-path': '',
|
|
|
|
'project-path': '',
|
|
|
|
'tags-path': ''
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-12-10 04:05:23 +00:00
|
|
|
private
|
|
|
|
|
2020-07-13 15:09:08 +00:00
|
|
|
def image_path(path)
|
2021-09-27 15:10:13 +00:00
|
|
|
ApplicationController.helpers.image_path(path)
|
2020-07-13 15:09:08 +00:00
|
|
|
end
|
|
|
|
|
2020-07-14 15:09:05 +00:00
|
|
|
# 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
|
|
|
|
|
2018-12-10 04:05:23 +00:00
|
|
|
def clusterable
|
|
|
|
if cluster.group_type?
|
|
|
|
cluster.group
|
|
|
|
elsif cluster.project_type?
|
|
|
|
cluster.project
|
|
|
|
end
|
|
|
|
end
|
2017-10-05 17:45:15 +00:00
|
|
|
end
|
|
|
|
end
|
2020-04-10 12:09:36 +00:00
|
|
|
|
2021-05-11 21:10:21 +00:00
|
|
|
Clusters::ClusterPresenter.prepend_mod_with('Clusters::ClusterPresenter')
|