2018-08-18 07:19:57 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-12-18 08:13:57 -05:00
|
|
|
module ClustersHelper
|
2021-10-26 20:13:04 -04:00
|
|
|
def display_cluster_agents?(clusterable)
|
|
|
|
clusterable.is_a?(Project)
|
2020-10-01 14:10:20 -04:00
|
|
|
end
|
|
|
|
|
2021-10-29 14:13:13 -04:00
|
|
|
def js_clusters_list_data(clusterable)
|
2020-06-10 14:09:15 -04:00
|
|
|
{
|
2020-07-13 20:09:46 -04:00
|
|
|
ancestor_help_path: help_page_path('user/group/clusters/index', anchor: 'cluster-precedence'),
|
2021-10-29 14:13:13 -04:00
|
|
|
endpoint: clusterable.index_path(format: :json),
|
2020-06-10 14:09:15 -04:00
|
|
|
img_tags: {
|
|
|
|
aws: { path: image_path('illustrations/logos/amazon_eks.svg'), text: s_('ClusterIntegration|Amazon EKS') },
|
|
|
|
default: { path: image_path('illustrations/logos/kubernetes.svg'), text: _('Kubernetes Cluster') },
|
|
|
|
gcp: { path: image_path('illustrations/logos/google_gke.svg'), text: s_('ClusterIntegration|Google GKE') }
|
2021-10-29 14:13:13 -04:00
|
|
|
},
|
2021-11-08 22:42:22 -05:00
|
|
|
clusters_empty_state_image: image_path('illustrations/empty-state/empty-state-clusters.svg'),
|
2022-03-18 05:07:21 -04:00
|
|
|
empty_state_image: image_path('illustrations/empty-state/empty-state-agents.svg'),
|
2021-10-29 14:13:13 -04:00
|
|
|
empty_state_help_text: clusterable.empty_state_help_text,
|
2022-03-16 14:08:16 -04:00
|
|
|
add_cluster_path: clusterable.connect_path,
|
2022-03-28 05:07:06 -04:00
|
|
|
new_cluster_docs_path: clusterable.new_cluster_docs_path,
|
2022-01-27 19:14:06 -05:00
|
|
|
can_add_cluster: clusterable.can_add_cluster?.to_s,
|
2022-03-09 22:08:56 -05:00
|
|
|
can_admin_cluster: clusterable.can_admin_cluster?.to_s,
|
2022-03-14 14:07:46 -04:00
|
|
|
display_cluster_agents: display_cluster_agents?(clusterable).to_s,
|
2022-05-05 05:08:00 -04:00
|
|
|
certificate_based_clusters_enabled: clusterable.certificate_based_clusters_enabled?.to_s,
|
2022-03-18 05:07:21 -04:00
|
|
|
default_branch_name: default_branch_name(clusterable),
|
|
|
|
project_path: clusterable_project_path(clusterable),
|
2022-02-04 04:14:46 -05:00
|
|
|
kas_address: Gitlab::Kas.external_url,
|
2022-05-12 14:08:38 -04:00
|
|
|
gitlab_version: Gitlab.version_info,
|
|
|
|
kas_version: Gitlab::Kas.version_info
|
2022-03-18 05:07:21 -04:00
|
|
|
}
|
2021-11-15 10:10:57 -05:00
|
|
|
end
|
|
|
|
|
2020-07-21 14:09:45 -04:00
|
|
|
def js_cluster_form_data(cluster, can_edit)
|
|
|
|
{
|
|
|
|
enabled: cluster.enabled?.to_s,
|
2020-08-17 08:10:12 -04:00
|
|
|
editable: can_edit.to_s,
|
|
|
|
environment_scope: cluster.environment_scope,
|
|
|
|
base_domain: cluster.base_domain,
|
|
|
|
application_ingress_external_ip: cluster.application_ingress_external_ip,
|
|
|
|
auto_devops_help_path: help_page_path('topics/autodevops/index'),
|
2022-04-22 11:09:52 -04:00
|
|
|
external_endpoint_help_path: help_page_path('user/project/clusters/gitlab_managed_clusters.md', anchor: 'base-domain')
|
2020-07-21 14:09:45 -04:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-05-07 14:06:02 -04:00
|
|
|
def render_gcp_signup_offer
|
2018-07-10 09:20:05 -04:00
|
|
|
return if Gitlab::CurrentSettings.current_application_settings.hide_third_party_offers?
|
2018-05-07 14:06:02 -04:00
|
|
|
return unless show_gcp_signup_offer?
|
|
|
|
|
|
|
|
content_tag :section, class: 'no-animate expanded' do
|
2018-10-31 20:39:01 -04:00
|
|
|
render 'clusters/clusters/gcp_signup_offer_banner'
|
2018-05-07 14:06:02 -04:00
|
|
|
end
|
|
|
|
end
|
2019-03-25 11:18:39 -04:00
|
|
|
|
2020-03-12 11:09:39 -04:00
|
|
|
def render_cluster_info_tab_content(tab, expanded)
|
|
|
|
case tab
|
|
|
|
when 'environments'
|
|
|
|
render_if_exists 'clusters/clusters/environments'
|
|
|
|
when 'health'
|
|
|
|
render_if_exists 'clusters/clusters/health'
|
|
|
|
when 'apps'
|
|
|
|
render 'applications'
|
2021-04-06 20:09:26 -04:00
|
|
|
when 'integrations'
|
|
|
|
render 'integrations'
|
2020-03-12 11:09:39 -04:00
|
|
|
when 'settings'
|
|
|
|
render 'advanced_settings_container'
|
|
|
|
else
|
|
|
|
render('details', expanded: expanded)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-04-10 11:09:50 -04:00
|
|
|
def cluster_type_label(cluster_type)
|
|
|
|
case cluster_type
|
|
|
|
when 'project_type'
|
|
|
|
s_('ClusterIntegration|Project cluster')
|
|
|
|
when 'group_type'
|
|
|
|
s_('ClusterIntegration|Group cluster')
|
|
|
|
when 'instance_type'
|
|
|
|
s_('ClusterIntegration|Instance cluster')
|
|
|
|
else
|
|
|
|
Gitlab::ErrorTracking.track_and_raise_for_dev_exception(
|
|
|
|
ArgumentError.new('Cluster Type Missing'),
|
|
|
|
cluster_error: { error: 'Cluster Type Missing', cluster_type: cluster_type }
|
|
|
|
)
|
|
|
|
_('Cluster')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-25 11:18:39 -04:00
|
|
|
def has_rbac_enabled?(cluster)
|
|
|
|
return cluster.platform_kubernetes_rbac? if cluster.platform_kubernetes
|
|
|
|
|
2019-11-13 01:06:38 -05:00
|
|
|
cluster.provider.has_rbac_enabled?
|
2019-03-25 11:18:39 -04:00
|
|
|
end
|
2020-03-12 11:09:39 -04:00
|
|
|
|
|
|
|
def project_cluster?(cluster)
|
|
|
|
cluster.cluster_type.in?('project_type')
|
|
|
|
end
|
|
|
|
|
|
|
|
def cluster_created?(cluster)
|
|
|
|
!cluster.status_name.in?(%i/scheduled creating/)
|
|
|
|
end
|
|
|
|
|
|
|
|
def can_admin_cluster?(user, cluster)
|
|
|
|
can?(user, :admin_cluster, cluster)
|
|
|
|
end
|
2022-03-18 05:07:21 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def default_branch_name(clusterable)
|
|
|
|
clusterable.default_branch if clusterable.is_a?(Project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def clusterable_project_path(clusterable)
|
|
|
|
clusterable.full_path if clusterable.is_a?(Project)
|
|
|
|
end
|
2017-12-18 08:13:57 -05:00
|
|
|
end
|