Module: ClustersHelper

Defined in:
app/helpers/clusters_helper.rb

Instance Method Summary collapse

Instance Method Details

#can_admin_cluster?(user, cluster) ⇒ Boolean

Returns:

  • (Boolean)


102
103
104
# File 'app/helpers/clusters_helper.rb', line 102

def can_admin_cluster?(user, cluster)
  can?(user, :admin_cluster, cluster)
end

#cluster_created?(cluster) ⇒ Boolean

Returns:

  • (Boolean)


98
99
100
# File 'app/helpers/clusters_helper.rb', line 98

def cluster_created?(cluster)
  !cluster.status_name.in?(%i[scheduled creating])
end

#cluster_type_label(cluster_type) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'app/helpers/clusters_helper.rb', line 71

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

#display_cluster_agents?(clusterable) ⇒ Boolean

Returns:

  • (Boolean)


4
5
6
# File 'app/helpers/clusters_helper.rb', line 4

def display_cluster_agents?(clusterable)
  clusterable.is_a?(Project) || clusterable.is_a?(Group)
end

#has_rbac_enabled?(cluster) ⇒ Boolean

Returns:

  • (Boolean)


88
89
90
91
92
# File 'app/helpers/clusters_helper.rb', line 88

def has_rbac_enabled?(cluster)
  return cluster.platform_kubernetes_rbac? if cluster.platform_kubernetes

  cluster.provider.has_rbac_enabled?
end

#js_cluster_form_data(cluster, can_edit) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'app/helpers/clusters_helper.rb', line 35

def js_cluster_form_data(cluster, can_edit)
  {
    enabled: cluster.enabled?.to_s,
    editable: can_edit.to_s,
    environment_scope: cluster.environment_scope,
    base_domain: cluster.base_domain,
    auto_devops_help_path: help_page_path('topics/autodevops/_index.md'),
    external_endpoint_help_path: help_page_path('user/project/clusters/gitlab_managed_clusters.md',
      anchor: 'base-domain')
  }
end

#js_clusters_list_data(clusterable) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/helpers/clusters_helper.rb', line 8

def js_clusters_list_data(clusterable)
  {
    ancestor_help_path: help_page_path('user/group/clusters/_index.md', anchor: 'cluster-precedence'),
    endpoint: clusterable.index_path(format: :json),
    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') }
    },
    clusters_empty_state_image: image_path('illustrations/empty-state/empty-cloud-md.svg'),
    empty_state_image: image_path('illustrations/empty-state/empty-environment-md.svg'),
    empty_state_help_text: clusterable.empty_state_help_text,
    add_cluster_path: clusterable.connect_path,
    new_cluster_docs_path: clusterable.new_cluster_docs_path,
    can_add_cluster: clusterable.can_add_cluster?.to_s,
    can_admin_cluster: clusterable.can_admin_cluster?.to_s,
    display_cluster_agents: display_cluster_agents?(clusterable).to_s,
    certificate_based_clusters_enabled: clusterable.certificate_based_clusters_enabled?.to_s,
    default_branch_name: default_branch_name(clusterable),
    full_path: clusterable_full_path(clusterable),
    is_group: clusterable.is_a?(Group).to_s,
    kas_address: Gitlab::Kas.external_url,
    kas_install_version: Gitlab::Kas.install_version_info,
    kas_check_version: Gitlab::Kas.display_version_info
  }
end

#migration_alert_config(migration) ⇒ Object



106
107
108
109
110
111
112
113
114
115
# File 'app/helpers/clusters_helper.rb', line 106

def migration_alert_config(migration)
  return unless migration

  status = migration.agent_install_status.to_sym
  config = migration_alert_configs[status]

  return config unless config && status == :error && migration.agent_install_message.present?

  config.merge(details: migration.agent_install_message)
end

#project_cluster?(cluster) ⇒ Boolean

Returns:

  • (Boolean)


94
95
96
# File 'app/helpers/clusters_helper.rb', line 94

def project_cluster?(cluster)
  cluster.cluster_type.in?('project_type')
end

#render_cluster_info_tab_content(tab, expanded) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/helpers/clusters_helper.rb', line 56

def render_cluster_info_tab_content(tab, expanded)
  case tab
  when 'environments'
    render_if_exists 'clusters/clusters/environments'
  when 'apps'
    render 'applications'
  when 'settings'
    render 'advanced_settings_container'
  when 'migrate'
    render 'migrate'
  else
    render('details', expanded: expanded)
  end
end

#render_gcp_signup_offerObject



47
48
49
50
51
52
53
54
# File 'app/helpers/clusters_helper.rb', line 47

def 
  return if Gitlab::CurrentSettings.current_application_settings.hide_third_party_offers?
  return unless 

   :section, class: 'no-animate expanded' do
    render 'clusters/clusters/gcp_signup_offer_banner'
  end
end